-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating Property of Generic Type fails when creating an Assembly using Reflection.Emit and MetadataLoadContext. #112155
Comments
Tagging subscribers to this area: @dotnet/area-system-reflection |
You should be able to workaround this by using -var listOfPoiType = listContextType.MakeGenericType(poiType);
+var listOfPoiType = Type.MakeGenericSignatureType(listContextType, poiType); For convenience, it may be nice if |
This allows the creation of the Type, but then the PersistedAssemblyBuilder fails to save the Assembly. It throws the following exception:
I've updated the repository, using Fields instead of Properties, for brevity. |
Hmmm, https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureConstructedGenericType.cs is missing implementation for |
@AugustoRuiz there is a PR up for v10 - do you need this ported to v9? |
Describe the bug
Cannot create a property of a Generic Type whose Type parameter is created using Reflection.Emit, when creating an assembly using MetadataLoadContext to use Reference Assemblies.
I am creating a DLL using
Reflection.Emit
from a JSON based description. This DLL has entity types that have properties with basic types, or with types already defined in the assembly that is being created. That works, but if the property is of a generic type, such as a List, and the generic type parameter is a type defined in the assembly being created, a System.ArgumentException is raised when invoking Type.MakeGenericType([entityType]).The error states:
To Reproduce
See the repository:
Repo in GitHub
Exceptions (if any)
System.ArgumentException:
An unhandled exception of type 'System.ArgumentException' occurred in System.Reflection.MetadataLoadContext.dll: 'This type 'Type: PurchaseOrderItem' was not loaded by the MetadataLoadContext that loaded the generic type or method.' at System.Reflection.TypeLoading.RoDefinitionType.MakeGenericType(Type[] typeArguments) at Program.<Main>$(String[] args) in ...\MetadataLoadContextError\Program.cs:line 37
Further technical details
dotnet --info
The text was updated successfully, but these errors were encountered: