-
Notifications
You must be signed in to change notification settings - Fork 430
"Could not load System.Runtime.dll" because it was not copied to the output folder #887
Comments
I believe that what is going on in this one is that you are not actually running on .NET 4.7.1. System.Runtime.dll comes in the GAC on 4.7.1 so you shouldn't have any problems loading it if you are actually running on that platform. Non-web applications will always ensure that the platform you target is installed on the machine running it, but unfortunately, Web apps do not behave this way. |
One more puzzle piece in dealing with these errors is the "Auto-generate binding redirects" feature: This feature seems to edit the Currently, it seems that this feature generates redirects to the wrong version (or to the correct version and something else causes that version to not be available). For web apps this feature does not exist. It comes to bear in console applications for example. |
Ok I understand what is going on here. This is the same issue as https://github.com/dotnet/corefx/issues/32757. The issue here is very specific to web projects that use packages.config. In non-web project types, this error would go away by enabling auto-generate binding redirects or by migrating to PackageReference. Here is more info: The problem here is that NuGet package manager is adding some binding redirects to your web.config but it doesn't have the full picture of your project references, so it fails to read the Framework list to know that System.Net.Http is part of the framework already. The way to tell NuGet package manager to not do that is to either turn on auto-generate binding redirects or to migrate to PackageReference, but unfortunately, that is not straightforward with web projects. With web projects, enabling auto redirects simply won't work, as web.config behaves very different than app.config. PackageReference will work, but the problem is that it is not trivial to migrate since there is no context menu option from VS to migrate a project to packageReferences for web projects, so you would have to do that work manually. Honestly, I think there are two bugs here that should be fixed. First, I would log a bug on vs feedback in order to have the project templates use PackageReference by default since packages.config is just a source of problems, especially when consuming libraries that target different frameworks. The other one seems to be a missing feature on web projects since you can't easily migrate references to PackageReference and today you have to do that manually which is a pain. I would probably also log that bug in vs feedback, since they would know how to route this accordingly. I tried your repro project but migrated (manually) to PackageReference and that fixed the issue at runtime. I'll close this issue given that it is not a problem with dotnet standard, but external instead: vs template system + vs lack of migration feature for web projects + NuGet package manager (incorrectly) trying to add binding redirects automatically. |
Are you saying there will not be a fix besides migrating to PackageReference? PackageReference is not yet appropriate for all development. Not all packages are supported and other reasons. I suggest that you use Microsoft internal channels to properly route these issues. |
I'm not. I don't know if/when the NuGet Package manager will fix these issues, I was simply putting that the package examples that you pointed out, PackageReference would make the scenario work. I was also stating that if the templates used PackageReference by default, then most user's wouldn't hit these type of issues.
We have definitely been doing that, and working with partner teams on how to make this whole experience better than its current state. |
I will attach a repro solution that I have created as follows:
When this application is started it immediately crashes:
Copying text from my other comment:
NuGetUnityRepro.zip
The text was updated successfully, but these errors were encountered: