Find the origin of MCG0007 compiler warning

804 Views Asked by At

I'm trying to compile an uwp app but I get the following error:

Warning MCG : warning MCG0007: Unresolved P/Invoke method 'ntdll!RtlGetVersion' for method 'System.Int32 Microsoft.DotNet.PlatformAbstractions.Native.NativeMethods.Windows.RtlGetVersion(Microsoft.DotNet.PlatformAbstractions.Native.NativeMethods.Windows.RTL_OSVERSIONINFOEX)'. Calling this method would throw exception at runtime. Please make sure the P/Invoke either points to a Windows API allowed in UWP applications, or a native DLL that is part of the package. If for some reason your P/Invoke does not satisfy those requirements, please use [DllImport(ExactSpelling=true) to indicate that you understand the implications of using non-UWP APIs.

The thing is that I can't find the origin, is there a way to debug this issue? Or how could I find the library that is causing the issue?

UPDATE: I attach a sample project that throws the same compilation error. If anyone could take a look. I'll be very grateful.

Sample project

UPDATE 2: I have an UWP app that uses the following nuget packages:

This app uses 3 .netstandard libraries.

The UWP app contains the following references.

<PackageReference Include="AdaptiveCards">
      <Version>1.2.4</Version>
    </PackageReference>
    <PackageReference Include="MailKit">
      <Version>2.4.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AppCenter">
      <Version>2.6.4</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AppCenter.Analytics">
      <Version>2.6.4</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AppCenter.Crashes">
      <Version>2.6.4</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Azure.Storage.Blob">
      <Version>11.1.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
      <Version>6.2.9</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Services.Store.Engagement">
      <Version>10.1901.28001</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Toolkit.Uwp">
      <Version>6.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
      <Version>6.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Animations">
      <Version>6.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
      <Version>6.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.DataGrid">
      <Version>6.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.UI.Xaml">
      <Version>2.3.191211002</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed">
      <Version>2.0.1</Version>
    </PackageReference>
    <PackageReference Include="MimeKit">
      <Version>2.4.1</Version>
    </PackageReference>
    <PackageReference Include="MvvmLight">
      <Version>5.4.1.1</Version>
    </PackageReference>
    <PackageReference Include="SQLitePCLRaw.bundle_green">
      <Version>2.0.2</Version>
    </PackageReference>
    <PackageReference Include="SQLitePCLRaw.core">
      <Version>2.0.2</Version>
    </PackageReference>
    <PackageReference Include="Win2D.uwp">
      <Version>1.24.0</Version>
    </PackageReference>

It uses 3 .netStandard libraries.

ServicesLibrary

<PackageReference Include="itext7" Version="7.1.9" />
    <PackageReference Include="Microsoft.AppCenter" Version="2.6.4" />
    <PackageReference Include="Microsoft.AppCenter.Analytics" Version="2.6.4" />
    <PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.1" />
    <PackageReference Include="Microsoft.Identity.Client" Version="4.7.1" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="Portable.BouncyCastle" Version="1.8.5.2" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
    <PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
    <PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.7.0" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.7.0" />

DataLibrary

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="3.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="3.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.0" />
    <PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="3.0.31" />
    <PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="3.0.31" />
    <PackageReference Include="Z.Expressions.Eval" Version="3.0.11" />

SigningLibrary

 <PackageReference Include="BouncyCastle.NetCore" Version="1.8.5" />
    <PackageReference Include="System.Security.AccessControl" Version="4.7.0" />
    <PackageReference Include="System.Security.Cryptography.Pkcs" Version="4.7.0" />
    <PackageReference Include="System.Security.Cryptography.Xml" Version="4.7.0" />
    <PackageReference Include="System.Security.Permissions" Version="4.7.0" />
    <PackageReference Include="System.Security.Principal.Windows" Version="4.7.0" />

The UWP references the ServicesLibrary and the DataLibrary, the ServicesLibrary references the SigningLibrary and the DataLibrary. That's the anatomy of the app that I'm trying to compile in release mode.

Thanks a lot for your help.

1

There are 1 best solutions below

1
Michael On

After all the suggestions, and trying to reproduce the compiler error. I find out that the Z.EntityFramework library was the one causing the issue. Looking at the logs all that I found was a reference to EntityFrameworkCore, related to the compiler error. But from that I started to remove libraries until I finally found the one that was causing the issue.

It's very hard and a bit frustrating finding the solution with such a cryptic message as MCG0007: Unresolved P/Invoke

Thanks for your help.