Skip to content
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

NativeAOT cannot create generic type even if it is rooted using rd.xml #79930

Closed
kant2002 opened this issue Dec 23, 2022 · 5 comments
Closed

Comments

@kant2002
Copy link
Contributor

Description

When attempt to run Blazor Hybrid + Winforms I ecounter following issue in the Microsoft.JSInterop

Location of the issue is here
https://github.com/dotnet/aspnetcore/blob/95c74fef646a262909be462c9edda8d8ed4d5b24/src/JSInterop/Microsoft.JSInterop/src/Infrastructure/TaskGenericsUtil.cs#L31-L34

Reproduction Steps

Program.cs

// See https://aka.ms/new-console-template for more information
var task = Task.CompletedTask;
var result = System.Activator.CreateInstance(typeof(T<>).MakeGenericType(task.GetType().GetGenericArguments()[0]));
Console.WriteLine("Success!");

class T<TT>
{
}

rd.xml

<?xml version="1.0" encoding="utf-8" ?>
<Directives>
  <Application>
    <Assembly Name="testaot" Dynamic="Required All">
      <Type Name="T`1[[System.Threading.Tasks.VoidTaskResult,System.Private.CoreLib]]" Dynamic="Required All" />
    </Assembly>
    <Assembly Name="System.Private.CoreLib">
      <Type Name="System.Threading.Tasks.VoidTaskResult" Dynamic="Required All" />
    </Assembly>
  </Application>
</Directives>

Expected behavior

Resulting program produce "Success!";

Actual behavior

Unhandled Exception: System.NotSupportedException: 'T`1[]' is missing native code or metadata. This can happen for code that is not compatible with trimming or AOT. Inspect and fix trimming and AOT related warnings that were generated when the app was published. For more information see https://aka.ms/nativeaot-compatibility
   at System.Reflection.Runtime.General.TypeUnifier.WithVerifiedTypeHandle(RuntimeConstructedGenericTypeInfo, RuntimeTypeInfo[]) + 0x166
   at System.Reflection.Runtime.General.TypeUnifier.GetConstructedGenericTypeWithTypeHandle(RuntimeTypeInfo, RuntimeTypeInfo[]) + 0x3b
   at System.Reflection.Runtime.TypeInfos.RuntimeTypeInfo.MakeGenericType(Type[]) + 0x44c
   at Program.<Main>$(String[]) + 0xf2
   at testaot!<BaseAddress>+0x28d037
   at testaot!<BaseAddress>+0x28d0ca

Regression?

No

Known Workarounds

Did not exists probably

Configuration

.NET 7.0.1

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Dec 23, 2022
@ghost
Copy link

ghost commented Dec 23, 2022

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

When attempt to run Blazor Hybrid + Winforms I ecounter following issue in the Microsoft.JSInterop

Location of the issue is here
https://github.com/dotnet/aspnetcore/blob/95c74fef646a262909be462c9edda8d8ed4d5b24/src/JSInterop/Microsoft.JSInterop/src/Infrastructure/TaskGenericsUtil.cs#L31-L34

Reproduction Steps

Program.cs

// See https://aka.ms/new-console-template for more information
var task = Task.CompletedTask;
var result = System.Activator.CreateInstance(typeof(T<>).MakeGenericType(task.GetType().GetGenericArguments()[0]));
Console.WriteLine("Success!");

class T<TT>
{
}

rd.xml

<?xml version="1.0" encoding="utf-8" ?>
<Directives>
  <Application>
    <Assembly Name="testaot" Dynamic="Required All">
      <Type Name="T`1[[System.Threading.Tasks.VoidTaskResult,System.Private.CoreLib]]" Dynamic="Required All" />
    </Assembly>
    <Assembly Name="System.Private.CoreLib">
      <Type Name="System.Threading.Tasks.VoidTaskResult" Dynamic="Required All" />
    </Assembly>
  </Application>
</Directives>

Expected behavior

Resulting program produce "Success!";

Actual behavior

Unhandled Exception: System.NotSupportedException: 'T`1[]' is missing native code or metadata. This can happen for code that is not compatible with trimming or AOT. Inspect and fix trimming and AOT related warnings that were generated when the app was published. For more information see https://aka.ms/nativeaot-compatibility
   at System.Reflection.Runtime.General.TypeUnifier.WithVerifiedTypeHandle(RuntimeConstructedGenericTypeInfo, RuntimeTypeInfo[]) + 0x166
   at System.Reflection.Runtime.General.TypeUnifier.GetConstructedGenericTypeWithTypeHandle(RuntimeTypeInfo, RuntimeTypeInfo[]) + 0x3b
   at System.Reflection.Runtime.TypeInfos.RuntimeTypeInfo.MakeGenericType(Type[]) + 0x44c
   at Program.<Main>$(String[]) + 0xf2
   at testaot!<BaseAddress>+0x28d037
   at testaot!<BaseAddress>+0x28d0ca

Regression?

No

Known Workarounds

Did not exists probably

Configuration

.NET 7.0.1

Other information

No response

Author: kant2002
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

@kant2002
Copy link
Contributor Author

Not sure, but type which is passed as parameter to MakeGenericType is actually Boxed VoidTaskResult and is ReflectionBlockedType

@MichalStrehovsky
Copy link
Member

Try adding <IlcArg Include="--nometadatablocking" /> to an ItemGroup

@kant2002
Copy link
Contributor Author

kant2002 commented Dec 23, 2022 via email

@MichalStrehovsky
Copy link
Member

Getting rid of reflection blocking is tracked in #72570 but currently it's by design that is not possible to reflect on implementation details.

@MichalStrehovsky MichalStrehovsky closed this as not planned Won't fix, can't repro, duplicate, stale Dec 24, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Dec 24, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jan 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants