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

.NET Library not working in NativeAot #506

Open
GEEKiDoS opened this issue Apr 10, 2023 · 0 comments
Open

.NET Library not working in NativeAot #506

GEEKiDoS opened this issue Apr 10, 2023 · 0 comments

Comments

@GEEKiDoS
Copy link

GEEKiDoS commented Apr 10, 2023

Bug Report

The .NET library is not functioning when compiled with NativeAot, resulting in an exception being thrown.

Steps to Reproduce

  1. Compile the code using the PublishAot option.

Observed behavior

An exception is thrown with the following message:

A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.

Environment

  • OS version: Windows 10 22H2 (10.0.19045.2728)
  • WinFsp version and build: 2023
  • dotnet version: 7.0.202

Temporary Solution

The issue stems from the static constructor of Fsp.Interop.Api. To resolve this, perform the following changes:

  1. Replace the static constructor with a static Init method and manually call it before executing your code.
  2. Modify the GetEntryPoint method in the class as follows:
private static T GetEntryPoint<T>(IntPtr Module)
{
    return Marshal.GetDelegateForFunctionPointer<T>(GetEntryPointPtr(Module, typeof(T).Name));
}

I hope this will help people that using NativeAOT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant