I have an exception thrown by a WPF application. The message is:
Type 'MyNamespacesPath.AType+<>c__DisplayClass5' in Assembly... is not marked as serializable
The problem is that the type cannot be serialized.
But that type is autogenerated, maybe an anonymous method or expression tree.
Anyone knows the exact origin of these kinds of types to know where to find the bug?
Types with that kind of name are generated when you write an anonymous method (using the
delegatesyntax or a lambda expression) that captures a local variable. The role of these types is to hold the values of the captured variablesNote that other kind of generated types have different names:
<>f__AnonymousType0<<a>j__TPar, <b>j__TPar>(generated bynew { a = 1, b = "2" }).<ZipIterator>d__0<TFirst, TSecond, TResult>(notice the name of the iterator method between the angled brackets)As far as I know, there is no documented rule for the naming of generated types, so you shouldn’t rely on these observations in your code. I’m just mentioning them for completeness.