Trying to port an application from .net 4.5 to .net core for a client. I'm noticing that CreateType is no longer part of TypeBuilder. I've searched through multiple of the new reflection libs with no luck. Does anyone know how to port this?
Code in question:
typeBuilder.CreateType()
End If Try tNested = eb.CreateType () If tNested Is Nothing Then Console.WriteLine ("NestedType CreateType failed but didn't throw!") End If Catch End Try ' This is needed because you might have already completed the type in the TypeResolve event.
After defining fields and methods on the class, CreateType is called in order to load its Type object. public Type? CreateType (); Returns the new Type object for this class. The enclosing type has not been created. This type is non-abstract and contains an abstract method.
The type cannot be loaded. For example, it contains a static method that has the calling convention HasThis. The following code example shows how to define an event handler for the AppDomain.TypeResolve event, in order to call the CreateType method on a nested type during a CreateType call on the enclosing type.
If the current type derives from an incomplete type or implements incomplete interfaces, call the CreateType method on the parent type and the interface types before calling it on the current type.
I found the answer, but in a different repository than I expected. CreateType was dropped, and CreateTypeInfo should be used now per this:
https://github.com/dotnet/coreclr/issues/2222
'TypeBuilder' does not contain a definition for 'CreateType' and no extension method 'CreateType' accepting a first argument of type 'TypeBuilder' could be found (are you missing a using directive or an assembly reference?)
Use typeBuilder.CreateTypeInfo() instead.
Hope this saves someone else time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With