Skip to content

Add | Add net8 compatibility #1934

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

Merged
merged 2 commits into from
Jun 6, 2023

Conversation

Wraith2
Copy link
Contributor

@Wraith2 Wraith2 commented Feb 26, 2023

closes #1930

In netcore builds SqlGuidCaster and the type workaround that used it are not required. The problem they solved has already been change to use the ReadOnlySpan ctor. The SqlGuid workarounds in netcore are removed. Netfx builds use a more recent approach to the original problem and do not need to change.

I have also added ifdeffed use of the new api's introduced to the ryntime in dotnet/runtime#72724 so if/when a net8 build is created the new methods will be used and the workarounds will be ifdeffed out entirely.

Testing on net was done manually with a small repro app that used reflection to force SqlGuidCaster to be compiled. Before these change the reported TypeLoadException was encountered, after them it is not.

/cc @Alerinos @MichalPetryka

@JRahnama
Copy link
Contributor

JRahnama commented May 3, 2023

I will do some changes to this PR, such as the csproj file to include SqlTypeWorkarounds to be included if it is net6 only and changing the Net 8 to net 7 for now.

@JRahnama JRahnama added this to the 5.2.0-preview2 milestone May 3, 2023
@Wraith2
Copy link
Contributor Author

Wraith2 commented May 3, 2023

You can't change the net8 to 7 because this is adding support for new apis that aren't in 7. For the rest, go ahead.

@codecov
Copy link

codecov bot commented May 8, 2023

Codecov Report

Patch coverage: 45.45% and project coverage change: -0.16 ⚠️

Comparison is base (a4f18ca) 70.82% compared to head (37fb9a0) 70.67%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1934      +/-   ##
==========================================
- Coverage   70.82%   70.67%   -0.16%     
==========================================
  Files         292      305      +13     
  Lines       61777    61794      +17     
==========================================
- Hits        43752    43670      -82     
- Misses      18025    18124      +99     
Flag Coverage Δ
addons 92.88% <ø> (+0.49%) ⬆️
netcore 73.43% <45.45%> (-1.01%) ⬇️
netfx 69.27% <ø> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rosoft/Data/SqlTypes/SqlTypeWorkarounds.netcore.cs 94.73% <ø> (+12.91%) ⬆️
...c/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs 64.16% <ø> (ø)
...qlClient/src/Microsoft/Data/SqlClient/SqlBuffer.cs 80.45% <ø> (ø)
.../netcore/src/Microsoft/Data/SqlClient/TdsParser.cs 68.58% <45.45%> (-4.81%) ⬇️

... and 93 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@DavoudEshtehari DavoudEshtehari requested a review from JRahnama May 11, 2023 22:52
@David-Engel
Copy link
Contributor

You can't change the net8 to 7 because this is adding support for new apis that aren't in 7. For the rest, go ahead.

The new APIs made it into .net7 last year. I think we are good to go on this PR.
https://github.com/dotnet/runtime/commits/v7.0.0/src/libraries/System.Data.Common/src/System/Data/SQLTypes

@DavoudEshtehari DavoudEshtehari added the Enhancement 💡 Issues that are feature requests for the drivers we maintain. label Jun 6, 2023
@DavoudEshtehari DavoudEshtehari merged commit 288a70c into dotnet:main Jun 6, 2023
@JRahnama JRahnama changed the title Add net8 compatibility Add | Add net8 compatibility Jun 7, 2023
kant2002 pushed a commit to kant2002/SqlClient that referenced this pull request Jun 29, 2023
wilbit added a commit to Intrigma/SqlClient that referenced this pull request Jan 19, 2024
wilbit added a commit to Intrigma/SqlClient that referenced this pull request Jan 19, 2024
wilbit added a commit to Intrigma/SqlClient that referenced this pull request Jan 19, 2024
@FS-FrankLakmann
Copy link

Hello, we just stumbled over #1930
One question concerning your release strategy: Why was this fix not added to the LTS 5.1.x branch? Now we have a situation where the only branch with half-decent (not enough but better than the other branches) support lifetime is not compatible to the current LTS version of the dotnet runtime itself.
Please remember: not everybody does inhouse development and can push releases every month. There are ISVs out there who release once a year and those have to run for 2 years with only minor bugfixes. We need stable and long-term support for the runtime and essential base libs like SqlClient.
Your LTS schedule should be aligned with the release of the framework LTS-versions and keep compatibility with that version.

@Wraith2
Copy link
Contributor Author

Wraith2 commented May 12, 2025

Why is your code, or your vendor code, touching internal types in an assembly it does not own?

@FS-FrankLakmann
Copy link

FS-FrankLakmann commented May 12, 2025

I'm not sure what you mean by touching. We just used SqlClient with NHibernate in dotnet 8 for some months in an ordinary line-of-business-application. Everthinig was fine with version 5.1.6. Then we made some changes to entity definitions and data mappings and got the same runtime exception as in #1930. I have no idea what triggered the change but we were not doing anything fancy in the internals.
Edit: The repo example provided in #1930 looks super harmless.

@Wraith2
Copy link
Contributor Author

Wraith2 commented May 12, 2025

The only way to touch SqlGuidCaster is through reflection accessing internal types inside SqlClient. That's why it wasn't found in testing, it wasn't used and the public surface area wasn't changed. If your dependency, NHibernate was using private reflection then it should not have been.

@Wraith2 Wraith2 deleted the fix-typeworkarounds branch May 12, 2025 12:37
@ErikEJ
Copy link
Contributor

ErikEJ commented May 12, 2025

@Wraith2 Looks like this repros:

assembly.GetTypes()

@FS-FrankLakmann
Copy link

Small Correction: There was no code change in the data access layer (Entiies, ,mappings). The new code that triggers the exception is a readonly reflection call
AppDomain.CurrentDomain.GetAssemblies().AsEnumerable() .SelectMany(x => x.GetTypes()) .Where(x => typeof(IAnyHandler).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract) .... that iterates all types of all loaded assemblies. Almost identical to the code by Alerinos in the initial issue post of #1930.

If this looking into the types via reflection without changing anything is what you mean with "touching" then yes - we are touching the types. It's readonly - we are not changing anything!
And the main point of my criticism is the sqlclient roadmap. Why am I forced off the LTS branch of sqlclient to stay compatible with the LTS version of the framework?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement 💡 Issues that are feature requests for the drivers we maintain.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could not load type 'SqlGuidCaster' from assembly Microsoft.Data.SqlClient
7 participants