-
Notifications
You must be signed in to change notification settings - Fork 300
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
SQLConnection GetSchema with PublishTrimmed not working #822
Comments
Tagging subscribers to this area: @cheenamalhotra, @David-Engel Issue DetailsIssue TitleGetSchema stops working when I publish my .Net Core 3.1 app with the single file and trimmed option. GeneralWhen using this code I am getting an error. The exception says: "Column requires a valid DataType." Code example: I was debugging this for a long time, and then I thought that maybe the trimming option had trimmed a bit too much. Sure enough, the problem was gone when I removed the trim option. My CSProj settings: Not sure if Linux and Mac has the same issue, I have only tested with Windows 10 64 bit.
|
I don't believe the library is tested at all with trimming and it is probably advisable to disable it from the trimable list. |
I can repro the issue. I suspect this is just the first error of many that would be hit. SqlClient uses reflection in its code and the trim feature is removing dependent code/assemblies that it is simply failing to detect as being referenced. I'd avoid the feature for now. There are new APIs in .NET 5 that might help, but it looks like it transfers a lot of burden to library developers to annotate their code to help the analyzers. |
If you've got a trimmed binary you could probably use https://github.com/bitdiffer/bitdiffer to identify the types which had been removed and then audit them to identify which need to be preserved. I know there's a bit of reflection in SqlTypeWorkarounds but not a lot else springs to mind. |
Closing in favor of #1947 |
Issue Title
GetSchema stops working when I publish my .Net Core 3.1 app with the single file and trimmed option.
General
When using this code I am getting an error. The exception says: "Column requires a valid DataType."
Code example:
var sqlConnection = new SqlConnection(_connectionString); string[] restrictions = new string[4] { null, dbSchema, dataTable.TableName, null }; DataTable data = sqlConnection.GetSchema("Columns", restrictions);
I was debugging this for a long time, and then I thought that maybe the trimming option had trimmed a bit too much. Sure enough, the problem was gone when I removed the trim option.
My CSProj settings:
<OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> <PublishSingleFile>true</PublishSingleFile> <PublishTrimmed>false</PublishTrimmed> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
Not sure if Linux and Mac has the same issue, I have only tested with Windows 10 64 bit.
The text was updated successfully, but these errors were encountered: