The following code compiles in both VS2013 and VS2015, for various .NET Framework versions from 2.0 to 4.6.1, but when executed throws a System.TypeLoadException:
namespace Test
{
struct Foo<T>
{
}
struct Bar<U>
{
Foo<Bar<U>> foo;
}
class Program
{
static void Main(string[] args)
{
var x = new Bar<int>();
}
}
}
But if either Foo or Bar are changed from a struct to a class, it runs. I'm trying to understand why this doesn't work for two structs. Why is this code failing?
The exception message is:
"System.TypeLoadException occurred Message: A first chance exception of type 'System.TypeLoadException' occurred in mscorlib.dll Additional information: Could not load type 'Test.Bar`1' from assembly 'scratch, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."