Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ericstj opened this issue Aug 17, 2017 · 9 comments

Comments

@ericstj
Copy link
Member

ericstj commented Aug 17, 2017

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.

@ericstj
Copy link
Member Author

ericstj commented 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.

@ericstj ericstj changed the title .NET Framework web projects fail with BadImageFormatException when referencing netstandard library .NET Framework web projects fail with BadImageFormatException when referencing netstandard1.5 or later library Aug 17, 2017
@nguerrera nguerrera modified the milestones: 2.0.x, 2.1.0 Sep 5, 2017
@ericstj
Copy link
Member Author

ericstj commented Sep 20, 2017

@dsplaisted / @livarcocc now that #1582 is merged can you ensure it flows to the right places to get updates out in a servicing release?

@dsplaisted
Copy link
Member

@ericstj This will go into VS 15.4, and the .NET Core SDK 2.0.2.

@ericstj
Copy link
Member Author

ericstj commented Sep 21, 2017

Also the standalone MSI?

@dsplaisted
Copy link
Member

We need to fix #1539 in the standalone MSI, then we should do a release with both fixes.

@techaimail
Copy link

In a solution (vstudio 2017 enterprise or community) with web projects target .net 4.6.1 and .net core 2 when I compile one of them the others get its bin folders corrupted and appears the file netfx.force.conflicts. This is causing me a lot of time lost. Please help with fix that wrong behavior.

@plsft
Copy link

plsft commented Oct 15, 2017

I am still seeing this issue in a solution targeting 4.7. its happening on both web and api projects in this solution. I can delete the bin folder as a workaround but it's very tedious. Also, the RemoveNetFxForceConflicts target XML above doesn't seem to make any difference at this point. please advise.

@ericstj
Copy link
Member Author

ericstj commented Oct 19, 2017

@dsplaisted please make sure that to fix this you also update the version of the support package that gets used in the CLI repo. I see that still seems to be the old one: https://github.com/dotnet/cli/blob/release/2.0-vs/build/DependencyVersions.props#L19

@chukwuemekanweke
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants