KarthikRaman-7576 avatar image
0 Votes"
KarthikRaman-7576 asked ·

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

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\\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\\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

· 10
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello, in order to eliminate the impact of the third party library, you can try to create a new blank UWP project, install the third-party libraries involved, and try to generate Release. If you can reproduce the problem, you can try to remove the package one by one, locate specific reason

0 Votes 0 · ·

Have you solved your problem?

0 Votes 0 · ·

@RichardZhang-MSFT @RoyLi-MSFT

Sorry for the late response. I did as you suggested. And I figured that the issue happens when I add media foundation .net library as a reference in empty uwp project. Library path: (The above code is migrated version of MF .net to .net standard 2.0) If I just add the library project to my solution, it compiles. Issue happens only if I add a reference of the above third-party library project in my empty uwp project.

Why does the issue happen only when I add a reference of third-party library in my project and not when I just add the third party project in my solution. Can you suggest on how to proceed? How do I isolate the source of the issue?

0 Votes 0 · ·
jtorjo avatar image jtorjo KarthikRaman-7576 ·

Let me shed some light here - this will NEVER work. I've ran into the same issue with library, and with Naudio library.

MediaFoundation is using some DirectX API that the WinRT gods don't allow. Same for Naudio.

As long as you use any library that will use some DirectX API / windows API with p/invoke that MS doesn't like, you'll run into the same issue.

So you have 2 choices: 1. You drop the MediaFoundation lib 2. You don't publish to MS Store

Personally, I would recommend the latter, but it's up to you.

1 Vote 1 · ·
Show more comments

0 Answers