Skip to content

Conversation

@jkoritzinsky
Copy link
Member

All of the delegates used very simple marshalling and they were all used in one or two places immediately after a GetProcAddress call for them, so it seemed like it was worthwhile to go all the way to function pointers instead of just manually pinning the parameters and still allocating delegates.

Fixes #65259

@danmoseley is there a particular CI pipeline I can trigger to validate that the failing tests are passing now?

cc: @dotnet/interop-contrib

…unction pointers.

All of the delegates used very simple marshalling and they were all used in one or two places immediately after a GetProcAddress call for them, so it seemed like it was worthwhile to go all the way to function pointers instead of just manually pinning the parameters and still allocating delegates.

Fixes dotnet#65259
@ghost
Copy link

ghost commented Feb 14, 2022

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

Issue Details

All of the delegates used very simple marshalling and they were all used in one or two places immediately after a GetProcAddress call for them, so it seemed like it was worthwhile to go all the way to function pointers instead of just manually pinning the parameters and still allocating delegates.

Fixes #65259

@danmoseley is there a particular CI pipeline I can trigger to validate that the failing tests are passing now?

cc: @dotnet/interop-contrib

Author: jkoritzinsky
Assignees: -
Labels:

area-System.DirectoryServices

Milestone: -

// call DsReplicaSyncAllW
IntPtr functionPtr = global::Interop.Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsListDomainsInSiteW");
if (functionPtr == (IntPtr)0)
var dsListDomainsInSiteW = (delegate* unmanaged<IntPtr, char*, IntPtr*, int>)global::Interop.Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsListDomainsInSiteW");
Copy link
Member

Choose a reason for hiding this comment

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

Is it desirable that this is IntPtr* rather than DS_NAME_RESULT*?

What about int rather than uint (since its a DWORD)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to match the existing delegate signatures to ensure I wouldn't have to add a ton of casts.

// call DsReplicaSyncAllW
IntPtr functionPtr = global::Interop.Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsListDomainsInSiteW");
if (functionPtr == (IntPtr)0)
var dsListDomainsInSiteW = (delegate* unmanaged<IntPtr, char*, IntPtr*, int>)global::Interop.Kernel32.GetProcAddress(DirectoryContext.ADHandle, "DsListDomainsInSiteW");
Copy link
Member

Choose a reason for hiding this comment

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

This library targets netstandard2.0. The default unmanaged calling convention is not supported for netstandard2.0. I think these needs to be explicit StdCall to make it work for netstandard2.0.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like the netstandard2.0 implementation is a PlatformNotSupported-stubbed out implementation, so it doesn't compile this code.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like the netstandard2.0 implementation is a PlatformNotSupported-stubbed out implementation, so it doesn't compile this code.

That is good. I had thought that targeting netstandard2.0 without stating the calling convention would result in a compiler error. Right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. The feature is conditionally available based on a RuntimeFeature field/property.

@jkoritzinsky
Copy link
Member Author

Both failing legs are issues that are occurring outside of this PR as well.

@jkoritzinsky jkoritzinsky merged commit 862b87a into dotnet:main Feb 14, 2022
@jkoritzinsky jkoritzinsky deleted the ds-tests-delegates branch February 14, 2022 21:21
@ghost ghost locked as resolved and limited conversation to collaborators Mar 17, 2022
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.

Disabling runtime marshaling broke DomainControllerTests.FindAll_NoSuchName_ReturnsEmpty()

4 participants