“Bad binary signature” in ASP.NET MVC application - asp.net

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.

Related

Why is ASP.NET failing to recognize the derivation of an Exception?

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.

Asp.net Core 2.0 with .net framework 4.6.1 - Cannot find reference assembly '.NETFramework/v4.6.1/Microsoft.CSharp.dll

I have recently upgraded my project from asp.net core 1.1 to asp.net core 2.0. and app us using .Net framework 4.6.1. Application is working as expected on local dev machine but once it deployed to server with dotnet publish command I am seeing this error
InvalidOperationException: Cannot find reference assembly
'.NETFramework/v4.6.1/Microsoft.CSharp.dll' file for package
Microsoft.CSharp.Reference
I have also noticed that ref folder that use be present when using asp.net core 1.1 when published is now missing. How to fix this issue.
Same issue was resolved when MvcRazorCompileOnPublish was added to .csproj file.
Give it a try.
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
I noticed if you have the Views folder included with the compiled View.dll when you start your IIS pool, you get this error. I was doing this on purpose for a short term work around hack.
In my case (I run .Net core in console application mode) none of above solutions didn't works, i just downloaded .Net Framework 4.6.1 from this link.

Mono is using mscorlib.dll 2.0 instead of 4.0 in Ubuntu with ASP.NET Web application

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

Error: This assembly is built by a runtime newer than the currently loaded runtime

I have downloaded published (code behind files are no there, combined with dll in bin folder) web application from Window Server 2008 where it is hosted, and open it with Visual Studio when I debug that application it shows following error:
"Could not load assembly because this assembly is built by a runtime newer than the currently loaded runtime"
I don't know how can I solve this problem and test application locally.
Please help me.
This errors happens when the DotNet framework you are using is of older version than the one used to build the assembly. You need to check which version of framework is used to build those assemblies and then use the same or higher to debug too.
I was getting this same error when running an installer for a Windows service, even when running the installer on the PC the installer was built on.
It turned out that although the Windows service project had been updated to .NET 4.5, the Setup project that was making the installer was still set to use .NET 2.0.
To check if the Setup project is using an older version of .NET than the project to be installed, in the Visual Studio Solution Explorer:
Expand the Setup project;
Under the Setup project, expand Detected Dependencies;
Under Detected Dependencies select Microsoft .NET Framework and check the Version property. Select the appropriate .NET version from the dropdown list;
Re-build the Setup project to create a new version of the installer.
This error can have a lot of other reasons, too. I had the same problem, and nothing helped until I stumbled across this:
TlbExp.exe error:This assembly is built by a runtime newer
I just ran into this issue when the assembly was built with a target framework of .NET 4, and v4.0.30319 was installed on the server, and other 4.0 apps were running successfully.
The problem arose because the app had originally been built targeting 2.0, and new 4.0 assemblies were pushed, but not the app.config file, which we generally update separately.
This means the supportedRuntime attribute was not updated in the config and caused the error. Adding the following to the app.config fixed our issue:
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
One the the assemblies reference in the project might be built using a newer version of .net, check version of every assembly reference and correct accordingly.
Also check the application pool that this web site is running as. It could be framework 2.0 default on some older windows servers. Change it to framework 4.0.

Asp.net published web site: The specified module could not be found. Exception from HRESULT: 0x8007007E

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.

Resources