UWP Compilation error with .net native compile option enabled : Internal compiler error: Specified cast is not valid

Karthik Raman 31 Reputation points
2020-03-19T13:18:27.787+00:00

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

Universal Windows Platform (UWP)
{count} votes