-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
System.Buffers, System.Runtime.CompilerServices.Unsafe, etc cannot be loaded #31147
Comments
Our guidance for end applications is usually to use PackageReference if they are not in order to have RAR be able to see transitive dependencies, and to make sure they have auto-binding redirects turned on (which are by default). I suppose main issue here is that IN the case of MimeKit and MailKit they are libraries, not end applications, which don't have binding redirects on by default. One advise that could help would be to a) cross-compile for a .NET Framework TFM in case they are currently only targeting .NET Standard, and B) turn on generation of binding redirects for the library project and pack the .dll.config with the NuGet package. |
What would read the .dll.config if it were in the NuGet package? AFAIK, .NET Framework does not do so, unless the application creates an AppDomain with AppDomainSetup.ConfigurationFile pointing there. Does the .NET SDK have some feature that merges things from .dll.config files to the application config? |
You are right in that .NET Framework doesn't read the .dll.config by default, it would be up-to the host process loading the assemblies to do so. That said, most applications models will do so automatically (as the loader is the one in charge of lazy loading the assemblies), and so will most of the test runners (which usually Load the assembly into an appdomain but most do make sure that they read a config file if there is one) as well. |
I've added |
To generate binding redirects for a DLL, you'd have to set GenerateBindingRedirectsOutputType=true as well. That's the default for EXEs but not for DLLs. |
I don't believe that generating MimeKit.dll.config or MailKit.dll.config with binding redirects in it would fix the problem. Applications are more likely to reference those libraries directly than to load them in dedicated application domains. Earlier, I filed dotnet/msbuild#7702 about a similar problem with System.Runtime.CompilerServices.Unsafe. That was resolved as a duplicate of #2547. The bug is that, if NuGet package includes both reference assemblies and runtime assemblies, then the runtime assemblies can have more dependencies than the reference assemblies (this is by design in Roslyn), but .NET SDK and MSBuild consider only the dependencies of the reference assemblies when they generate binding redirections. On net472, the System.Memory/4.5.1 package includes such a runtime-only dependency on System.Runtime.CompilerServices.Unsafe, hitting the bug. System.Memory/4.5.2 does not have this problem as the reference assemblies were removed in dotnet/corefx#33254. However, MimeKit/3.4.3 already depends on System.Memory (>= 4.5.5), so this shouldn't be the problem. |
Describe the bug
I keep getting reports of my MimeKit and MailKit libraries throwing Exceptions trying to load System.Buffers and System.Runtime.CompilerServices.Unsafe.
Some examples:
To Reproduce
I haven't been able to reproduce it myself, but apparently, it's enough to add the MimeKit nuget package to a project and then create a new MimeMessage:
Exceptions (if any)
Further technical details
dotnet --info
The text was updated successfully, but these errors were encountered: