You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are aware of an issue where some customers are unable to run Windows Forms apps built against 6.0.2. This appears as a result of Windows Desktop servicing ref packs in 6.0.2.
This was reported on dotnet/winforms#6663 (Windows Forms) and in #7172 (comment) (WPF). We are working on a fix for this and will update this thread once we have a resolution.
Adding this will explicitly override the WindowsDesktop targeting pack used by the .NET 6.0.102 SDK, with the 6.0.0 WindowsDesktop targeting pack. This way you can use the .NET 6.0.102 SDK without using the broken .NET 6.0.2 WindowsDesktop targeting pack.
Reacted by Lee Coward, theKBro, Zeus, Philippe Fontaine, Morten Nielsen, Scott Stringer, Matvei Stefarov, Markus Hofknecht, openbullet, Andrew Campbell and 1 more
I found this workaround from dotnet/winforms#6663.
I was having that issue in a Github Action for my 'x86 build and run unit test' only.
My x64 version had no issues.
After adding the suggested lines to my project, my unit tests (which uses some methods from my WinForm project) are working again.
This workaround isn't working for my MegaBuild solution's .exe project. When I comment out the <UseWpf> property and comment out the few lines that require WPF in MainForm.cs, then it works. But when UseWpf is true, then I get these errors in the diagnostics MSBuild output:
2> Encountered conflict between 'Reference:C:\Users\Bill\.nuget\packages\microsoft.windowsdesktop.app.ref\6.0.0\ref/net6.0/System.Windows.Forms.dll' and 'Reference:C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.2\ref/net6.0/System.Windows.Forms.dll'. Choosing 'Reference:C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.2\ref/net6.0/System.Windows.Forms.dll' because AssemblyVersion '6.0.2.0' is greater than '6.0.0.0'.
2> Encountered conflict between 'Reference:C:\Users\Bill\.nuget\packages\microsoft.windowsdesktop.app.ref\6.0.0\ref/net6.0/System.Windows.Forms.dll' and 'Reference:C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.2\ref/net6.0/System.Windows.Forms.dll'. Choosing 'Reference:C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.2\ref/net6.0/System.Windows.Forms.dll' because AssemblyVersion '6.0.2.0' is greater than '6.0.0.0'.
2> Encountered conflict between 'Reference:C:\Users\Bill\.nuget\packages\microsoft.windowsdesktop.app.ref\6.0.0\ref/net6.0/System.Windows.Forms.dll' and 'Reference:C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.2\ref/net6.0/System.Windows.Forms.dll'. Choosing 'Reference:C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.2\ref/net6.0/System.Windows.Forms.dll' because AssemblyVersion '6.0.2.0' is greater than '6.0.0.0'.
2> Encountered conflict between 'Platform:System.Windows.Forms.dll' and 'Platform:System.Windows.Forms.dll'. Could not determine winner due to equal file and assembly versions.
2> Encountered conflict between 'Platform:System.Windows.Forms.dll' and 'Platform:System.Windows.Forms.dll'. Could not determine winner due to equal file and assembly versions.
I've spent hours trying to resolve these conflicts, but I've been unsuccessful. I can't reproduce the problem in a small new WinForms app targeting 6.0, setting UseWpf=true, and pulling in similar references. Hopefully, someone here can take a look and point out the problem. The MSBuild diagnostic output is 241,646 lines long, so I don't want to post that here. But getting the MegaBuild repo (from https://github.com/menees/MegaBuild.git), building in VS 2022 with the 6.0.2 SDK produces a MegaBuild.dll for .NET 6.0 that still references System.Windows.Forms.dll v6.0.2. :-(
Thanks, @RussKie! That worked! In addition to global.json, I added the following step to my GitHub build.yml workflow to make sure it will keep building successfully even when GitHub updates their windows-2022 image to a newer SDK:
- uses: actions/setup-dotnet@v1with:
dotnet-version: '6.0.101'# SDK Version to use; x will use the latest version of the 6.0 channel. Force 101 for global.json compatibility.
I believe this error is related to the issue so I'll share it here. I have a WPF app that should compile to a single file but fails with the error "error netsdk1112: the runtime pack for microsoft.windowsdesktop.app.runtime.win-x86 was not downloaded." I have restoration of missing packages enabled during the build.
@RussKie I now think the error above is caused by these errors:
XamlC error XFC0000 : Cannot resolve type "Application"
XamlC error XFC0000 : Cannot resolve type "Window".
I thought these errors were secondary but now I'm thinking they are primary. Here are the repro steps, but I'm not sure this issue belongs here? I've tried the FrameworkReference and globals.json workarounds but it doesn't seem to address this issue.
Repro Steps
Create a new WPF App.
Add a package reference to 'Xamarin.Forms'
XAML compiler can not resolve "Application" and "Window" types.
You may ask, why would I want to do this? I don't. In my solution that used to work prior to the Visual Studio update, I have a project that references a third party package (<PackageReference Include="Microcharts.Forms" Version="1.0.0-preview1" />). This package references Xamarin.Forms. Referencing the third party package also causes the XAML compiler to not resolve the "Application" and "Window" types.
Any help in solving this or where to create an issue is appreciated!
If this is WPF related, please raise an issue in dotnet/wpf repo.
You can also build with /bl flag to generate a binlog, and use MSBuild Structured Log Viewer tool to investigate what assemblies are referenced, and see where it's failing.
Activity
philfontaine commentedon Feb 11, 2022
FYI, the workaround needs to be added to every referenced project that uses WPF/WinForms, not just the one being built.Check #7176 (comment) for a more robust/scalable solution.
Possible fix for the "Could not load file or assembly 'System.Windows…
pmeems commentedon Feb 14, 2022
I found this workaround from dotnet/winforms#6663.
I was having that issue in a Github Action for my 'x86 build and run unit test' only.
My x64 version had no issues.
After adding the suggested lines to my project, my unit tests (which uses some methods from my WinForm project) are working again.
Workaround for WPF error in .NET 6.0.2
RussKie commentedon Feb 15, 2022
work around bug in net6.0.2
Remove explicit SDK reference
menees commentedon Feb 17, 2022
This workaround isn't working for my MegaBuild solution's .exe project. When I comment out the
<UseWpf>property and comment out the few lines that require WPF in MainForm.cs, then it works. But when UseWpf is true, then I get these errors in the diagnostics MSBuild output:I've spent hours trying to resolve these conflicts, but I've been unsuccessful. I can't reproduce the problem in a small new WinForms app targeting 6.0, setting UseWpf=true, and pulling in similar references. Hopefully, someone here can take a look and point out the problem. The MSBuild diagnostic output is 241,646 lines long, so I don't want to post that here. But getting the MegaBuild repo (from https://github.com/menees/MegaBuild.git), building in VS 2022 with the 6.0.2 SDK produces a MegaBuild.dll for .NET 6.0 that still references System.Windows.Forms.dll v6.0.2. :-(
RussKie commentedon Feb 17, 2022
@menees have you tried dotnet/winforms#6663 (comment)?
Force use of 6.0.1 SDK
menees commentedon Feb 17, 2022
Thanks, @RussKie! That worked! In addition to global.json, I added the following step to my GitHub build.yml workflow to make sure it will keep building successfully even when GitHub updates their windows-2022 image to a newer SDK:
Ensure WPF Dependency is 6.0.0+ instead of 6.0.2+
ebussa commentedon Feb 18, 2022
I believe this error is related to the issue so I'll share it here. I have a WPF app that should compile to a single file but fails with the error "error netsdk1112: the runtime pack for microsoft.windowsdesktop.app.runtime.win-x86 was not downloaded." I have restoration of missing packages enabled during the build.@RussKie I now think the error above is caused by these errors:
XamlC error XFC0000 : Cannot resolve type "Application"
XamlC error XFC0000 : Cannot resolve type "Window".
I thought these errors were secondary but now I'm thinking they are primary. Here are the repro steps, but I'm not sure this issue belongs here? I've tried the FrameworkReference and globals.json workarounds but it doesn't seem to address this issue.
Repro Steps
You may ask, why would I want to do this? I don't. In my solution that used to work prior to the Visual Studio update, I have a project that references a third party package (
<PackageReference Include="Microcharts.Forms" Version="1.0.0-preview1" />). This package references Xamarin.Forms. Referencing the third party package also causes the XAML compiler to not resolve the "Application" and "Window" types.Any help in solving this or where to create an issue is appreciated!
RussKie commentedon Feb 18, 2022
Ensure WPF Dependency is 6.0.0+ instead of 6.0.2+ (#413)
Pin ReactiveUI.WPF to .NET 6.0.0 to allow compiling on < 6.0.102.
Pin ReactiveUI.WPF to .NET 6.0.0 to allow compiling on < 6.0.102.
ThumbGen commentedon Mar 4, 2022
Use Directory.Build.props for that. Directory.Build.targets is a better fit (see below)tomaszmalik commentedon Mar 4, 2022
You should use Directory.Build.targets, otherwise it would not override default reference.
Directory.Build.targets content:
Removed .NET 6.0.2 build workarounds
Force target .NET 6.0.0 to avoid dotnet/core#7176
remove dotnet/core/issues/7176 workaround