-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
NativeAOT Windows - System.InvalidCastException: Specified cast is not valid #89672
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsI have followed the guide here https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/?tabs=net7 to try compile our app with Native AOT on .NET 8 Preview 6. However, I am getting this error:
How can I find out more information of what this means and how it can be fixed? The publish command I used is: dotnet publish -f:net8.0-windows10.0.19041.0 -r:win10-x64 -c:Release
|
@e012345678 is that app public? |
Hi @EgorBo thanks for the reply, unfortunately no. |
The framework (-f) value has TPI, which suggests that your app is using CsWinRT. This issue was recently fixed downstream: #68278 (comment)). Currently, CsWinRT does not fully support AOT, so even after its next release, chances are your app may not build or run. You can follow the progress in their issue tracker for AOT support: https://github.com/microsoft/CsWinRT/labels/AOT. |
Thanks for the reply @am11 . Why is the NativeAOT marketed as it supports Windows (on the link in my first post) but it does not due to "CsWinRT does not fully support AOT". What fine print/requirements am I missing? |
If your project or one of its dependencies are relying on one of the limitations: https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/?tabs=net8plus#limitations-of-native-aot-deployment, publishing as AOT app will not work. |
Hi @am11, is there anyway I can find out which of my dependencies have this limitation? Basically "what part of my app do I need to remove?" |
Putting those options in your csproj should enable all the analyzers that will log such info at build time: <PublishAot>true</PublishAot>
<EnableAOTAnalyzer>true</EnableAOTAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<TrimmerSingleWarn>false</TrimmerSingleWarn> |
PublishAot is enough to enable all the analyzers. The last two change analysis behaviors and should be set if one want such behaviors. I'm closing this Won't fix with the same justification as #68278 (comment) |
Getting the same build error with CsWinRT Can also open a new issue in the CsWinRT repo to track this there. |
You will need an updated Windows SDK projection with that CsWinRT version. |
I have followed the guide here https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/?tabs=net7 to try compile our app with Native AOT on .NET 8 Preview 6. However, I am getting this error:
How can I find out more information of what this means and how it can be fixed? The publish command I used is: dotnet publish -f:net8.0-windows10.0.19041.0 -r:win10-x64 -c:Release
The text was updated successfully, but these errors were encountered: