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

Exception on startup with version 8.3.0 #923

Closed
1 of 4 tasks
LeDahu22 opened this issue Aug 28, 2024 · 32 comments
Closed
1 of 4 tasks

Exception on startup with version 8.3.0 #923

LeDahu22 opened this issue Aug 28, 2024 · 32 comments
Labels
by design Some behavior that is intended and not an issue external ⤴️ Something related to or caused by an external project mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit

Comments

@LeDahu22
Copy link

LeDahu22 commented Aug 28, 2024

Describe the bug

Hi,

After upgrading from 8.2.2 to 8.3.0, as soon I run my WPF application, I've got the following exception :

System.TypeInitializationException : 'The type initializer for 'Module' threw an exception.'
FileNotFoundException : Could not load file or assembly 'WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709'. Specified file not found.

It crashes on the very first line of OnStartup method :

IHost host = CreateHostBuilder().Build();

There seems to be something wrong related to WinRT.Runtime.

Thanks

Regression

8.2.2

Steps to reproduce

Not sure if I can provide a repro sample easily...

Expected behavior

App should start with no exception

IDE and version

VS 2022

IDE version

17.11.2

Nuget packages

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

Nuget package version(s)

8.3.0

Help us help you

No, just wanted to report this

@LeDahu22 LeDahu22 added the bug 🐛 An unexpected issue that highlights incorrect behavior label Aug 28, 2024
@Sergio0694
Copy link
Member

This is unfortunate, but I think it's expected so far until the new .NET SDK comes out. The problem is that the MVVM Toolkit is using the new Windows SDK projections, but your app is trying to use the old ones (because you have an old version of the .NET SDK that doesn't know about this new version yet). As a workaround, can you try adding this to your .csproj file:

<WindowsSdkPackageVersion>10.0.22621.41</WindowsSdkPackageVersion>

Replace 22621 with whatever Windows SDK you're using as target (it should match your TargetFramework). For instance:

<TargetFramework>net8.0-windows10.0.18362.0</TargetFramework>
<WindowsSdkPackageVersion>10.0.18362.41</WindowsSdkPackageVersion>

Let me know if this solves the issue for you! 🙂

@jysong74
Copy link

I also encountered this problem.

@LeDahu22
Copy link
Author

@Sergio0694 Thank you for your quick answer, I changed my csproj to what you advised and the issue went away

<TargetFramework>net8.0-windows10.0.18362.0</TargetFramework> <WindowsSdkPackageVersion>10.0.18362.41</WindowsSdkPackageVersion>

Thanks a lot ! 😃

@Sergio0694 Sergio0694 added by design Some behavior that is intended and not an issue external ⤴️ Something related to or caused by an external project mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit and removed bug 🐛 An unexpected issue that highlights incorrect behavior labels Aug 28, 2024
@hungchips
Copy link

hungchips commented Aug 29, 2024

  • In my csproj there is no line <WindowsSdkPackageVersion>10.0.18362.41</WindowsSdkPackageVersion>
  • If I try to paste it in, when building it says:
    Severity Code Description Project File Line Suppression State Details
    Error (active) NU1102 Unable to find package Microsoft.Windows.SDK.NET.Ref with version (= 10.0.26100)
  • Found 263 version(s) in nuget.org [ Nearest version: 10.0.26100.1 ]
  • Found 0 version(s) in Microsoft Visual Studio Offline Packages
  • Found 0 version(s) in C:\Program Files\dotnet\library-packs NameProject (net8.0-windows10.0.26100.0) F:\Apps\XXX\XXXX\NameProject.csproj 1

@Sergio0694
Copy link
Member

Like I said, you need to use a package version that matches your target framework SDK version.

So for instance, if you have:

<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>

Then you need:

<WindowsSdkPackageVersion>10.0.26100.41</WindowsSdkPackageVersion>

Etc., basically just replace the last .0 with .41 from the target framework.

@LucaCris
Copy link

@Sergio0694, my project is a universal dll, so no target framework:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
  </ItemGroup>

What to add here, on upgrade? Or I need to set it in the caller project?

@bagusnl
Copy link

bagusnl commented Aug 29, 2024

After adding WindowsSdkPackageVersion identifier, I get different error

Error CS0433 : The type 'TextDecorations' exists in both 'Microsoft.WinUI, Version=3.0.0.0, Culture=neutral, PublicKeyToken=de31ebe4ad15742b' and 'Microsoft.Windows.SDK.NET, Version=10.0.22621.38, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

here is our target settings

        <Platforms>x64</Platforms>
        <TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
        <WindowsSdkPackageVersion>10.0.22621.41</WindowsSdkPackageVersion>
        <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
        <RuntimeIdentifier>win-x64</RuntimeIdentifier>
        <EnableWindowsTargeting>true</EnableWindowsTargeting>

Project is using WinUI3

@Sergio0694
Copy link
Member

That is expected if you're using an older version of WinAppSDK. You need to update to 1.6 preview 2, or later.

@Sergio0694
Copy link
Member

"Or I need to set it in the caller project?"

@LucaCris you need to add that in the consuming project (presumably, your app) that's targeting Windows 🙂

@LucaCris
Copy link

That is expected if you're using an older version of WinAppSDK. You need to update to 1.6 preview 2, or later.

1.6 preview 2?! Ok... nothing for now. :(

@hungchips
Copy link

sorry for rushing to give you a bad review. But how can I download and install Windows 11 SDK version 10.0.26100.41?

Because I tried to edit csproj 10.0.26100.0 -> 10.0.26100.41.
This resulted in no SDK on my Project to perform Build.
I tried to type the command dotnet restore but it couldn't install the SDK itself.

Currently on Visual Studio Installer Windows 11 SDK version 10.0.26100.0 is the latest, I can't choose other versions at all. (Maybe it only exists in beta versions? I haven't checked it myself).

@Sergio0694 Sergio0694 mentioned this issue Aug 30, 2024
4 tasks
@Sergio0694
Copy link
Member

Once again, you are modifying the wrong thing. You should not change your target framework. Just follow exactly the steps I provided in #923 (comment). Only add WindowsSdkPackageVersion with the right version based on your target framework. You do not need to change the target framework. You do not need to install any Windows SDK.

For instance, if you have:

<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>

Then leave that as is and just also add this:

<WindowsSdkPackageVersion>10.0.22621.41</WindowsSdkPackageVersion>

That's it.

@4broadcast
Copy link

I don't think this issue should be closed. Others, like I did, are going to miss this because it is not an open issue, and will have to search closed issues. And in my humble opinion, it is an open issue that this "stable" release relies on a preview of the SDK.

@Sergio0694
Copy link
Member

I pinned this issue yesterday for visibility. It's closed because it's not an issue with the MVVM Toolkit itself.

"this "stable" release relies on a preview of the SDK"

It does not. There are no references anywhere in the .NET Community Toolkit to preview builds of the .NET SDK. The VM image used in the pipeline that builds the repo doesn't have access to the preview of the .NET SDK either. This is the same exact issue that WinAppSDK 1.6 will also have when they release in stable soon: it will not work correctly for people using a .NET SDK that has not been updated. The only difference is that WinAppSDK includes a custom target that generates a build error to detect that scenario, whereas the MVVM Toolkit does not. But the point is that without either overriding the Windows SDK package version manually, or updating the .NET SDK to a version that knows about the new SDK projections, things will not work.

@eduardoagr
Copy link

I put this

`

<PropertyGroup>
	<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
	<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.26100.0</TargetFrameworks>
	<WindowsSdkPackageVersion>windows10.0.26100.0</WindowsSdkPackageVersion>
	<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
	<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->

	<!-- Note for MacCatalyst:
	The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
	When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
	The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
	either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
	<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

	<OutputType>Exe</OutputType>
	<RootNamespace>METROWIND</RootNamespace>
	<UseMaui>true</UseMaui>
	<SingleProject>true</SingleProject>
	<ImplicitUsings>enable</ImplicitUsings>
	<Nullable>enable</Nullable>

	<!-- Display name -->
	<ApplicationTitle>METROWIND</ApplicationTitle>

	<!-- App Identifier -->
	<ApplicationId>com.companyname.metrowind</ApplicationId>

	<!-- Versions -->
	<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
	<ApplicationVersion>1</ApplicationVersion>

`

and errors
image

@4broadcast
Copy link

@Sergio0694 fair enough, I misunderstood one of your earlier comments & missed the pin.

Still can't get it to work w/ workaround, but I'm gonna wait 'til all this shakes out. I have enough trouble getting my own code to work.

@eduardoagr
Copy link

This should be opened again

@Sergio0694
Copy link
Member

@eduardoagr you did not set the correct values. Please follow my instructions in #923 (comment) and #923 (comment).

@eduardoagr
Copy link

@Sergio0694 I did

`
net8.0-android;net8.0-ios;net8.0-maccatalyst
$(TargetFrameworks);net8.0-windows10.0.19041.0

<!-- Note for MacCatalyst:
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

<OutputType>Exe</OutputType>
<RootNamespace>METROWIND</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<WindowsSdkPackageVersion>10.0.19041.0</WindowsSdkPackageVersion>

<!-- Display name -->
<ApplicationTitle>METROWIND</ApplicationTitle>`

image

@Sergio0694
Copy link
Member

"I did"

You did not. Like I clearly said in both my comments, especially in #923 (comment):

"basically just replace the last .0 with .41 from the target framework."

In your screenshot, you're using 10.0.19041.0 for WindowsSdkPackageVersion. You need 10.0.19041.41.

@eduardoagr
Copy link

@Sergio0694 Than you and sorry for the trouble, are you considering adding this, for future releases

@Sergio0694
Copy link
Member

No worries. No, this is not something that we'll add to the MVVM Toolkit. Like I explained in #923 (comment), this is a problem in outdated versions of the .NET SDK. As soon as the new update for the .NET SDK is released next month, this will just work with no changes needed. Manually setting the package version is a temporary workaround, but you should remove it when the new .NET SDK is out (as you don't want to hardcode a package version that will be eventually outdated) 🙂

@jarvis10211
Copy link

jarvis10211 commented Sep 2, 2024

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

Works Well.

@Balkoth

This comment was marked as abuse.

@Sergio0694
Copy link
Member

There's no need to use that tone. We did not realize this would be an actual issue before we released the package, that's why the disclaimer doesn't mention it. I've unlisted the package on NuGet for the time being, and will list it again after the servicing .NET SDK update. That should help minimize issues in the meantime. I'll also mention this in the release notes just in case.

@eduardoagr
Copy link

@Balkoth dude how can you be a developer with that attitude? This is not anyone fault and @Sergio0694 is only trying to help. I had to bother him a couple of times times, and you know what this is probably the best package we have for Windows development.

Do you think you are acomplinshing anything by using that tone?

abdes added a commit to abdes/DroidNet that referenced this issue Sep 4, 2024
see CommunityToolkit/dotnet#923

As soon as the new update for the .NET SDK is released next month, this will just work with no changes needed. Manually setting the package version is a temporary workaround, but you should remove it when the new .NET SDK is out (as you don't want to hardcode a package version that will be eventually outdated).
@sdb7
Copy link

sdb7 commented Sep 5, 2024

me work well, thankyou @Sergio0694

yes, i understand people are upset, I postponed a project for a week, me frustrated but that's because me overlooked something.

pardon the english.

@LucaCris
Copy link

LucaCris commented Sep 5, 2024

SDK 1.6 just released, if someone can test it now...

@rlatm
Copy link

rlatm commented Sep 11, 2024

The release notes mention needing the .NET SDK version > 8.0.400 (or the "temporary workaround" of the WindowsSdkPackageVersion).

I verified that I have .NET SDK > 8.0.400 - 8.0.401 specifically (and only that version). However, I still receive the original error. Is this fixed in .NET SDK > 8.0.400 ?

> dotnet --list-sdks
8.0.401 [C:\Program Files\dotnet\sdk]
> dotnet --version
8.0.401
> ls "C:\Program Files\dotnet\Sdk"
[only 8.0.401]

I restarted Windows. I deleted all /bin/ and /obj/ folders. I verified that the servicing release version number is the third part of the version number ( https://learn.microsoft.com/en-us/dotnet/core/releases-and-support#minor-releases ). I searched this repo and found no mentions of 8.0.401.

Thank you!

@Sergio0694
Copy link
Member

Ah, typo, I meant to say 8.0.403, fixed it! Also I'll be releasing a hotfix soon with a built-in diagnostics to help out 🙂

@Sergio0694
Copy link
Member

Hey everyone! Thank you all for the feedback. I've just published a new 8.3.1 hotfix update that includes the changes in #942. This is a new custom targets that will validate the Windows SDK package version and emit a helpful error message to spot issues right at build time. It will also tell you exactly which package version to set in case the one you have isn't compatible.

Hope this helps! 🙂

@Sergio0694 Sergio0694 unpinned this issue Sep 12, 2024
Timthreetwelve added a commit to Timthreetwelve/MyScheduledTasks that referenced this issue Oct 8, 2024
@mikeKuester
Copy link

Hi,

after updating to the latest Visual Studio Version 17.11.5, the installed SDKs are updated: https://github.com/microsoft/CsWinRT/releases/tag/2.1.5.241003.1

For .NET 8 for example I have to use the .47 now:

<WindowsSdkPackageVersion>10.0.19041.47</WindowsSdkPackageVersion>

Hope that helps if some runs into the same problem after the update.

@github-staff github-staff deleted a comment from robykartis Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
by design Some behavior that is intended and not an issue external ⤴️ Something related to or caused by an external project mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit
Projects
None yet
Development

No branches or pull requests

16 participants