Skip to content

Missing Metadata exception with the Microsoft.Extensions.Options 5.0.0 Package #44697

Closed

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

  1. ghost changed the title [-]Missing Metadata exception with the Microsoft.Extensions.Logging 5.0.0 Package[/-] [+]Missing Metadata exception with the Microsoft.Extensions.Options 5.0.0 Package[/+] on Nov 15, 2020
  2. maryamariyan commented on Nov 23, 2020

    @maryamariyan
    Contributor

    @DRAirey1 It would help if you could please share a small repro for this.

  3. jkotas commented on Nov 23, 2020

    @jkotas
    Member

    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.

  4. added
    linkable-frameworkIssues associated with delivering a linker friendly framework
    on Nov 23, 2020
  5. MichalStrehovsky commented on Nov 24, 2020

    @MichalStrehovsky
    Member

    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?

    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:

    <Assembly Dynamic="Required All" Name="Microsoft.Extensions.Options"/>

    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.

  6. MichalStrehovsky commented on Nov 24, 2020

    @MichalStrehovsky
    Member

    @MichalStrehovsky - Thank you. That got me past the Metadata error, but it looks like this error was just the tip of the problems with this release. Now I'm getting:

    Add a similar RD.XML entry for the Microsoft.Extensions.Logging assembly.

    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.

  7. added this to the Future milestone on Feb 25, 2021
  8. removed
    untriagedNew issue has not been triaged by the area owner
    on Feb 25, 2021
  9. self-assigned this
    on Feb 25, 2021
  10. removed their assignment
    on Feb 27, 2022
  11. added a commit that references this issue on Apr 13, 2023
  12. added a commit that references this issue on May 3, 2023
  13. ramondeklein commented on Jul 25, 2023

    @ramondeklein

    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.Logging doesn't show a proper missing meta-data exception. It gave me a runtime exception that didn't have a call stack or .NET exception.

  14. added a commit that references this issue on Jul 26, 2023
    c79e7ac
  15. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 26, 2023
  16. added a commit that references this issue on Jul 27, 2023
    1138b24
  17. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 27, 2023
  18. ghost locked as resolved and limited conversation to collaborators on Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions