Skip to content

NativeAOT when building shared library #71063

Closed

Description

@rodrigovaras

Description

Attempting to create a shared library using the NativeAOT tools on my managed assembly entry point.
I tried the NativeLibrary and succeeded but not my project.

Reproduction Steps

Create a .NET project that has several dependencies. Attempt to run:
dotnet publish /p:NativeLib=Shared /p:SelfContained=true -r win-x64 -c Release <Myproject.csproj>

Expected behavior

Native library being created for the Windows platform

Actual behavior

EXEC : error : Failed to load type 'Void ()' from assembly '?' [D:\mr\mixedreality.eu.proto\client\sdk.net\src\Hololen
s\Hololens.Runtime.Native\Hololens.Runtime.Native.csproj]
Internal.TypeSystem.TypeSystemException+TypeLoadException: Failed to load type 'Void ()
' from assembly '?'
at Internal.TypeSystem.ThrowHelper.ThrowTypeLoadException(ExceptionStringID id, String typeName, String assemblyNa
me) in //src/coreclr/tools/Common/TypeSystem/Common/ThrowHelper.cs:line 17
at ILCompiler.DependencyAnalysis.EETypeNode..ctor(NodeFactory factory, TypeDesc type) in /
/src/coreclr/tools/aot/
ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs:line 81
at ILCompiler.DependencyAnalysis.NodeFactory.CreateNecessaryTypeNode(TypeDesc type) in //src/coreclr/tools/aot/IL
Compiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs:line 508
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
at ILCompiler.DependencyAnalysis.ReflectableFieldNode.GetStaticDependencies(NodeFactory factory) in /
/src/coreclr
/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectableFieldNode.cs:line 89
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer2.GetStaticDependenciesImpl(DependencyNodeCore1 node
) in //src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 181
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer2.GetStaticDependencies(DependencyNodeCore1 node) in
/
/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 221
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer2.ProcessMarkStack() in /_/src/coreclr/tools/aot/ILCo mpiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 256 at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer2.ComputeMarkedNodes() in //src/coreclr/tools/aot/IL
Compiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 307
at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan() in /
/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILSc
anner.cs:line 140
at ILCompiler.Program.Run(String[] args) in //src/coreclr/tools/aot/ILCompiler/Program.cs:line 833
at ILCompiler.Program.Main(String[] args) in /
/src/coreclr/tools/aot/ILCompiler/Program.cs:line 1090
C:\Users\rodrigov.nuget\packages\microsoft.dotnet.ilcompiler\7.0.0-preview.6.22321.1\build\Microsoft.NETCore.Native.ta
rgets(270,5): error MSB3073: The command ""C:\Users\rodrigov.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompile
r\7.0.0-preview.6.22321.1\tools\ilc" @"D:\mr\mixedreality.eu.proto\client\sdk.net\bin\obj\Hololens.Runtime.Native\Rele
ase\net6.0-windows10.0.19041.0\win-x64\native\MixedReality.EU.HoloLens.Runtime.Native.ilc.rsp"" exited with code 1. [D:
\mr\mixedreality.eu.proto\client\sdk.net\src\Hololens\Hololens.Runtime.Native\Hololens.Runtime.Native.csproj]

Regression?

No response

Known Workarounds

No response

Configuration

.NET -> 6.0.300
Architecture : win-x64

Other information

No response

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Jun 21, 2022
  2. MichalStrehovsky commented on Jun 22, 2022

    @MichalStrehovsky
    Member

    Could you do a search in your codebase for fields that have delegate*<void> somewhere in their type? From the stack the issue you're running into is caused by a field of type delegate*<void> but we have explicit code that should make this situation impossible to reach:

    // Runtime reflection stack needs to obtain the type handle of the field
    // (but there's no type handles for function pointers)
    if (!_field.FieldType.IsFunctionPointer)
    dependencies.Add(factory.MaximallyConstructableType(_field.FieldType.NormalizeInstantiation()), "Type of the field");

    ReflectableFieldNode.GetStaticDependencies should never be calling CreateNecessaryTypeNode if the type of the field is a function pointer. It's a bit of a puzzle how we end up with the stack/error you're hitting.

  3. rodrigovaras commented on Jun 23, 2022

    @rodrigovaras
    Author

    Could you do a search in your codebase for fields that have delegate*<void> somewhere in their type? From the stack the issue you're running into is caused by a field of type delegate*<void> but we have explicit code that should make this situation impossible to reach:

    // Runtime reflection stack needs to obtain the type handle of the field
    // (but there's no type handles for function pointers)
    if (!_field.FieldType.IsFunctionPointer)
    dependencies.Add(factory.MaximallyConstructableType(_field.FieldType.NormalizeInstantiation()), "Type of the field");

    ReflectableFieldNode.GetStaticDependencies should never be calling CreateNecessaryTypeNode if the type of the field is a function pointer. It's a bit of a puzzle how we end up with the stack/error you're hitting.

    Hi Michael, i did more research and our project define the framework target as 'net6.0-windows' , this seems to be reason of the problem. The reason we will forced to do that is because of some winrt C# interop required for some of the components. I experiment removing the dependency and use 'net6.0' and it seems to work now (of course without the full functionality we needed) but it was a good exercise to see the trimming warnings and the size of the generated dll. If you are curious the size is around 22 MB compared with a 'from the scratch C++ native effort' that is around 8.5 MB. Closing this since the problem goes away. Please comment if in the future a specific 'windows only' target would eventually work.

  4. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on Jun 23, 2022
  5. ghost locked as resolved and limited conversation to collaborators on Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions