I have a UWP project where build works in debug mode but build fails in release mode where .net native compiler is selected. The UWP projects has many external third party libraries like RTSP client sharp, .net media foundation. The error shown is
"
1> Processing application code
1> Computing application closure and generating interop code
1> Loading 84 modules...
"some warnings displayed....
C:\Users\kR\.nuget\packages\microsoft.net.native.compiler\2.2.8-rel-28605-00\tools\Microsoft.NetNative.targets(801,5): error : Internal compiler error: **Specified cast is not valid.**"
It doesn't say where the error is.
I tried various values in Default.rd.xml but I can't get rid of this error and I don't think this is the right way of by-passing the error
Attempts 1)Changing Dynamic key to Public or PublicAndInternal didn't help. 2)When I removed I get different error "Internal compiler error: Type 'MediaFoundation.Misc.PVMarshaler' was referenced in method 'IMFAttributes.GetItem(Guid, PropVariant)', but was not found necessary by analysis." This goes away when I re-set dynamic key to Required All or Public or Public Internal 3)Code walk through: I did some basic code walk through. I assume it might be related to some cast but it is very time consuming to go through all the code to figure out the location of error.
We will be needing our app in windows store and hence we can't uncheck .net native compiler mode
Questions) 1. How do you get the location of error: Internal compiler error: C:\Users\kR.nuget\packages\microsoft.net.native.compiler\2.2.8-rel-28605-00\tools\Microsoft.NetNative.targets(801,5): error : Internal compiler error: Specified cast is not valid." 2. Any clues on where the issue can be and how to proceed? 3. Any settings I can use to ignore the error as the build works fine in release mode after disabling .net native compiler
This error will happen on using any library that will use some DirectX API / windows API with p/invoke. In general please make sure any third party libraries builds in release mode in an empty project before using them in your UWP project. They might work but Microsoft store build will throw error.
Specifically in my project: I figured that the issue happens when I add media foundation .net library as a reference Library path: [link] sourceforge.net/projects/mfnet/files/mfnet (I migrated above project to .net standard 2.0 for UWP support) So alternative is to 1. drop the MediaFoundation lib 2. You don't publish to MS Store –
Details: See comments in https://learn.microsoft.com/answers/questions/15463/uwp-compilation-error-with-net-native-compile-opti.html