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

[release/8.0-staging] [LibraryImportGenerator] Use basic forwarder in down-level support if any parameters can't be marshalled #104501

Conversation

elinor-fung
Copy link
Member

@elinor-fung elinor-fung commented Jul 6, 2024

Backport of #104416 to release/8.0-staging

cc @dotnet/ncl for WinHttpHandler

Customer Impact

  • Customer reported
  • Found internally

Libraries built out of dotnet/runtime using LibraryImport targeting .NET 6 can end up with some parameters that are marshalled by generated source and some that are simply forwarded to a DllImport, such that the generated DllImport signature is still not blittable. This can result in some parameters being incorrectly marshalled, as the generated DllImport does not have all the metadata/attributes needed for those parameters. In the WinHttpHandler package, this hit an issue where StringBuilder was no longer marshalled as expected and using the function fails at runtime.

This fix makes it so that if any parameter cannot be marshalled by the source generator, it simply forwards everything to a DllImport. It eliminates there is no scenario where a stub is generated that marshals some parameters and forwards the rest (without erroring).

Regression

  • Yes
  • No

This is a regression when using the LibraryImport source generator to target .NET 6 (down-level support that only exists for the dotnet/runtime repo) building out of the .NET 8 branch.

Testing

Manual verification. Automated tests added.

Risk

Low. This is down-level support that exists for dotnet/runtime only. While it could affect anything using the LibraryImport targeting .NET 6, the switch to just forwarding to DllImport (instead of generating something that only marshals some parameters) is low risk.

Other

  • Updated ServicingVersion for System.Net.Http.WinHttpHandlers

Copy link
Contributor

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

@elinor-fung
Copy link
Member Author

/azp run runtime-libraries-coreclr outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

@agocke
Copy link
Member

agocke commented Jul 9, 2024

Is there any additional/different testing that we want to do in the 8.0 branch, since my recollection is that is where the downlevel targeting is supported? Or are the current tests sufficient?

Copy link
Contributor

@rokonec rokonec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have discussed it with NCL team and changes in WinHttpHandler.csproj are correct

Copy link
Member

@jeffschwMSFT jeffschwMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. we will take for consideration in 8.0.x

@elinor-fung
Copy link
Member Author

Is there any additional/different testing that we want to do in the 8.0 branch, since my recollection is that is where the downlevel targeting is supported? Or are the current tests sufficient?

For 8.0, the only additional testing I did was inspect the IL for the library built for 6.0 to validate it is simply a DllImport now for p/invokes where we could only marshal some parameters and that p/invokes where we could marshal all parameters were not affected (that is, we still generate the stub to handle the marshalling). For automated tests, I think what is added in this change is sufficient (the down-level support from the perspective of LibraryImport generator itself is the same in main - it is just that the repo doesn't build libraries that use it for 6.0 anymore)

@leecow leecow added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Jul 9, 2024
@leecow leecow modified the milestones: 8.0.x, 8.0.8 Jul 9, 2024
@carlossanlop
Copy link
Member

Friendly reminder that Monday July 15th is Code Complete day, that's the deadline to get this included in the August Release.

@elinor-fung elinor-fung merged commit 09784cd into dotnet:release/8.0-staging Jul 12, 2024
121 of 136 checks passed
@elinor-fung elinor-fung deleted the library-import-partial-forward-rel branch July 12, 2024 21:57
@github-actions github-actions bot locked and limited conversation to collaborators Aug 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants