question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.NET Framework web projects fail with BadImageFormatException when referencing netstandard1.5 or later library

See original GitHub issue

This is happening when someone tries to debug the web application. Something in the web project system is copying reference-only (Private=false, CopyLocal=false) assemblies to the output directory, and then ASP.NET later tries to load these for execution. See https://github.com/dotnet/corefx/issues/23229.

We should get to the bottom of why this happens, it seems to only do it for assemblies which don’t already have an implementation in the output directory. The only case like this is the netfx.force.conflicts.dll.

Regardless of root cause we probably need a workaround in the SDK since these targets need to work on older versions of Visual Studio (which will never see any fix made to the web project system).

Since netfx.force.conflicts.dll is not needed at compile time at all, we can actually remove it from ReferencePath after RAR is done with it. It’s sole purpose is to force conflicts for every assembly that is inbox so that bindingRedirects will be generated to the assemblies in the app.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
ericstjcommented, Aug 17, 2017

Here’s the workaround:

<Target Name="RemoveNetFxForceConflicts" AfterTargets="ResolveAssemblyReferences">
  <ItemGroup>
    <ReferencePath Remove="@(ReferencePath)" Condition="'%(FileName)' == 'netfx.force.conflicts'" />
  </ItemGroup>
</Target>

@livarcocc if possible we should try and get this in for servicing.

0reactions
chukwuemekanwekecommented, Nov 22, 2018

Fixed it by deleting the netfx.conflict dll in project bin folder

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix System.BadImageFormatException
BadImageFormatException is usually due to bitness. One project is 64 bit and the the other is 32 bit. Make sure both project target...
Read more >
'Could not load file or assembly 'netstandard, Version=2.0. ...
The netstandard.dll you are trying to load is a reference assembly that which cannot be loaded for runtime on .NET Framework as pointed...
Read more >
r/dotnet
My solution says my 6.0 library cannot be referenced from my 4.6.1 console app. After looking into it more, it seems another (better?)...
Read more >
Could not load file or assembly or one of its dependencies. ...
Hi, I have a web application on .net 4.7 which references Microsoft. ... [BadImageFormatException: Cannot load a reference assembly for ...
Read more >
BadImageFormatException when I target .NET Framework ...
I'm using Visual Studio 2019 and when I change the target frameworks for all the projects in the solution to 4.7.2, the solution...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found