We are maintaining a Kentico 11-based site (.NET Framework 4.6.1 running on IIS 10/Windows Server 2019). In testing code that throws an Exception derived directly from System.Exception, the system throws HttpCompileException with this message:
C:\<path>\B2CTokenProcessor.ascx.cs(28): error CS0155: The type caught or thrown must be derived from System.Exception
This is B2CTokenProcessor.ascx.cs line 28:
catch (IdTokenException x)
and this is the definition of IdTokenException:
public class IdTokenException : System.Exception
{
public IdTokenException(string message) : base(message) { }
}
In a situation this simple, an error like this is entirely baffling to me. If the definition of IdTokenException were missing or unreachable, I'd expect to see a type could not be found message (though, in fact, when I substitute an undefined name in that catch no error is logged by the CMS or in the Event Log). The only thought I have at all is that IdTokenException is defined in a NuGet package that was imported into the project; this Exception is not raised on the development site, but happens on a test site to which the site project and NuGet package DLLs have been deployed.
Why is .NET not seeing this type as being derived from System.Exception?
I still don't understand why this manifested in the test environment and not in the development environment which is running the same .NET environment, but what solved this problem in this case was creating and installing a new version of the NuGet package that targets the same framework version as Kentico (Framework 4.6.1 as noted in the question), rather than targeting .NET Standard 2.0 as it was originally built. I suppose there is something on that dev box that includes the .NET Standard 2.0 framework definitions.
Related
I have a Web API that has version 5.1.2 of the Microsoft.AspNet.WebApi.Client package installed.
I am trying to access the API from an ASP.NET MVC application, which also has the same version of the package installed.
However, in the Global.asax of the Web API project, on the line below, I get the following exception:
WebApiConfig.Register(GlobalConfiguration.Configuration);
Attempt by method 'System.Web.Http.HttpConfiguration..ctor(System.Web.Http.HttpRouteCollection)' to access method 'System.Web.Http.HttpConfiguration.DefaultFormatters()' failed.
I found that this error occurs when you have multiple projects pointing to different .net versions.
For example if you have a Web API project targeting .net 4.5 and a unit test project targeting .net 4.5.3 it seems that default settings mean nuget may silently update the .net 4.5 project references to incompatible versions one day when you open visual studio and cause your Web API project to fail with the recondite 'Attempt by method 'HttpConfiguration..ctor(HttpRouteCollection)' to access method 'HttpConfiguration.DefaultFormatters()' failed' error.
To avoid the error drop the higher .net version back on the new project to match the Web API project - for this example right click the unit test project, click properties, then change the target framework to .net framework 4.5.
In my case it was a discrepancy between versions of Microsoft.AspNet.WebApi.Client and Microsoft.AspNet.WebApi.Core, I tried updating both to the same version and it worked.
In my case, the issue was solved when I installed the Microsoft.AspNet.WebApi.Core as well. So three libraries should present and be in harmony (uninstall / install) Microsoft.AspNet.WebApi.Client, Microsoft.AspNet.WebApi.Core and Newtonsoft.json
same for the above answers in my case also it is working good after updating or reinstalling packages
Microsoft.AspNet.WebApi.Client
Microsoft.AspNet.WebApi.Core
I'm new here.
I have searched this site for answers and I found a workaround, but I'd still like get the original problem solved. I have set the target framework to Mono/.NET 4.0 and I am using Mysql.Data.dll. It compiles fine, but when I am trying to run it on xsp2 web server on my laptop, I run into errors:
Missing method .ctor in assembly
/tmp/kari-temp-aspnet-0/eaee30a1/assembly/shadow/04e2c4cc/18848ad4_1c664e18_00000001/MySql.Data.dll,
type System.Security.SecurityRulesAttribute
Can't find custom attr
constructor image:
/tmp/kari-temp-aspnet-0/eaee30a1/assembly/shadow/04e2c4cc/18848ad4_1c664e18_00000001/MySql.Data.dll
mtoken: 0x0a00002a
Missing method
System.Threading.Monitor::Enter(object,bool&) in assembly
/usr/lib/mono/2.0/mscorlib.dll, referenced in assembly
/tmp/kari-temp-aspnet-0/eaee30a1/assembly/shadow/04e2c4cc/18848ad4_1c664e18_00000001/MySql.Data.dll
Here you can see that it is using .../2.0/mscorlib.dll. I have tried to create a new project, like this thread suggests Mono take mscorlib.dll 2.0 instead of 4.0 but it still does the same. If I set the target framework to Mono/.NET 2.0, I run into some other errors.
For the workaround, I renamed mscorlib.dll in 2.0 and then made a symbolic link to the same file in 4.0 directory as some post here suggested and it works, but I'm not happy with that.
Is there a way to manually edit a project configuration file to select a 4.0 target instead of 2.0? Should this be reported as a bug to MonoDevelop? I am using MonoDevelop 2.8.6.3.
This is how xsp works:
xsp2 => mscorlib.dll 2.0
xsp4 => mscorlib.dll 4.0
I'm experiencing the same issue reported here: "Bad binary signature" in ASP.NET MVC application
The ASP.Net MVC site works fine on the local machine, but when deployed using a combination of aspnet_compiler, aspnet_merge, and msdeploy, loading any page will fail with the following error:
System.BadImageFormatException
Bad binary signature. (Exception from HRESULT: 0x80131192)
The accepted solution in the linked question suggests that the issue is caused by using the wrong version of aspnet_merge, and I have verified that removing the aspnet_merge step from the deployment solves the issue.
My problem is that using the correct aspnet_merge version doesn't appear to resolve the issue.
The web application is targeting .Net 4.0 64-bit.
The aspnet_merge path used is: "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\aspnet_merge.exe"
[EDIT]
Local dev is:
VS2010 SP1
Cassini
x64
VS11 Beta and .Net 4.5 are installed
Build paths are:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\
C:\Program Files (x86)\IIS\Microsoft Web Deploy V2\
I've also experienced a similar issue using a Web Deployment Project to pre-compile an ASP.NET Web Site Project in VS2010 (.NET 4.0).
Everything worked fine until I installed VS2012 (which installs .NET 4.5 - I presume that is related) which started giving me:
System.BadImageFormatException: Bad binary signature. (Exception from HRESULT: 0x80131192)
After some debugging and isolated test cases I tracked the issue down to a lambda being passed between the .NET 4.0 web site and another .NET 3.5 project.
The method defined in the 3.5 project had a signature like this:
public IEnumberable<T> ExecuteAsEnumerable(Func<IDataReader, T> func)
{
//..
}
which was being used in the 4.0 website in a property getter resulting in the error when merged via aspnet_merge:
public IList<MyObject> MyListOfItems
{
get
{
return _myListOfItems ?? (_myListOfItems = new SomeQueryBuilder()
//.build statement
.ExecuteAsEnumerable(reader => new MyObject(reader))
.ToArray());
}
}
In my test case I recreated ExecuteAsEnumerable as an different named extension method inside the 4.0 web site, pre-compiled, and it worked. After checking the "Target .NET Framework" of the project and realising it was 3.5 (I hadn't realised before), I switched everything to 4.0, and everything worked again.
Something obviously changed in the .NET 4.5 update (which was an in place upgrade over 4.0). In my case I could recompile the project in question - I'm not sure everyone would have that luxury (is that the right word?).
Hope that helps.
I encountered this exception as well. It wasn't a aspnet_merge version issue either, nor an issue with the target framework as far as I can tell. It is however on a older project recently updated to MVC 5.
I had this code in the Razor view:
var companies = users.Select(u => u.Company).DistinctBy(c => c.Id)
.OrderBy(c => c.Id == CurrentUser.Company.Id ? 0 : 1)
.ThenBy(c => c.Name);
It uses Linq and DistinctBy for the MoreLinq library. As this shouldn't be in a View anyway, I moved it to the controller and the exception vanished.
I've written some code using the REST starter kit and it works fine on my development machine. However, when I upload it to our server the page gives me the following error message...
CS1684: Warning as Error: Reference to type 'System.Runtime.Serialization.Json.DataContractJsonSerializer' claims it is defined in 'c:\WINNT\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll', but it could not be found
I've removed code line by line and it appears that the following line of code is triggering the error...
HttpContent newOrganizationContent = HttpContentExtensions.CreateXmlSerializable(newOrganizationXml);
Really haven't got a clue how to fix it. I assumed it might be because it needs a newer version of the framework to run, but looking in IIS it says it's running version 2.0.50727 which I think is the lates version because it says that even when we're using framework 3.5
Very confused, any ideas?
Jon
At first I thought this was possibly because the server you're deploying to didn't have .NET Framework 3.5SP1 installed and only .NET 3.5RTM.
However, upon checking a .NET 3.5 RTM System.ServiceModel.Web.dll assembly I see that the System.Runtime.Serialization.Json.DataContractJsonSerializer is actually defined.
The compiler warning CS1684 suggests that there is a System.ServiceModel.Web.dll assembly in the server's GAC, but one that doesn't have the System.Runtime.Serialization.Json. DataContractJsonSerializer defined.
So things I would check:
Check that the deployment server is running at least .NET 3.5 RTM and that a beta or release candidate isn't in use or hasn't been left over.
In Visual Studio 2008 make sure you select a "Target Framework" of .NET 3.5 in the project properties.
One final check you could do to see if the problem lies with the server's framework install is to knock up a simple application to consume the DataContractJsonSerializer directly. There's an example on the MSDN documentation page for the class:
DataContractJsonSerializer Class (MSDN)
As a last resort, if the server is under your control then I'd uninstall .NET Framework 3.5 and then re-install from:
Microsoft .NET Framework 3.5 Service Pack 1 (Full Install)
Update:
As per your comments:
If you're running a beta of 3.5 then chances are that DataContractJsonSerializer isn't in the System.ServiceModel.Web.dll assembly.
I seem to remember back around the CTP, betas and release candidates there were late breaking changes in this area. I vaguely remember the DataContractJsonSerializer was one of these late additions/changes due to the increased popularity of JSON and community pressure. My memory is a bit vague but it rings a bell.
To replace the DLL you need to unregister the current version from the GAC then register the RTM one using the GACUTIL.exe tool. I wouldn't advise mixing RTM and beta bits, you're leaving yourself open to unpredictable behavour.
I'm having a problem when browsing a published site on local iis7 (on windows 7).
When browsing the asp.net site through VS2008 with F5 (dev iis) it works fine. When publishing it and browsing, I get a:
Server Error in '/MySite' Application.
The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Stack trace offers no clue on the problematic dll either. I copied the same published folder to a different machine (also with windows 7 32bit and iis 7) and it works.
Since this is a fresh install of iis on my machine, I verified the matching selected items in "Turn Windows Features on/off". After noticing the issue I also ran the "aspnet_regiis" util, but the problem remains.
The web site includes several external dlls (native and managed) and they all appear in the published bin folder (which is identical to the development bin folder)
Any insights?
Cheers,
Shay
As gleaned from this thread: http://social.msdn.microsoft.com/forums/en-US/netfx64bit/thread/f609f52e-00f6-4ada-9d6e-7129b85d3d4d/, as mentioned toward the bottom of the thread (second to last post as of right now), our problem was a "rogue" dll, Microsoft.SqlServer.Replication.dll. We simply removed the dll and no more error. Additionally, as no project in the solution referenced this dll, I simply removed it from the bin file and subsequent builds/publishes do not add the dll. I have no idea how the dll got in the bin file in the first place. A college prank, maybe.
Native dlls are supposed to be locatable in the PATH. Problem was they were under the User PATH and not the System PATH, so it worked fine through the VS but not through the IIS. I added the dll folder to the system PATH and everything worked...
A long shot in most cases but check you have good .NET Framework libraries. Was getting nothing from old Framework 2.0 website maintained with VS 2005 running on IIS 6 except plain text in browser window stating the error. Fiddler and Firebug reveled nothing. Started checking this, that and the other thing. Perhaps when wondering about using aspnet_iisreg that the C:\Windows\Microsoft.NET\Framework\v4.0.30319 folder was discovered to have only a handful of files. Doesn't make a lot of sense, the applications were 2.0 but there is some cross application communication and several libraries so maybe some are run as 4.0 or it might be that IIS will try to use some things from the highest version of .NET Framework available.
A co-worker more knowledgeable about servers repaired the 4.0 Framework with the stand alone installer from here.
Runs well now.
This error occurred for me when the .Net Framework on the target server was only 4.5.2 and a recently upgraded Nuget package required 4.7.2. To temporarily solve it, we downgraded the Nuget library to a previous version that did not require 4.7.2 until we can upgrade the server library.
This was in spite of our project properties having .NET Framework 4.5.2 selected as a target framework.