how to export function in dll to aot?

mc 3,701 Reputation points
2024-04-23T02:04:43.3933333+00:00

I created .net class library to build dll and want to publish native aot

and I write function

public static MyClass
{
public static int MyFun(int n)
{
return n*n;
}
}

I publish it to native aot to win-x64 but in dll there is no function why?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,395 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,274 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,686 Reputation points
    2024-04-28T16:20:24.2933333+00:00

    Native aot libraries only support entry points with the [UnmanagedCallersOnly()] attribute.

    https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/?tabs=net8plus%2Cwindows#limitations-in-the-net-native-aot-deployment-model

    try:

    public static MyClass
    {
         [UnmanagedCallersOnly(EntryPoint = "MyClass_MyFun")]
         public static int MyFun(int n)
         {
              return n*n;
         }
    }
    
    0 comments No comments