Skip to content

NativeAOT fails to resolve PInvoke in System.Data.SqlClient #89874

@vitek-karas

Description

@vitek-karas

See #89782 (comment) for details.
The failure is really weird - I can confirm that the native dll is next to the AOT compiled app.
Non-AOT version of the app can load the dll just fine (it fails later on for me, but that's not the issue here).
I also tried just a simple app with a PInvoke (using Libuv package and calling into it) and that works just fine even with NativeAOT.

Repro steps:
https://github.com/dotnet/runtime/files/12243049/sqlClient.zip
Publish as AOT and run on win-x64.

Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'sni.dll' or one of its dependencies: The specified module could not be found.
   at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x6f
   at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0xfd
   at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x2f
   at System.Data.SqlClient.SNINativeMethodWrapper.UnmanagedIsTokenRestricted(IntPtr, Boolean&) + 0x31
   at System.Data.Win32NativeMethods.IsTokenRestrictedWrapper(IntPtr) + 0x19
   at System.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrentNative() + 0xb0
   at System.Data.ProviderBase.DbConnectionPoolGroup.GetConnectionPool(DbConnectionFactory) + 0x51
   at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPool(DbConnection, DbConnectionPoolGroup) + 0x5f
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection, TaskCompletionSource`1, DbConnectionOptions, DbConnectionInternal, DbConnectionInternal&) + 0xb6
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection, DbConnectionFactory, TaskCompletionSource`1, DbConnectionOptions) + 0x118
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1) + 0x101
   at System.Data.SqlClient.SqlConnection.Open() + 0xf8
   at Program.<Main>$(String[] args) + 0x45
   at sqlClient!<BaseAddress>+0x413074

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions