Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CreateType missing from TypeBuilder. How to port this?

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()
like image 562
Zoey M Avatar asked May 27 '16 16:05

Zoey M


People also ask

What to do if createtype createtype failed?

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.

What is the use of createtype () method in Java?

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.

Can I call createtype on a nested type?

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.

When to call createtype () method on an incomplete 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.


1 Answers

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.

like image 124
Zoey M Avatar answered Oct 21 '22 15:10

Zoey M