Skip to content

After Updating to 8.1.1 "Could not load type 'System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute'" #1434

@Zaneo

Description

@Zaneo

Describe the Bug

After updating to Autofac 8.1.1 our tests using Autofac fail with : System.TypeLoadException Could not load type 'System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute'.

Steps to Reproduce

Unfortunately I don't have a good reproduction yet.

  • The project that this occurs in has a netstandard2.1 library that is being executed in a test runner on net6.0 and net8.0.
  • Reference code/class that has [RequiresUnreferencedCodeAttribute]

Expected Behavior

On Autofac v8.0.0 no error occurs when resolving classes with this attribute.
On Autofac v8.1.1 the previously mentioned error occurs.

Exception with Stack Trace

System.TypeLoadException Could not load type 'System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute' from assembly 'Autofac, Version=8.1.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da'.
   at System.ModuleHandle.ResolveMethod(QCallModule module, Int32 methodToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount)
   at System.ModuleHandle.ResolveMethodHandleInternal(RuntimeModule module, Int32 methodToken, ReadOnlySpan`1 typeInstantiationContext, ReadOnlySpan`1 methodInstantiationContext)
   at System.ModuleHandle.ResolveMethodHandle(Int32 methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.RuntimeType.GetMethodBase(RuntimeModule scope, Int32 typeMetadataToken)
   at System.Reflection.RuntimeCustomAttributeData..ctor(RuntimeModule scope, MetadataToken caCtorToken, ConstArray& blob)
   at System.Reflection.RuntimeCustomAttributeData.GetCustomAttributes(RuntimeModule module, Int32 tkTarget)
   at Autofac.Util.ReflectionExtensions.HasSetsRequiredMembersAttribute(ConstructorInfo constructorInfo)

Dependency Versions

Autofac: v8.1.1
Autofac.Extensions.DependencyInjection: v10.0.0

Additional Info

I'll try and create a minumum working example. However it does look like that code related to how attributes are checked changed recently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions