Why do I get a "loop in structure structure" with phantom types in C #?
As discussed in the comments, although this code is compiled using the MS C # compiler, it does not actually execute - it gives a TypeLoadException at runtime. Please note that the problem only occurs if both types are struct . So the question is, is this problem a C # compiler or runtime?
Since runtime is also covered by its own specification, I went through all parts of the CLI specification, which were even vagual, and I did not find anything that could prohibit this. Not in the definition of IL (obviously, since IL is considered valid), but not in runtime metadata structures.
Given this, I am more inclined to cause the implementation of the runtime to be erroneous. I suspect that when the Mono team encountered this problem, they decided to add a compiler error so that this situation was a lesser evil. Or maybe they just incorrectly evaluate the constraint of a cyclic struct :)
It may even be possible that it was not used to crash at runtime, which makes the C # compiler even more legit. Of course I can not check it :)
Unfortunately, this means that you cannot use this convenient design. Either make sure that one of the types is a class , or you just need to make a different type for each of these IdOfSomething yours. Just glad the Mono C # compiler told you this before you found out at runtime: P