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/5.0] P/Invoke function returning SafeSocketHandle throws MissingMethodException (#45911) #45942

Merged
merged 2 commits into from
Dec 11, 2020

Conversation

eerhardt
Copy link
Member

Description

The ILLinker is trimming the private default constructors of SafeHandle classes if they are not used by the library. Adding an XML descriptor file to preserve the private constructors of these SafeHandles so they can be used in P/Invokes in external code.

Customer Impact

If an app is using SafeSocketHandle as the return of a P/Invoke and upgrades from 3.1 to 5.0, the app is broken with System.MissingMethodException: .ctor. There isn't a workaround other than not using SafeSocketHandle in the P/Invoke signature.

Testing

Added 2 new tests for the SafeHandles identified as problematic to ensure customers can P/Invoke using these classes.

Risk

Low

Fix #45633

…ption (dotnet#45911)

* P/Invoke function returning SafeSocketHandle throws MissingMethodException

The ILLinker is trimming the private default constructors of SafeHandle classes if they are not used by the library. Adding an XML descriptor file to preserve the private constructors of these SafeHandles so they can be used in P/Invokes in external code.

Fix dotnet#45633

Suppress P/Invoke test on Browser
@ghost
Copy link

ghost commented Dec 11, 2020

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

Issue Details

Description

The ILLinker is trimming the private default constructors of SafeHandle classes if they are not used by the library. Adding an XML descriptor file to preserve the private constructors of these SafeHandles so they can be used in P/Invokes in external code.

Customer Impact

If an app is using SafeSocketHandle as the return of a P/Invoke and upgrades from 3.1 to 5.0, the app is broken with System.MissingMethodException: .ctor. There isn't a workaround other than not using SafeSocketHandle in the P/Invoke signature.

Testing

Added 2 new tests for the SafeHandles identified as problematic to ensure customers can P/Invoke using these classes.

Risk

Low

Fix #45633

Author: eerhardt
Assignees: eerhardt
Labels:

area-System.Net.Sockets, regression-from-last-release

Milestone: -

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.

Approved. We should consider this for 5.0.2

@eerhardt
Copy link
Member Author

This is broken in the release/5.0 branch because of some build infrastructure differences between master and release/5.0. (Thank you, tests!)

Working on a fix.

@marek-safar marek-safar added the Servicing-approved Approved for servicing release label Dec 11, 2020
@eerhardt
Copy link
Member Author

The single test failure is #43981.

    System.Threading.Tests.ThreadLocalTests.RunThreadLocalTest8_Values [FAIL]
      System.Threading.Tasks.TaskSchedulerException : An exception was thrown by a TaskScheduler.
      ---- System.ExecutionEngineException : Couldn't create thread. Error 0x0
      Stack Trace:
        /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs(1696,0): at System.Threading.Tasks.Task.ScheduleAndStart(Boolean needsProtection)
        /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs(333,0): at System.Threading.Tasks.Task`1[[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].StartNew(Task parent, Func`1 function, CancellationToken cancellationToken, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
        /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskFactory.cs(629,0): at System.Threading.Tasks.TaskFactory.StartNew[Int32](Func`1 function, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler)
        /_/src/libraries/System.Threading/tests/ThreadLocalTests.cs(253,0): at System.Threading.Tests.ThreadLocalTests.RunThreadLocalTest8_Values()
        /_/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs(384,0): at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
        ----- Inner Stack Trace -----
        /_/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs(265,0): at System.Threading.Thread.Start(Object parameter)
        /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs(50,0): at System.Threading.Tasks.ThreadPoolTaskScheduler.QueueTask(Task task)
        /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskScheduler.cs(237,0): at System.Threading.Tasks.TaskScheduler.InternalQueueTask(Task task)
        /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs(1668,0): at System.Threading.Tasks.Task.ScheduleAndStart(Boolean needsProtection)
  Finished:    System.Threading.Tests
=== TEST EXECUTION SUMMARY ===

@eerhardt eerhardt merged commit 83b4457 into dotnet:release/5.0 Dec 11, 2020
@eerhardt eerhardt deleted the Port45911 branch December 11, 2020 21:23
@ghost ghost locked as resolved and limited conversation to collaborators Jan 10, 2021
@danmoseley danmoseley added this to the 5.0.2 milestone Jan 12, 2021
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.

6 participants