wpf: Updating to 16.4 from 16.3.x causes build issues with WPF project file.
When building a WPF project the following error is shown, this built fine in the last 16.3.x version that was released.
C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets(225,9): error MC1000: Unknown build error, ‘Could not find assembly ‘mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e’. Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.’
The project file:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net461</TargetFramework>
<UseWPF>true</UseWPF>
<Platforms>x86</Platforms>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Version>1.0.0</Version>
<Description></Description>
<FileVersion>1.0.0.0</FileVersion>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<ApplicationIcon />
<StartupObject />
</PropertyGroup>
</Project>
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 11
- Comments: 70 (14 by maintainers)
There is a fix queued for this in the next update (3.1.3) which should be available shortly.
I also want to offer some context on the delay, which is a failure on our end. The problem and the solution turned out to be a bit nuanced and hard to track down.
We did fix this in 3.1.2 as part of https://github.com/dotnet/corefx/pull/42768 or so we thought.
To understand what really happened, you have to understand how a .NET Core SDK is put together, where the fix had to be made, and how the fix makes its way from point-of-fix to point-of-consumption.
The point of fix-consumption
The WindowsDesktop SDK, the one that is referred to in WPF and WinForms projects by the line
<Project SDK="Microsoft.NET.Sdk.WindowsDesktop">
, is a set of build tools, properties and targets. Typically, it can be found under$env:ProgramFiles\dotnet\sdk\3.1.102\Sdks\Microsoft.NET.Sdk.WindowsDesktop
or a similar path.The fix was needed in
System.Reflection.MetadataLoadContext.dll
carried by the tools bundled with this SDK.Where is the fix made?
System.Reflection.MetadataLoadContext.dll
is a core library built out of dotnet/corefx (which has since been migrated to dotnet/runtime in .NET 5). It was fixed as part of https://github.com/dotnet/corefx/pull/42768How do fixes ‘move’ from one repository to another in the .NET Core build process?
To explain this, I want to share a snapshot of how various repositories are interconnected.
dotnet/wpf
consumes updates fromdotnet/corefx
by propagating version updates viadotnet/core-setup
->dotnet/winforms
.It can be observed in the flow-diagram above that
dotnet/wpf
also propagates its own version updates intodotnet/core-setup
(throughdotnet-wpf-int
).This sets up a perpetual cycle of builds, like this:
->
dotnet\wpf
->dotnet-wpf-int
->dotnet/core-setup
->dotnet/winforms
->dotnet/wpf
->This perpetual cycle was not a serious problem during active product development of .NET Core 3.0/3.1 - we create a lot of builds, builds take a lot of time to complete, and the overall progress tends to be relatively slow.
But once the product stabilized and switched to servicing, this perpetual-build engine couldn’t be allowed to continue. To break this cycle, the edge from
dotnet/core-setup
->dotnet/winforms
had been disabled (which can also been seen in the flow-diagram).We have only created a handful of servicing builds since .NET Core 3.1 was announced (we are just about to release 3.1.3), and we didn’t take this change into account. More importantly, we failed to grasp the implications for
Microsoft.NET.Sdk.WindowsDesktop
and put one and one together.What this change (the disablement of the edge from
dotnet/core-setup
->dotnet/winforms
) meant was that updates fromdotnet/corefx
wouldn’t flow seamlessly intodotnet/wpf
.What happened ?
The above flow process works fine for the vast majority of scenarios. The all-up product construction (
Mirosoft.WindowsDesktop.App
shared framework) happens indotnet/core-setup
, where the right bits are usually integrated together.dotnet/wpf
(ordotnet/winforms
) not receiving the latest versions fromdotnet/corefx
simply means that these repos build against slightly older reference assemblies - except in the case ofMicrosoft.NET.Sdk.WindowsDesktop
construction. In the latter case,dotnet/wpf
is where the “product” is assembled, and when it needed the latest runtime binaries, it only had access to a slightly older version that lacked the right fixes.dotnet/corefx
, but never made its way back todotnet/wpf
dotnet/corefx
as a runtime bug, and failed to add a test-case for validation. Our private validations seems to pass since we were working with, well, privates.By the time we understood the full scope of what happened and how, 3.1.3 was almost ready and it was looking like the fix may not make it into the schedule. We decided to delay 3.1.3 a bit and rebuild it to take the fix into it anyway. Ultimately, this was all that was needed - https://github.com/dotnet/wpf/pull/2670 (well, followed by an across-the-board rebuild, resetting the progress we had made in 3.1.3 so far across the board, retesting, etc.).
/cc @rladuca
I can confirm this has been fixed in 3.1.103, great work, thanks!
Same issue here, still, with 3.1.2.
Please try to fix this asap because it seems this is a showstopper for many of use.
I was eagerly waiting for this fix, but it’s not working?
I have this defined in global.json:
Still getting this error:
Note that this happens to some projects, not all of them. I am still trying to figure out when exactly this is happening.
.NET Core 3.1.3 Release Notes
Download .NET Core 3.1
Are there any news on this? 3.1.2 didn’t fix it, is using 3.0.101 with global.json the only workaround? Isn’t 3+ months quite a long time to have a severe bug like this go unfixed?
Installing the 3.0.101 SDK and using global.json to force it, is a viable workaround that does not require rolling back all of VS, while we look at the issue and work on fixing it.
But this is hopefully not the solution we have to accept…
Still have the same issue on 3.1.2 😦
[build-up, build]: C:\Program Files\dotnet\sdk\3.1.102\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets(225,9): error MC1000: Неизвестная ошибка сборки, "Could not find assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly." [D:\Projects\Work\Git\Sungero\Common\src\Controls\Controls.csproj]
This fix is in 3.1.2 which is scheduled to release 2/18. Obviously things can happen between here and there to impact the final date but, that’s the target.
https://github.com/dotnet/corefx/pull/42768 fixes this, which is targeted for 3.1.2 milestone.
We release updates at approx. 1-2 month cadence (.NET Core Roadmap]).
Note that the last update (3.1.1) was released on Jan 14, 2020, and we hope to release this fix in the following update to .NET Core 3.1 (unless, of course, something unexpected results in a change of plans).
Me as well. But I will NEVER go back to the old csproj style : )
I had the same problem too. I fixed it, as mentioned above, by installing the .NET Core 3.0.101 SDK and adding a global.json file. However, why do I have to install a .NET Core SDK if my project isn’t targetting .NET core at all?
See the attached project.
I could reproduce it with an almost plain WPF project and a reference to Unit v4.0.1. I know, this is a very old version but for legacy reason I have to stick to this version. Before the VS 16.4 update it was no problem to build the project with this reference.
project.zip
@ericstj please update us on this issue, the new sdk still has the same problem and the workaround suggested also not working
Oh Damn, Such a frustrating moment, didn’t expect such a scenario from Microsoft Development Platform… Please try to fix this issue and release asap
https://github.com/dotnet/wpf/issues/2274#issuecomment-590783681
this workaround is not correct. the issue still exist in the all of .net core sdks
My VB WPF control libraries have the same problem.
Minimal log
The log of failed build task
I solved this issue by adding reference to “mscorlib” in my project.
We were going to update our open source project to use 2019 & .NET Core 3.0 but because of this issue, this is blocking us from proceeding forward with the upgrade.
The workaround of installing older SDK and using
global.json
is no-go for us because while that would have worked for AppVeyor (our build server), it would not be something we can have our contributor manually download & install as I understand that the specific SDK version cannot be downloaded & installed as part of the Visual Studio build. This is quite unfortunate.I have a WPF project targeting net451 and net472 but using the Microsoft.NET.Sdk.WindowsDesktop SDK using the new csproj format. In VS 16.3.9 it was working, after upgrading to 16.4.1 I have the same issue. Could not find System.Core 2.0.5.0
I have all the targeting pack installed.
If I remove net451 everything works. I can build for 472 successfully, Did you raise the minimum framework version or something? We have both because we always build two versions for customers who don’t have an up-to-date framework on their computers.
Yes, beginning with VS 16.3, VS will only “root” the one SDK it comes with. If VS installed an SDK and you upgrade to a VS that brings a newer SDK, it will remove the older SDK and add the newer one. There is ref counting so that if you install an SDK standalone, it will never be uninstalled by VS. VS gets one ref count and the standalone install gets another. If you have scenarios where you need multiple SDKs, you have to install the other ones standalone.
This came after a TON of feedback against leaving SDKs behind from VS upgrades.
I am advocating that the global.json default policy should allow roll forward to any newer version by default. You now have control over the roll forward, but the default is very restrictive and will only roll across the xx in A.B.Cxx if the matching version is not found.
cc @KathleenDollard
Microsoft.WinFX.targets(225,9)
isMarkupCompilePass1
; When building a project forTargetFrameowrk=net472
, it usually resolvesmscorlib
to a path like this:@olivegamestudio, @zplan, are you sure that .NET 4.6.1 and .NET 4.7.2 targeting packs are installed for you respectively?
Same issue here
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <PropertyGroup> <TargetFramework>net472</TargetFramework> <UseWPF>true</UseWPF> <FileVersion>0.0.0.9999</FileVersion> <AssemblyVersion>0.0.0.9999</AssemblyVersion> </PropertyGroup>
Workaround: Because only sdk 3.1.100 is installed after the update, I installed “dotnet-sdk-3.0.101-win-x64” and added a global.json with 3.0.101 to the project root. Now at least it compiles again (but with 3.0)
Using Visual Studio 16.6, migrating WPF app to target .netcore3.1(.300). Cannot compile with error below:
Error MC1000 Unknown build error, ‘Could not find assembly ‘System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.’ MyApp C:\Program Files\dotnet\sdk\3.1.300\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets 225
Is this the same issue? I seem to have most current .netcore (3.1.300) and VS16.6.0.
Any suggestions how to get compiled?
@GeertvanHorrik as things stand, we are hoping for for 24/03/2020 (assuming that factors outside our control do not change this plan, of course 😄).
We already moved to python for development platform, Microsoft really keeps on disappointing as a development platform, python is amazing in fixing bugs ASAP
This has us blocked from updating to the WindowsDesktop sdk project format.
@vatsan-madhavan I got the same issue When I migrate my WPF app from .NET Framework 4.6 to .NET Core 3.1, is there any workaround found or do we have to wait till the next release? (I am using VS 16.5)
@vatsan-madhavan : I did this already long time ago. see my comment on Dec 6, 2019
@zplan, @elparasite, can you share a repro project that shows your error ?
Something small/self-contained that picks out the essential characteristics of the project that is affected by this bug would be nice. Chances are good that the NuGet references are the key.
/cc @rladuca, @nguerrera
Did some more investigation, I think this is the culprit (System.ValueTuple):
@pieterphilippaerts
From my experience, that’s because you are using the new “SDK-style” projects, which by definition use the .NET Core SDK/build system. When using the old “.NET Framework” project files, it will work fine.
It would be very helpful if someone who is hitting this could provide a binlog with the failure.