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

8.3.0 and WinForms throws Could not load file or assembly 'WinRT.Runtime' #927

Closed
1 of 4 tasks
RemcoBlok opened this issue Aug 29, 2024 · 12 comments
Closed
1 of 4 tasks
Labels
duplicate 👥 Indicates that an identical issue or PR already exists

Comments

@RemcoBlok
Copy link

RemcoBlok commented Aug 29, 2024

Describe the bug

I just updated to CommunityToolkit.Mvvm 8.3.0 in a WinForms project targeting net8.0-windows10.0.22621.0 (and runtime identifier win-x64) and everything compiles but when the WinForms app starts I get the following exception:

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for '<Module>' threw an exception.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

  This exception was originally thrown at this call stack:
    <Module>.<Module>()

Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709'. The system cannot find the file specified.

I read something on the blog post announcing 8.3.0 about targeting net8.0-windows10.0.17763.0, but that gives the same exception.

Only when I target net8.0-windows does the WinForms app start correctly.

How can I get it to work with net8.0-windows10.0.22621.0 (or net8.0-windows10.0.17763.0)?

Regression

8.2.2

Steps to reproduce

Update from CommunityToolkit.Mvvm 8.2.2 to 8.3.0 produces the exeption in my project. Starting a new WinForms project from scratch targeting net8.0-windows10.0.22621.0 and runtime identifier win-x64 and CommunityToolkit 8.3.0 does not produce the exception, so there must be something else in my project that triggers the exception. Any advise where to look would be appreciated.

Expected behavior

no exception

Screenshots

No response

IDE and version

VS 2022

IDE version

17.10.6

Nuget packages

  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.3.0

Additional context

No response

Help us help you

Yes, but only if others can assist

@RemcoBlok RemcoBlok added the bug 🐛 An unexpected issue that highlights incorrect behavior label Aug 29, 2024
@RemcoBlok RemcoBlok changed the title 8.3.0 and WinForms gives Could not load file or assembly 'WinRT.Runtime' 8.3.0 and WinForms throws Could not load file or assembly 'WinRT.Runtime' Aug 29, 2024
@abdes
Copy link

abdes commented Aug 29, 2024

Not specific to WinForms, same problem with WinUI...
Downgrading CommunityToolkit.Mvvm to 8.2.2 makes the problem disappear.

At build time, a warning states that a conflict on the version of WinRT.Runtime between 2.0.0.0 and 2.1.0.0 could not be resolved.

@toniemin
Copy link

Happens also on WPF targeting net8.0-windows10.0.17763.0. CommunityToolkit.Mvvm v8.2.2 indeed doesn't seem to have this problem (thanks for the idea!).

@Bush-cat
Copy link

you can fix the winrt conflict by adding the nuget package Microsoft.Windows.CsWinRT

but after that I get lots of namespace problems, I was able to solve them for other communitytoolkit packages like in the issue CommunityToolkit/Windows#489 but didn't work for mvvm

The type or namespace name 'VectorChangedEventHandlerMethods' does not exist in the namespace 'ABI.Windows.Foundation.Collections' (are you missing an assembly reference?)

'IObservableVectorMethods' does not contain a definition for 'Do_Abi_remove_VectorChanged_1'

@LucaCris
Copy link

Confirmed. Unable to safely upgrade to 8.3.0 into WinUI3 packaged App:

2>------ Build started: Project: App8 (Package), Configuration: Debug x64 ------ Microsoft.Common.CurrentVersion.targets(2412,5): warning MSB3277: Found conflicts between different versions of "WinRT.Runtime" that could not be resolved. Microsoft.Common.CurrentVersion.targets(2412,5): warning MSB3277: There was a conflict between "WinRT.Runtime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709" and "WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709". Microsoft.Common.CurrentVersion.targets(2412,5): warning MSB3277: "WinRT.Runtime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709" was chosen because it was primary and "WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709" was not. Microsoft.Common.CurrentVersion.targets(2412,5): warning MSB3277: References which depend on "WinRT.Runtime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709" [C:\Users\Luca\.nuget\packages\microsoft.windows.sdk.net.ref\10.0.19041.34\lib\net6.0\WinRT.Runtime.dll]. Microsoft.Common.CurrentVersion.targets(2412,5): warning MSB3277: C:\Users\Luca\.nuget\packages\microsoft.windows.sdk.net.ref\10.0.19041.34\lib\net6.0\WinRT.Runtime.dll Microsoft.Common.CurrentVersion.targets(2412,5): warning MSB3277: Project file item includes which caused reference "C:\Users\Luca\.nuget\packages\microsoft.windows.sdk.net.ref\10.0.19041.34\lib\net6.0\WinRT.Runtime.dll". Microsoft.Common.CurrentVersion.targets(2412,5): warning MSB3277: C:\Users\Luca\.nuget\packages\microsoft.windows.sdk.net.ref\10.0.19041.34\lib/net6.0/WinRT.Runtime.dll

@MRoc
Copy link

MRoc commented Aug 29, 2024

Same here. When upgrading CommunityToolkit.Mvvm from 8.2.2 to 8.3.0 Compiles fine but get the following exception at the start of my application:

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for '<Module>' threw an exception.
  Source=....
  StackTrace:
    ....

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709'. The system cannot find the file specified.

My application is targeting net8.0-windows10.0.17763.0 and has UseWPF set to true.

@Sergio0694
Copy link
Member

Duplicate of #923, the workaround is in #923 (comment) 🙂

@Sergio0694 Sergio0694 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 29, 2024
@Sergio0694 Sergio0694 added duplicate 👥 Indicates that an identical issue or PR already exists and removed bug 🐛 An unexpected issue that highlights incorrect behavior labels Aug 29, 2024
bagusnl added a commit to CollapseLauncher/Collapse that referenced this issue Aug 29, 2024
@jarvis10211
Copy link

Just change
"<TargetFramework>net8.0-windows10.xxx</TargetFramework>"
to
"<TargetFramework>net8.0-windows</TargetFramework>"

Works Well.

@ZeeOgre
Copy link

ZeeOgre commented Oct 16, 2024

I too was getting it, and noted that if you're using the GUI, targeting Windows 7 or 8 is ok, but targeting anything higher results in the error.

Which is SUPER annoying, since I can SEE the WinRT.Runtime getting copied over into the directory

@ZeeOgre
Copy link

ZeeOgre commented Oct 16, 2024

I had the same in a similar (Non MAUI, WPF app).

WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709'. The system cannot find the file specified.

Which had me really banging my head against the wall.

Until I used winmerge to put the directories side by side with a working earlier version:

'lo and behold.

There's a WinRT.Runtime in my folder... and what is this...Image

For whatever reason, our system continues to look for 2.1.0

What has worked for me is targeting no higher than Windows 8.0. So... I'm fairly sure, that retargeting to a lower version of windows will PROBABLY solve your problem too.

I don't specify that WinRT runtime anywhere, and it LOOKS like my frameworks were up-to-date when I updated VS and .Net, but there's still some mismatch between what it's saying to go look for, and what's actually there.

@Ulrich-Personal
Copy link

Project = .Net 8 winforms

I am facing the same problem. Suddenly a running project is looking for WinRT.Runtime 2.1.0
I never referenced this assembly anywhere in my project. And it was working fine. Suddenly messages like this are coming up:

Could not load file or assembly 'WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709'. The system cannot find the file specified.

The best way to keep a system running is to never update anything. VS or any supporting .Net references.

The advised workaround from @jarvis10211 to change the target framework to:
<TargetFramework>net8.0-windows</TargetFramework>
is not reasonable since I need to target a more actual version.

Another thing with WinRT.Runtime is following example by creating a collection
public class TestCollection : List<T>
and suddenly WinRT is telling me that it needs to be partial

CsWinRT1028
Class 'TestCollection' implements WinRT interfaces but isn't marked partial. Type should be marked partial for trimming and AOT compatibility if passed across the WinRT ABI.
Where is this suddenly coming from? Why is an derived List suddenly be marked as partial?

a workaround for this is:
public class TestCollection : Collection<T>
and no WinRT message is popping up.

Perfectly fine working projects are suddenly full of WinRT messages and disrupting the work.
I cannot even open the Designer for a derived form because of the WinRT.Runtime 2.1.0 cannot be found issue.

A solution is certainly needed regardless of the mentioned workarounds...

@PhilHodgkins
Copy link

I had problems in all my WinForms projects targeting net8.0-windows10.0.18362.0, They all ran, but in designer I could only view forms, my custom controls and usercontrols all gave the 'WinRT.Runtime, Version=2.1.0.0' error.

Using Bush-cat's suggestion of adding the nuget package Microsoft.Windows.CsWinRT fixed it.

@Ulrich-Personal
Copy link

The suggestion of @Bush-cat to add package Microsoft.Windows.CsWinRT fixed the problems within Winform Designer. The error cannot find assembly WinRT.Runtime 2.1.0.0 does not appear anymore and the Designer is loading just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate 👥 Indicates that an identical issue or PR already exists
Projects
None yet
Development

No branches or pull requests