.Net 4.6 website not loading Reference Assemblies correctly .Net 4.6 website not loading Reference Assemblies correctly asp.net asp.net

.Net 4.6 website not loading Reference Assemblies correctly


I delete the package from the /Bin folder

System.Collections and System.Collections.Concurrent

and rebuild project

its works.


Resolution:

My library projects were referencing some core libs (System.* etc) with the RequiredTargetFramework option set to 3.5. This was only evident in the csproj file, example:

<Reference Include="System.Core">  <RequiredTargetFramework>3.5</RequiredTargetFramework></Reference>

Thus causing all sorts of issues with .net versions, visual studio was trying to sort it by adding binding redirects into my web.config to point these to v4 (and include reference assemblies), unsuccessfully.

Removing all RequiredTargetFramework elements from the csproj files has solved the problem.


Any time you see BadImageFormatException, you have an issue of binary format compatibility. May be your IIS pool configured to run 32-bit pool and your assemblies are built to x64, or wise versa. Or, may be, you trying to run x64 assemblies on 32 bit machine. May be you have x64 machine, anycpu-built assemblies but some 3rd party assembly is built strictly to 32-bit code.

It is one of these, or similar

Now, "usr" has good point here. You do have Cannot load a reference assembly for execution but in context with BadImageFormatException. I am wondering if this happens at compilation time. For this, try to add this to web.config

<compilation>  <assemblies>      <remove assembly="System.Collections" />  . . . . 

Or, if you have

<add assembly="System.Collections. . . ."  />

Try removing it first

Now, it is normal that GAC is preferred location for reference unless you supply probing settings