Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Zaneo opened this issue Nov 25, 2024 · 2 comments
Labels
pending-input Pending input or update

Comments

@Zaneo
Copy link

Zaneo commented Nov 25, 2024

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.

@tillig
Copy link
Member

tillig commented Nov 25, 2024

I don't see anything in either of the noted items that would cause the described issue. We're definitely going to need to see a repro on this one. :)

@tillig tillig added the pending-input Pending input or update label Nov 25, 2024
@alexanderjshall
Copy link

Just to add I experienced this as a reflection error (same trace as above) in testing this week and luckily we discovered this amidst testing migrations between NET6 and NET8. The NET6 version had the error, the NET8 version did not. Difficult to add a repro without posting production code - I will try and dig more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-input Pending input or update
Projects
None yet
Development

No branches or pull requests

3 participants