Repository navigation
Description
Description
I have not changed any code. I made a minor change recently to my UWP application. I noticed that some of the packages were out of rev, so I pulled them down and started getting strange "Missing Metadata" exceptions when trying to instantiate my views (again, working great prior to this). The exception happened in this statement:
BlotterView blotterView = this.serviceProvider.GetRequiredService<BlotterView>();
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.Reflection.Core.dll
Exception thrown: 'System.Reflection.MissingMetadataException' in System.Private.Reflection.Core.dll
'Microsoft.Extensions.Options.IPostConfigureOptions<>' is missing metadata. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=392859
So I rolled back all the package updates I made until these three packages appear to be the cause of the problem:
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.15.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.9" />
I don't know which one, exactly, is causing the problem, but with the 5.0.0 version, I get this crash.
EDIT: As nearly as I can diagnose, the issue is with the upgrade of the Microsoft.Extensions.Options 5.0 package
Configuration
This error only occurs when compiling with the .NET Native toolchain
.NET: .NET Standard 2.0
Windows: Windows 10 10.0.19042
Architecture: 64
Regression?
Fall back from:
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.16.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
to
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.15.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.9" />
makes it work again. Also, turning off the "Compile with Native toolset* option will make it work again.
Activity
[-]Missing Metadata exception with the Microsoft.Extensions.Logging 5.0.0 Package[/-][+]Missing Metadata exception with the Microsoft.Extensions.Options 5.0.0 Package[/+]maryamariyan commentedon Nov 23, 2020
@DRAirey1 It would help if you could please share a small repro for this.
jkotas commentedon Nov 23, 2020
IIRC, .NET Native Toolchain assumes that all assemblies marked with
AssemblyMetadataAttribute(".NETFrameworkAssembly")are compatible with .NET Native version of IL trimming. @MichalStrehovsky Could you please confirm that it is it correct?Microsoft.Extensions.Options 3.1 is not marked as
.NETFrameworkAssembly. It makes .NET Native toolchain to use conservative reflection policy that makes it work.Microsoft.Extensions.Options 5.0 is marked as
.NETFrameworkAssembly. It makes .NET Native toolchain to use more aggresive reflection policy that leads to MissingMetadataException.MichalStrehovsky commentedon Nov 24, 2020
Yes, that will probably be it. .NET Native assumes that framework libraries are trimmable and ship with an embedded RD.XML that describes their dynamic behavior. It looks like we don't have test coverage for this combination anymore.
@DRAirey1 you should be able to work around by adding:
Nested under the
<Application>tag of your default.rd.xml file. You can find the default.rd.xml in the properties folder of your app project.MichalStrehovsky commentedon Nov 24, 2020
Add a similar RD.XML entry for the
Microsoft.Extensions.Loggingassembly.There's 35 of these Microsoft.Extensions assemblies because people in charge of these assemblies don't like to put more than ~20 types in a single assembly. In the worst case we'll need an entry for each.
Fixed .net native release crash
Fixed .net native release crash
ramondeklein commentedon Jul 25, 2023
Can't these assemblies be annotated somehow, so the .NET Native toolchain needs to know about this? I've spent hours to find out about the crash, because
Microsoft.Extensions.Loggingdoesn't show a proper missing meta-data exception. It gave me a runtime exception that didn't have a call stack or .NET exception.Remove `AssemblyMetadata(".NETFrameworkAssembly", "")` attributes
Remove `AssemblyMetadata(".NETFrameworkAssembly", "")` attributes (#8…