I've reviewed your sample and experimented a little on my own, and
here are my findings (mostly reflecting your own):
- It's definitely a (.NET/debugger) bug related to in-memory
assemblies. If you reference the saved assembly from disk, the
exception doesn't occur.
- It seems that in order for the bug to appear, you need a combination
of nested generic types, generic methods, type initializers, and type
constraints.
- The bug occurs with differenct combinations of the above, depending
on the order of emitted items. As your last example shows, it even
goes so far that a successfully emitted type may trigger the bug for
the next emitted nested type.
I think, there's probably some internal metadata structure being
corrupted. As you say, we could switch to non-nested types, but it's
still a bug that should be fixed. If you report it on Connect (include
your sample code in the bug report! that makes a fix much more likely)
and post the link here so that we can vote for it.
Cheers,
Fabian
> >
>