Skip to content

FileLoadException for System.Text.Json #176

Description

@PerfectlyNormal

When looking at attributes on properties from other assemblies than the main assembly.
If any of the attributes comes from for example System.Text.Json, that tries loading the
System.Text.Json assembly into our MetadataLoadContext, as it should.
For some unknown reason, the versions does not always agree with each other, leading to this (or a similar) exception.

System.IO.FileLoadException: The assembly 'System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' has already loaded been loaded into this MetadataLoadContext.
   at System.Reflection.MetadataLoadContext.LoadFromStreamCore(Stream peStream)
   at System.Reflection.MetadataLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.PathAssemblyResolver.Resolve(MetadataLoadContext context, AssemblyName assemblyName)
   at System.Reflection.MetadataLoadContext.TryFindAssemblyByCallingResolveHandler(RoAssemblyName refName)
   at System.Reflection.MetadataLoadContext.ResolveToAssemblyOrExceptionAssembly(RoAssemblyName refName)
   at System.Reflection.TypeLoading.Ecma.EcmaResolver.<>c.<.cctor>b__15_3(EntityHandle h, EcmaModule m)
   at System.Reflection.TypeLoading.Ecma.MetadataTable`2.GetOrAdd(EntityHandle handle, C context, Func`3 factory)
   at System.Reflection.TypeLoading.Ecma.EcmaResolver.ResolveToAssemblyOrExceptionAssembly(AssemblyReferenceHandle handle, EcmaModule module)
   at System.Reflection.TypeLoading.Ecma.EcmaResolver.TryResolveAssembly(AssemblyReferenceHandle handle, EcmaModule module, Exception& e)
   at System.Reflection.TypeLoading.Ecma.EcmaResolver.ResolveAssembly(AssemblyReferenceHandle handle, EcmaModule module)
   at System.Reflection.TypeLoading.Ecma.EcmaResolver.ComputeTypeRefResolution(TypeReferenceHandle handle, EcmaModule module)
   at System.Reflection.TypeLoading.Ecma.EcmaResolver.<>c.<.cctor>b__15_1(EntityHandle h, EcmaModule m)
   at System.Reflection.TypeLoading.Ecma.MetadataTable`2.GetOrAdd(EntityHandle handle, C context, Func`3 factory)
   at System.Reflection.TypeLoading.Ecma.EcmaResolver.ResolveTypeRef(TypeReferenceHandle handle, EcmaModule module)
   at System.Reflection.TypeLoading.Ecma.EcmaResolver.ResolveTypeDefRefOrSpec(EntityHandle handle, EcmaModule module, TypeContext& typeContext)
   at System.Reflection.TypeLoading.Ecma.EcmaCustomAttributeData.ComputeAttributeType()
   at System.Reflection.TypeLoading.RoCustomAttributeData.get_AttributeType()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions