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
I understand MS.Data.SqlClient does not support trimming yet. Could the team share a build configuration that works in .NET 8.0 to include SqlClient untrimmed into an exe that is otherwise trimmed?
My goal is to publish a CLI tool that is self-contained -- and obviously trimmed for size.
Since I updated to latest MS.Data.SqlClient and .NET 8.0, no configuration I tried to exclude SqlClient from trimming works.
The only setup that works is completely disabling trimming, and insead of being ~30Mo the self-contained executable is ~180Mo now. That's terrible for a CLI tool.
Most things I tried usually end up in a TypeLoadException with "Unable to load DLL 'Microsoft.Data.SqlClient.SNI.dll'".
And I've tried to go back to the previous default of partial for TrimMode, I've tried rooting MS.Data.SqlClient with TrimmerRootAssembly but it didn't work.
I'd like an example of a csproj configuration where .net 8 trimming works in a project using SqlClient (understanding that SqlClient itself can't be trimmed, but the rest should).
Hi,
Did you ever get anywhere with getting this to work?
I've been trying to get a trimmed self contained app working on .NET 9 and getting TypeInitializationExceptions when it does some SSL setup in TDSParser, and as you say, setting trim mode and rooting the SqlClient assembly doesn't help.
Marking System.Private.CoreLib as a root assembly does seem to help, but I haven't worked out exactly what it is that's getting trimmed when it shouldn't yet
As of 7.0.0-preview1, it's technically possible to use RuntimeHostConfigurationOption to set the UseManagedNetworkingOnWindows AppContext switch. This will allow the IL trimmer to remove the unused SNI (whether this is managed or native.)
Setting this to true will force SqlClient to use the managed SNI and remove all references to the native SNI, setting it to false will do the opposite.
With this being said: SqlClient doesn't officially support trimming. The RuntimeHostConfigurationOption approach is undocumented because it doesn't completely unlock the feature.
A handful of features aren't trim-compatible at all:
The native SNI isn't statically linked to the finished EXE (which also blocks untrimmed single-file publishing.)
Using System.Configuration to dynamically load a type based on app.config will be hit-and-miss at best. The use of System.Configuration can't be trimmed because it's the only way to define LocalDB instance versions.
User-defined CLR types don't work, and I don't think will be able to work without a new library API of some kind to register the type - SQL Server sends the type information as a string at runtime, long after the linker has done its work.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
I understand MS.Data.SqlClient does not support trimming yet.
Could the team share a build configuration that works in .NET 8.0 to include SqlClient untrimmed into an exe that is otherwise trimmed?
My goal is to publish a CLI tool that is self-contained -- and obviously trimmed for size.
Since I updated to latest MS.Data.SqlClient and .NET 8.0, no configuration I tried to exclude SqlClient from trimming works.
The only setup that works is completely disabling trimming, and insead of being ~30Mo the self-contained executable is ~180Mo now. That's terrible for a CLI tool.
Most things I tried usually end up in a TypeLoadException with "Unable to load DLL 'Microsoft.Data.SqlClient.SNI.dll'".
All reactions