Skip to content
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

Closed
kblood opened this issue Nov 13, 2020 · 6 comments
Closed

SQLConnection GetSchema with PublishTrimmed not working #822

kblood opened this issue Nov 13, 2020 · 6 comments

Comments

@kblood
Copy link

kblood commented Nov 13, 2020

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.

@carlossanlop carlossanlop transferred this issue from dotnet/core Nov 25, 2020
@ghost
Copy link

ghost commented Nov 25, 2020

Tagging subscribers to this area: @cheenamalhotra, @David-Engel
See info in area-owners.md if you want to be subscribed.

Issue Details

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.

Author: kblood
Assignees: -
Labels:

area-System.Data.SqlClient, untriaged

Milestone: -

@cheenamalhotra
Copy link
Member

Hi @kblood

Which Microsoft.Data.SqlClient driver version you're referencing in your application?
Could you try by directly referencing latest v2.1.0 and let us know?

@cheenamalhotra cheenamalhotra transferred this issue from dotnet/runtime Nov 26, 2020
@Wraith2
Copy link
Contributor

Wraith2 commented Nov 26, 2020

I don't believe the library is tested at all with trimming and it is probably advisable to disable it from the trimable list.

@David-Engel
Copy link
Contributor

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.

@David-Engel David-Engel added this to the Future milestone Dec 7, 2020
@Wraith2
Copy link
Contributor

Wraith2 commented Dec 7, 2020

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.

@mdaigle
Copy link
Contributor

mdaigle commented Mar 20, 2025

Closing in favor of #1947

@mdaigle mdaigle closed this as completed Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants