dotnet / dotnet/dotNext

Odd Reflection Issue Loading DotNext.Threading Types Using Reflection

Open
#297 5 comments 0 reactions 0 assignees View on GitHub
Lib:Threading question wontfix
Dominant language
C#
Stars
2k
Forks
159
Avg merge
1d 3h
Merged PRs (30d)
2

Description

To recreate:

* Create a console app with the following settings (note: this should be run with .NET 11 Preview 7)
* `preview`
* `net11.0`
* 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.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.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](https://github.com/dotnet/runtime/issues?q=is%3Aissue%20state%3Aopen%20TypeLoadException) 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.

Contributor guide

Open the contributing guide

Research direction

Start with the Program.cs reproduction targeting net11.0 Preview 7 and calling GetTypes() on the DotNext.Threading assembly, then compare the same code targeting .NET 10. Inspect the reported ImmediateTask and DelayedTaskStateMachine types and determine whether the failure is in DotNext.Threading or the .NET preview; done means the reflection call loads all assembly types without TypeLoadException.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.