Remove inconsistent UnmanagedCallersOnly delegate construction check#122906
Remove inconsistent UnmanagedCallersOnly delegate construction check#122906
Conversation
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
|
/azp run runtime-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Tagging subscribers to this area: @dotnet/interop-contrib |
There was a problem hiding this comment.
Pull request overview
This PR removes an inconsistent eager validation check that threw NotSupportedException when creating a delegate to a method marked with [UnmanagedCallersOnly]. This aligns delegate construction behavior with the runtime's lazy validation policy, where validation occurs at invocation time (during JIT compilation) rather than at delegate creation time. The failfast protection remains in place through ThrowIfInvalidUnmanagedCallersOnlyUsage called during JIT compilation.
Key changes:
- Removed eager
HasUnmanagedCallersOnlyAttribute()check from delegate constructor path in CoreCLR - Removed test that verified the now-removed exception behavior
- Cleaned up unused IL test methods and resource strings
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/vm/comdelegate.cpp | Removed the eager UnmanagedCallersOnly attribute check from GetDelegateCtor that threw NotSupportedException during delegate construction |
| src/tests/Interop/UnmanagedCallersOnly/UnmanagedCallersOnlyTest.cs | Removed NegativeTest_ViaDelegate test that verified the removed NotSupportedException behavior |
| src/tests/Interop/UnmanagedCallersOnly/InvalidCallbacks.il | Removed unused IL methods ManagedDoubleCallback, DoubleImpl, and GetDoubleDelegate that were only used by the removed test |
| src/libraries/System.Private.CoreLib/src/Resources/Strings.resx | Removed unused resource string NotSupported_UnmanagedCallersOnlyTarget that was displayed in the removed exception |
|
/azp run runtime-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Fixed by #122914 |
|
/azp run runtime-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run runtime-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/ba-g known issue #122345, build analysis is unable to match it for some reason |
Description
Removes the eager check in
COMDelegate::GetDelegateCtorthat throwsNotSupportedExceptionwhen attempting to create a delegate to a method with[UnmanagedCallersOnly]. This check is inconsistent with the runtime's policy of lazy validation for UnmanagedCallersOnly methods, which failfast only when actually invoked (e.g., via reflection or calli).Changes:
HasUnmanagedCallersOnlyAttribute()check and exception throw fromcomdelegate.cpp:2796-2801NegativeTest_ViaDelegatetest that verified this exception behaviorGetDoubleDelegateandManagedDoubleCallbackfrom test infrastructureNotSupported_UnmanagedCallersOnlyTargetfromStrings.resxBehavior change:
Customer Impact
Minimal. The previous exception could be worked around, and invoking an UnmanagedCallersOnly method via delegate already triggers failfast at call time. This aligns the fast delegate construction path with the existing slow path behavior.
Regression
No. Removes a safety check introduced earlier but makes behavior consistent across all delegate construction paths.
Testing
CoreCLR and libraries builds verified. Remaining UnmanagedCallersOnly tests ensure failfast behavior on invocation still works correctly.
Risk
Low. Change removes defensive check but failfast protection remains at invocation time, consistent with other code paths.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.