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
.NET Standard library not working with .NET Framework #2786
If you are using the Microsoft.Data.SqlClient NuGet in a .NET Standard project which you are referencing in a .NET Framework project it throws the following exception.
Exception message: System.IO.FileNotFoundException: 'Die Datei oder Assembly "Microsoft.Data.SqlClient, Version=5.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.'
Stack trace: at StandardLibary.SqlClientWrapper.MakeConnectionToLocalhost() in C:\Users\LNA\source\repos\SqlClient.FrameworkStandard.MRE\StandardLibary\SqlClientWrapper.cs:line 10
at FrameworkProject.Program.Main(String[] args) in C:\Users\LNA\source\repos\SqlClient.FrameworkStandard.MRE\SqlClient.FrameworkStandard.MRE\Program.cs:line 12
I also noticed that if you take a closer look at the DLLs provided by the NuGet you can see that in the netstandard2.0 folder there only is a .NETCoreApp v8.0 DLL and not the required .NET Standard one.
Workaround
For me the only way to get the NuGet to work is using a older version (5.1.3). But since then there is the wrong version in the .NET Standard folder.
Hej @dauinsight I experimented a bit with the different versions.
Using the MRE it throws the same exception regardless of the version. But if I add <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> to the csproj the error changes to platform not supported. (Maybe this is somehow related? dotnet/runtime#103662)
In our real code it behaves a bit different. I think this is because we run the dotnet publish --runtime win command which seems to fix the platform not supported issues. So if you build the StandardLibary project in my example, run the dotnet publish command and paste the files in the Framework project it works with version 5.1.3. All newer versions do not seem to work. (As I mentioned previously I think this is caused by the .NET Core DLL in the .NET Standard folder)
If I try to do the same process with a newer version I get the exception:
FileLoadException: Could not load file or assembly 'System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
with stack trace:
at Microsoft.Data.SqlClient.SqlConnection..ctor()
at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString)
at StandardLibary.SqlClientWrapper.MakeConnectionToLocalhost() in C:\Users\LNA\source\repos\SqlClient.FrameworkStandard.MRE\StandardLibary\SqlClientWrapper.cs:line 9
I double checked the versions and found out that I was wrong. Version 5.1.5 is the latest working one. Version 5.2.0 and 5.2.1 both have the same error.
If the latest failing version is 5.2.0: it sounds like this could be related to issue #2535. We are releasing 5.2.2 hotfix soon that will address this issue so stay tuned for that.
@LNA-DEV I would suggest going through this documentation first, have you tried having a multi target frameworks for your application instead of having two separate projects? I had a brief look at your repro and those two netcore and netframework are looking almost identical. Based on the documentation provided it is better to do so
@JRahnama It is a bit more complex in our real world implementation. I added the two projects mainly to show the difference between .NET and .NET Framework.
We are building a sort of plugin for our software which currently runs in Framework. But for the future we want to have the flexibility to change that and therefore want to use .NET Standard for the plugin. (Which only works in version 5.1.5 that's the issue)
Multi targeting might be something worth looking into in the future but I am not sure how well it works in our case, because we are doing a bit of manual DLL loading. However thanks for the suggestion. Could be a benefit for us👍
Nevertheless if I install a NuGet which has support for .NET Standard I expect it to work in both Framework and .NET. Which I think currently is not the case.
@JRahnama I can confirm this workaround is working for the project I provided. (But I do not understand why. What is SDK-style changing?)
For our production application this does not work because we are publishing the .NET Standard project directly (with runtime win). But we are using v5.1.5 there until the NuGet is fixed.
FYI: Version 5.2.2 does not seem to solve this issue
Thanks for the details
If the latest failing version is 5.2.0: it sounds like this could be related to issue #2535. We are releasing 5.2.2 hotfix soon that will address this issue so stay tuned for that.
@JRahnama That is a good workaround and possibly a clue to the fix needed under the hood.
Unfortunately, in our case the workaround doesn't help as our .NET Framework project is a Web Site project, so there is no .csproj file at all to change to SDK-style. We would be really interested in a fix for this issue, as it's forcing us to do some wild re-architecting (we have a huge legacy .NET 4.8.1 app with many pieces that we are slowly migrating to .NET 8+.)
Checking in, @JordanRieger are you still experiencing issues with the latest MDS v6.1.3?
@cheenamalhotra Yes, I just tested, and it's still occurring.
If, as a workaround, I try manually copying the Microsoft.Data.SqlClient.dll file from the \Microsoft.Data.SqlClient.6.1.3\lib\net462 folder to the \bin folder of my .NET Framework 4.8.1 Web Site project (WSP), I get this error:
Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x64.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
For fun, I downloaded the Microsoft.Data.SqlClient.SNI package, which has a scary "Internal implementation package not meant for direct consumption. Please do not reference directly" warning, and then copied the \microsoft.data.sqlclient.sni.6.0.2\build\net462\Microsoft.Data.SqlClient.SNI.x64.dll file to the \bin folder of my project, and that actually seems to work!
Do you think this is a safe workaround?
(Note that a WSP has no .csproj file and cannot easily be converted to a SDK project or Web Application Project (WAP) and due to its ASPX Web Forms dependencies, cannot easily be converted to a .NET 5+ project.)
All required environment details provided for investigation (SqlClient 5.2.1, .NET target v4.8, OS Windows; SQL Server version not applicable — failure occurs during assembly load, before a connection is attempted)
Area
Area\Netfx
Duplicates
Potentially related: #3316 (feature "Bring back .NET Standard support", closed/completed), #4461 (publish resolves reference assembly instead of runtime assembly), #2535
Regression
Likely regression from v5.1.5 — reporter confirms 5.1.5 is the last working version; 5.2.0/5.2.1/5.2.2/6.1.3 all reproduce the failure
Analysis
A .NET Standard 2.0 class library referencing Microsoft.Data.SqlClient fails to load the correct assembly when consumed from a .NET Framework 4.8 host: the netstandard2.0 folder in the NuGet package ships a .NET-Core-only build, so at runtime .NET Framework throws FileNotFoundException/FileLoadException (missing Microsoft.Data.SqlClient/System.Runtime.Loader). Community workarounds (SDK-style csproj conversion, manual Microsoft.Data.SqlClient.SNI.x64.dll copying) are unreliable and don't apply to non-SDK project types (e.g. ASP.NET Web Site Projects), which have no .csproj to convert. This is a long-standing (2+ year), high-impact packaging/targeting issue affecting cross-targeted apps still bridging .NET Framework and .NET/.NET Standard. Severity: P2 — real, reproducible regression with viable but incomplete workarounds, blocking legacy-to-modern migration paths for multiple reporters as recently as v6.1.3.
Next Steps
Assign to Copilot coding agent to investigate why the netstandard2.0 output of Microsoft.Data.SqlClient.csproj embeds a .NET-Core-targeted assembly instead of a true netstandard2.0-compatible build, and confirm whether the netstandard2.0 TFM was fully restored per Bring back .NET Standard support #3316, or whether the assembly-resolution/runtime-selection logic (similar to the root cause in dotnet publish -r linux-x64 resolves reference assembly instead of runtime assembly for net10.0 apps #4461) still misroutes to the wrong lib/runtimes folder when netstandard2.0 is the direct target and .NET Framework is the ultimate host.
Verify current package versions (6.1.3+, and any 7.x) against the exact MRE in this issue to confirm whether the fix from Bring back .NET Standard support #3316 fully resolves this specific netstandard2.0-in-netfx-host scenario, since the latest comment (Nov 2025) still reports the failure on 6.1.3.
Note: This triage summary is auto-generated by an AI agent. The analysis and suggestions above have not been verified by a human maintainer. Please treat as preliminary guidance only.
Activity
dauinsight commentedon Aug 20, 2024
Hi @LNA-DEV we'll look into this issue further.
Can I confirm again - Microsoft.Data.SqlClient 5.1.3 is the earliest working version? So 5.1.4 and beyond all encounter the same issue?
LNA-DEV commentedon Aug 20, 2024
Hej @dauinsight I experimented a bit with the different versions.
Using the MRE it throws the same exception regardless of the version. But if I add
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>to the csproj the error changes to platform not supported. (Maybe this is somehow related? dotnet/runtime#103662)In our real code it behaves a bit different. I think this is because we run the
dotnet publish --runtime wincommand which seems to fix the platform not supported issues. So if you build the StandardLibary project in my example, run the dotnet publish command and paste the files in the Framework project it works with version 5.1.3. All newer versions do not seem to work. (As I mentioned previously I think this is caused by the .NET Core DLL in the .NET Standard folder)If I try to do the same process with a newer version I get the exception:
with stack trace:
LNA-DEV commentedon Aug 20, 2024
I double checked the versions and found out that I was wrong. Version 5.1.5 is the latest working one. Version 5.2.0 and 5.2.1 both have the same error.
dauinsight commentedon Aug 20, 2024
Thanks for the details
If the latest failing version is 5.2.0: it sounds like this could be related to issue #2535. We are releasing 5.2.2 hotfix soon that will address this issue so stay tuned for that.
JRahnama commentedon Aug 21, 2024
@LNA-DEV I would suggest going through this documentation first, have you tried having a multi target frameworks for your application instead of having two separate projects? I had a brief look at your repro and those two netcore and netframework are looking almost identical. Based on the documentation provided it is better to do so
LNA-DEV commentedon Aug 22, 2024
@JRahnama It is a bit more complex in our real world implementation. I added the two projects mainly to show the difference between .NET and .NET Framework.
We are building a sort of plugin for our software which currently runs in Framework. But for the future we want to have the flexibility to change that and therefore want to use .NET Standard for the plugin. (Which only works in version 5.1.5 that's the issue)
Multi targeting might be something worth looking into in the future but I am not sure how well it works in our case, because we are doing a bit of manual DLL loading. However thanks for the suggestion. Could be a benefit for us👍
Nevertheless if I install a NuGet which has support for .NET Standard I expect it to work in both Framework and .NET. Which I think currently is not the case.
JRahnama commentedon Aug 23, 2024
@LNA-DEV I tested below scenarios:
LNA-DEV commentedon Aug 26, 2024
@JRahnama I can confirm this workaround is working for the project I provided. (But I do not understand why. What is SDK-style changing?)
For our production application this does not work because we are publishing the .NET Standard project directly (with runtime win). But we are using v5.1.5 there until the NuGet is fixed.
LNA-DEV commentedon Sep 3, 2024
FYI: Version 5.2.2 does not seem to solve this issue
JordanRieger commentedon Apr 3, 2025
@JRahnama That is a good workaround and possibly a clue to the fix needed under the hood.
Unfortunately, in our case the workaround doesn't help as our .NET Framework project is a Web Site project, so there is no .csproj file at all to change to SDK-style. We would be really interested in a fix for this issue, as it's forcing us to do some wild re-architecting (we have a huge legacy .NET 4.8.1 app with many pieces that we are slowly migrating to .NET 8+.)
Thanks!
1 remaining item
cheenamalhotra commentedon Nov 24, 2025
Checking in, @JordanRieger are you still experiencing issues with the latest MDS v6.1.3?
JordanRieger commentedon Nov 25, 2025
@cheenamalhotra Yes, I just tested, and it's still occurring.
If, as a workaround, I try manually copying the Microsoft.Data.SqlClient.dll file from the \Microsoft.Data.SqlClient.6.1.3\lib\net462 folder to the \bin folder of my .NET Framework 4.8.1 Web Site project (WSP), I get this error:
For fun, I downloaded the Microsoft.Data.SqlClient.SNI package, which has a scary "Internal implementation package not meant for direct consumption. Please do not reference directly" warning, and then copied the \microsoft.data.sqlclient.sni.6.0.2\build\net462\Microsoft.Data.SqlClient.SNI.x64.dll file to the \bin folder of my project, and that actually seems to work!
Do you think this is a safe workaround?
(Note that a WSP has no .csproj file and cannot easily be converted to a SDK project or Web Application Project (WAP) and due to its ASPX Web Forms dependencies, cannot easily be converted to a .NET 5+ project.)
priyankatiwari08 commentedon Sep 17, 2026
/triage
github-actions commentedon Sep 17, 2026
🔍 Triage Summary (on-demand re-triage)
Area\NetfxAnalysis
A .NET Standard 2.0 class library referencing
Microsoft.Data.SqlClientfails to load the correct assembly when consumed from a .NET Framework 4.8 host: thenetstandard2.0folder in the NuGet package ships a .NET-Core-only build, so at runtime .NET Framework throwsFileNotFoundException/FileLoadException(missingMicrosoft.Data.SqlClient/System.Runtime.Loader). Community workarounds (SDK-style csproj conversion, manualMicrosoft.Data.SqlClient.SNI.x64.dllcopying) are unreliable and don't apply to non-SDK project types (e.g. ASP.NET Web Site Projects), which have no.csprojto convert. This is a long-standing (2+ year), high-impact packaging/targeting issue affecting cross-targeted apps still bridging .NET Framework and .NET/.NET Standard. Severity: P2 — real, reproducible regression with viable but incomplete workarounds, blocking legacy-to-modern migration paths for multiple reporters as recently as v6.1.3.Next Steps
netstandard2.0output ofMicrosoft.Data.SqlClient.csprojembeds a .NET-Core-targeted assembly instead of a true netstandard2.0-compatible build, and confirm whether the netstandard2.0 TFM was fully restored per Bring back .NET Standard support #3316, or whether the assembly-resolution/runtime-selection logic (similar to the root cause in dotnet publish -r linux-x64 resolves reference assembly instead of runtime assembly for net10.0 apps #4461) still misroutes to the wronglib/runtimesfolder when netstandard2.0 is the direct target and .NET Framework is the ultimate host.