Skip to content

Odd Reflection Issue Loading DotNext.Threading Types Using Reflection #297

Closed as not planned

Description

@JasonBock

To recreate:

  • Create a console app with the following settings (note: this should be run with .NET 11 Preview 7)
    • <LangVersion>preview</LangVersion>
    • <TargetFramework>net11.0</TargetFramework>
  • Reference the DotNext.Threading NuGet package, version 6.6.5
  • Add this to Program.cs:
    • _ = typeof(DotNext.Threading.AsyncAutoResetEvent).Assembly.GetTypes();

I would expect this to return the types in the assembly. What I get is a TypeLoadException:

System.TypeLoadException: Method 'get_Task' in type 'DotNext.Threading.Tasks.<TaskSchedulerExtensions_T>FEC23FF8E24C5C893F2B0DCE3A3DBD6B033A895D525ABEAE11C935B5879FC7CF4__ImmediateTask`2' from assembly 'DotNext.Threading, Version=6.6.1.0, Culture=neutral, PublicKeyToken=c8827b44e18fe572' does not have an implementation.
System.TypeLoadException: Method 'get_Task' in type 'DotNext.Threading.Tasks.<TaskSchedulerExtensions_T>FEC23FF8E24C5C893F2B0DCE3A3DBD6B033A895D525ABEAE11C935B5879FC7CF4__DelayedTaskStateMachine`2' from assembly 'DotNext.Threading, Version=6.6.1.0, Culture=neutral, PublicKeyToken=c8827b44e18fe572' does not have an implementation.

I'm not sure this is a DotNext-specific issue. It may be something that's broken in the preview version of .NET 11 with the way these types are file scoped. If you feel like this is a general .NET issue, I can file it there, referencing this issue. I did a search for any current issues reported with TypeLoadException and nothing seemed related to this.

I also ran the same code targeting .NET 10 and it works with no issues, so ... I'm guessing this is .NET 11-specific.

Activity

  1. sakno commented on Aug 31, 2026

    @sakno
    Collaborator

    I think it's an issue in .NET 11 Reflection subsystem. The issue is related to the fact that ImmediateTask<TArgs, TResult> derives from DelayedTask<TResult> where Task property is overridden as follows:

    public abstract override Task<TResult> Task { get; }

    But DelatedTask<TResult> derives from DelayedTask, which defines Task property as

    public abstract Task Task { get; }

    C# allows covariant return types in overrides since version 9.0. It also requires runtime support, which is probably broken in .NET 11 Preview.

  2. added
    Lib:Threading
    question
    wontfix
    on Aug 31, 2026
  3. sakno commented on Aug 31, 2026

    @sakno
    Collaborator

    I think you can verify my hypothesis with similar trick:

    public abstract class A
    {
        public abstract object Property { get; }
    }
    
    public abstract class B : A
    {
        public override abstract string Property { get; }
    }
    
    public sealed class C : B
    {
        public override string Property => string.Empty;
    }

    Then, load these class by using Reflection.

  4. JasonBock commented on Aug 31, 2026

    @JasonBock
    Author

    @sakno I tried that, but it seems to work:

    var types = typeof(C).Assembly.GetTypes(); 
    Console.WriteLine(types.Length);
    
    public abstract class A
    {
    	public abstract object Property { get; }
    }
    
    public abstract class B : A
    {
    	public override abstract string Property { get; }
    }
    
    public sealed class C : B
    {
    	public override string Property => string.Empty;
    }

    That prints 4 when I run it, whether I target .NET 10 or .NET 11, and putting them into a separate project didn't seem to matter.

    I'll still report this to the .NET runtime repo as I agree, I don't think this is dotNext-specific.

  5. sakno commented on Sep 1, 2026

    @sakno
    Collaborator

    Try with generics:

    public abstract class A
    {
    	public abstract object Property { get; }
    }
    
    public abstract class B<T> : A
       where T : class
    {
    	public override abstract T Property { get; }
    }
    
    public sealed class C : B<string>
    {
    	public override string Property => string.Empty;
    }

    Possibly, some combination of generics and covariant overload raises the exception.

  6. JasonBock commented on Sep 1, 2026

    @JasonBock
    Author

    @sakno that works fine as well. Reading what the .NET folks are saying on the issue I created, it seems like it's specific to Task-returning methods that are overridden to return Task<T> . It seems like this may already be fixed, just need another release to test the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Lib:Threadingquestionwontfix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions