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

Build 5.01 on .net 4.8 breaks because of ref to Microsoft.BCL.AsyncInterfaces v 1.0.0 #825

Closed
michaelkhalsa opened this issue Jun 21, 2020 · 5 comments
Labels

Comments

@michaelkhalsa
Copy link

App: Win Forms using .Net Framework 4.8
Installer: Microsoft VS Desktop Installer build .98
VS : 2019 Latest (not preview)

Simple Injector Build 5.01 (upgraded from build 4.1) broke my application (this took several days to find what was going on, as did not suspect simple injector). And adding a ref to nuget for this assembly does not work (I did not try an assembly redirect, and i believe i turned off this option).

It looks like Simple Injector contains a reference to 1.0.0 for Microsoft.Bcl.AsyncInterfaces
It will build fine and run within VS, however when installed, it crashes on startup with an error: Reference assemblies should only be loaded for execution, They can only be loaded in the Reflection-only-loader context.

I believe the solution is to use version 1.1.0 or 1.1.1 via nuget within your library, as quite a few libraries do (such as csv helper, reactive, etc) , instead of including a gac assembly in your library.

Downgrading back to simple injector 4.1 fixed the problem

This took several days of work to figure out.
Once i narrowed it down to Simple Injector as the culprit, I looked in the project assets.json file in the obj folder for the main project in the solution, to go through all of the assemblies using the Bcl.AsyncInterfaces, and found that build Simple Injector 5.01 was indeed referencing 1.0.0 assembly. When i downgraded, the ref to 4.1, any BCL assembly was gone from Simple Injector in the assets.json file created in the obj folder by visual studio.

Several other libraries which are using version 1.1.0 work fine.

@dotnetjunkie
Copy link
Collaborator

Hi Michael,

A NuGet package should always use the lowest possible version of a dependency, which is why Simple Injector referwnces 1.0 of AsyncInterdaces. This generally means that binding redirects need to be used (under .NET) and NuGet typically managescthat for you. I say typically, because NuGet tends to fuck up from time to time.

But the solution is to manually add the binding redirect in case NuGet fails to do so.

@dotnetjunkie
Copy link
Collaborator

One other thing, the release notes that you should always first upgrade to the latest v4.x (i.e. 4.10) version before upgrading to v5. You shouldn't take this advice lightly.

@dotnetjunkie
Copy link
Collaborator

dotnetjunkie commented Jun 22, 2020

You can add the following binding redirect to fix the problem.

@dotnetjunkie
Copy link
Collaborator

Hopefully, the next version of .NET (4.9?) will include the IAsyncDisposable interface OOTB. This would allow the Simple Injector NuGet package to have a /lib/net49 version which would solve the problem all together.

Another option is to migrate to .NET Core. With .NET Core everything will work OOTB.

@dotnetjunkie
Copy link
Collaborator

Hi @michaelkhalsa,

I pushed an 5.2.0-alpha2 version of the Simple Injector core library and the ASP.NET Core integration packages to NuGet. These set of packages tend to solve the problems regarding Microsoft.bcl.AsyncInterfaces completely. Would you mind trying these packages out to see if this solves the problem for you and whether there are any unintended consequences? You can see more details about what changes here: #867. This is also the place to post your feedback.

Cheers

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

No branches or pull requests

2 participants