다음 코드는 2.0에서 4.6.1 다양한 .NET 프레임 워크 버전, VS2013와 VS2015에서 모두 컴파일 실행 때 TypeLoadException이를 throw하지만 실행될 때 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>();
}
}
}
을
그러나 Foo 또는 Bar 중 하나가 구조체에서 클래스로 변경되면 실행됩니다. 왜이 두 structs 작동하지 않는 이해하려고 노력하고있어. 이 코드가 실패하는 이유는 무엇입니까?
예외 메시지는 다음과 같습니다
는"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'."
가능한 복제 (HTTP : // 유래 .com/questions/13731798/generics-in-struct-vs-class) – MethodMan
TypeLoadException 메시지는 무엇입니까? –
예외 메시지 : "System.TypeLoadException이 발생했습니다. 메시지 : mscorlib.dll에서 'System.TypeLoadException'유형의 첫 번째 예외가 발생했습니다. 추가 정보 : 어셈블리 'scratch에서'Test.Bar'1 '유형을로드 할 수 없습니다. 버전 = 1.0.0.0, 문화 = 중립, PublicKeyToken = null '. " –