“Bad binary signature” in ASP.NET MVC application

吃可爱长大的小学妹 提交于 2019-12-12 12:23:30

问题


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\

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/11148423/bad-binary-signature-in-asp-net-mvc-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!