TypeLoadException with type-level circular reference (structs only) - by hay_guise

Status : 


Sign in
to vote
ID 776953 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 1/18/2013 9:31:03 PM
Access Restriction Public


struct A, with field of type B<A>, where B is also a struct, causes a TypeLoadException at runtime. this happens even when B doesn't have fields of type A.
Sign in to post a comment.
Posted by Microsoft on 2/28/2013 at 9:53 AM
The fact that this kind of an error isn’t apparent at compile time is an unfortunate side effect of the way in which the .NET runtime handles generic types. While in C++ or Java, generics are resolved at compile time, .NET resolves them at runtime. This difference results in an interesting set of positives & negatives when compared to compile time generic resolution. Actually implementing compile time generic resolution, while helping to uncover problems like you’ve pointed out, would cause some pretty severe compatibility & performance problems with the overall system, so I can confirm that while I agree that the behavior you're hoping for is desirable, I can also tell you that the behavior you're asking for is not going to be possible in the next product cycle or two.
Posted by Microsoft on 1/21/2013 at 11:51 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by hay_guise on 1/21/2013 at 8:34 AM
i have attached a project.

the project compiles, but throws an exception when run.

it contains a Console.WriteLine call, but that can be replaced by anything that will cause the type to be loaded. just assigning 'new A()' to a variable causes the exception, if it doesn't get optimized away.
Posted by Microsoft on 1/20/2013 at 11:05 PM
I am having trouble reproducing your issue. Can you share a sample project on which you are seeing this problem?
Posted by Microsoft on 1/18/2013 at 9:51 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)