You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Null reference on Microsoft.Data.SqlClient.SqlClientFactory.Instance #1424
I try to register SqlClient as a Dataprovider in my NetCore6 Application, but the Field Microsoft.Data.SqlClient.SqlClientFactory.Instance is null. It has worked before, but does not any more, since I implemented my own AssemblyResolver.
Where in the Code is the instance Assigned, so I can debug whats wrong. I get no exception when Loading the DLL, or before accessing that static field (I've enabled break on all exceptions in Visual Studio)
To reproduce
At the moment it will be hard to create a reproducible scenario. I'd firstly try to debug myself, if someone explains to me where the Field is assigned.
Expected behavior
A clear and concise description of what you expected to happen.
Further technical details
Microsoft.Data.SqlClient version: 4.0.0
.NET target: NET6.0
SQL Server version: doesn't matter
Operating system: Windows 10
I have almost the same problem! now on net7.0.
I found the problem only occurs if use own AssemblyResolver!! with the exception:
System.InvalidOperationException:“The requested .NET Data Provider's implementation does not have an Instance field of a System.Data.Common.DbProviderFactory derived type.”
In my project, i met the same issue when System.Data.SqlClient is only loaded by my own plugin assembly loader, where the AppDomain.CurrentDomain.AssemblyResolve delegate is used to resolve assemblies.
If i reference System.Data.SqlClien directly as nuget package in my entry assembly, it works well. but not possible as in plugin.
I think there's something wrong in underlying assembly resolving process, when use own assembly resolver.
I replaced System.Data.SqlClient with Microsoft.Data.SqlClient, it's the same issue.
Activity
jogibear9988 commentedon Dec 7, 2021
Okay, if I look here:
SqlClient/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientFactory.cs
Line 13 in c56baaa
the Factory is assigned immediately, but if I open the DLL on my system in ILSpy it looks like this:
jogibear9988 commentedon Dec 7, 2021
Ahhh....
now I found the dll in
runtimes\win\lib\netcoreapp3.1
jogibear9988 commentedon Dec 7, 2021
so I load the wrong one.
gumbarros commentedon Sep 15, 2022
I also having the same problem on Pop!_OS 22.10
kvisscher commentedon Oct 12, 2022
@gumbarros I'm having the same issue on Pop 22.04. Did you manage to solve your issue?
gumbarros commentedon Oct 12, 2022
No, but our customer updated to a more recent server and now is working. But in the old server still not working.
The upgrade was from WinServer 2012 to 2019 I think.
kvisscher commentedon Oct 12, 2022
@gumbarros thanks for the quick reply!
I actually just found another related issue that exactly matched my issue: #1643. Hopefully it can help someone in the future.
I installed dotnet via the apt repository, but for some reason, this didn't work. I reinstalled with the install script: https://learn.microsoft.com/en-us/dotnet/core/install/linux-scripted-manual#scripted-install and everything is up and running again.
gumbarros commentedon Oct 12, 2022
Sorry I saw the notification on my phone and confuded with this issue microsoft/azuredatastudio#11249 (comment).
To solve #1424 I manually installed .NET in my OS (without apt or snap)
xiaoyuvax commentedon Jun 16, 2023
I have almost the same problem! now on net7.0.
I found the problem only occurs if use own AssemblyResolver!! with the exception:
In my project, i met the same issue when System.Data.SqlClient is only loaded by my own plugin assembly loader, where the AppDomain.CurrentDomain.AssemblyResolve delegate is used to resolve assemblies.
If i reference System.Data.SqlClien directly as nuget package in my entry assembly, it works well. but not possible as in plugin.
I think there's something wrong in underlying assembly resolving process, when use own assembly resolver.
I replaced System.Data.SqlClient with Microsoft.Data.SqlClient, it's the same issue.