I have an issue where the following code can throw a StackOverflowException
:
var t = typeof(SomeType).Assembly.DefinedTypes;
Debugging into it, the exception happens in RuntimeAssembly.cs
at GetType(this)
:
internal RuntimeType[] GetDefinedTypes()
{
return GetTypes(this);
}
It also seems to have something to do with target frameworks. SomeType
is defined in a project that targets .NET 6. The executing project is targeting .NET 7. If I change the executing project to target .NET 6, the exception goes away.
Accessing Asssembly.DefinedTypes
is the first call in Program.cs
so there is no loop of any kind in my code. I've also tried rebooting and rebuilding. global.json
specifies 7.0.400
.
Any ideas what could cause this?