-1

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

karthik vr
  • 55
  • 5
  • 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 – Richard Zhang Mar 20 '20 at 02:05
  • I figured that the issue happens when I add media foundation .net library as a reference in empty uwp project. Library path: [link] https://sourceforge.net/projects/mfnet/files/mfnet/ (I migrated above project to .net standard 2.0 for UWP support) 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? – karthik vr Mar 26 '20 at 20:30
  • Hi, You have the same problem at [Q&A](https://learn.microsoft.com/answers/questions/15463/uwp-compilation-error-with-net-native-compile-opti.html) and it looks like it has been resolved. – Richard Zhang Mar 30 '20 at 01:28
  • Hi @RichardZhang-MSFT It is not actually resolved.Just got to know that "using any library that will use some DirectX API / windows API with p/invoke ", this error will be thrown. So alternative is to 1. drop the MediaFoundation lib 2. You don't publish to MS Store – karthik vr Mar 31 '20 at 17:24
  • Hi, because the library you are referring to is not designed for UWP applications. Some of the APIs it involves are restricted or even unusable in UWP. If you plan to continue developing your UWP application, consider looking for alternative solutions – Richard Zhang Apr 01 '20 at 00:00

1 Answers1

0

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

karthik vr
  • 55
  • 5