Native aot libraries only support entry points with the [UnmanagedCallersOnly()] attribute.
try:
public static MyClass
{
[UnmanagedCallersOnly(EntryPoint = "MyClass_MyFun")]
public static int MyFun(int n)
{
return n*n;
}
}