Skip to content

Rewrite Type.GetTypeFromProgID in C# #42546

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
Sep 23, 2020
Merged

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Sep 21, 2020

  • Move CoreRT managed implementation of Type.GetTypeFromProgID to CoreCLR
  • Delete dead code and unnecessary levels of indirection
  • Add tests for Type.GetTypeFromProgID and Type.GetTypeFromCLSID

- Move CoreRT managed implementation of Type.GetTypeFromProgID to CoreCLR
- Delete dead code and unnecessary levels of indirection
- Add tests for Type.GetTypeFromProgID and Type.GetTypeFromCLSID
#else // FEATURE_COMINTEROP_UNMANAGED_ACTIVATION
internal static Type GetTypeFromProgIDImpl(string progID, string? server, bool throwOnError)
{
throw new NotImplementedException("CoreCLR_REMOVED -- Unmanaged activation removed");
Copy link
Member Author

Choose a reason for hiding this comment

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

Calling Type.GetTypeFromProgID on Unix gives this today:

Unhandled exception. System.NotImplementedException: CoreCLR_REMOVED -- Unmanaged activation removed
   at System.RuntimeType.GetTypeFromProgIDImpl(String progID, String server, Boolean throwOnError)
   at System.Type.GetTypeFromProgID(String progID)

This change is changing it to nice COM interop not support PlatformNotSupportedException.

Assert.Same(type, Marshal.GetTypeFromCLSID(guid));
Assert.Same(type, Marshal.GetTypeFromCLSID(TestCLSID));

Assert.Same(type, Type.GetTypeFromCLSID(TestCLSID));
Copy link
Member Author

Choose a reason for hiding this comment

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

We did not have any test coverage for Type.GetTypeFromCLSID and Type.GetTypeFromProgID

if (throwOnError)
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);

return null;
Copy link
Member Author

Choose a reason for hiding this comment

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

We will return null instead of throwing when throwOnError is false. It matches what we do in other similar situations.

@@ -1318,171 +1318,6 @@ FCIMPL2(Object*, MarshalNative::GetObjectsForNativeVariants, VARIANT* aSrcNative
}
FCIMPLEND

FCIMPL2(void, MarshalNative::DoGetTypeLibGuid, GUID * result, Object* refTlbUNSAFE)
Copy link
Member Author

Choose a reason for hiding this comment

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

Dead code that I have run into along the way

//--------------------------------------------------------------------------
// GetComClassFromCLSID used by reflection class to setup a Class based on CLSID
void GetComClassFromCLSID(REFCLSID clsid, STRINGREF srefServer, OBJECTREF* pRef);
void GetComClassFromCLSID(REFCLSID clsid, __in_opt PCWSTR wszServer, OBJECTREF* pRef);
Copy link
Member

Choose a reason for hiding this comment

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

__in_opt is SAL. The SAL2 version is _In_opt_z_ for this one.

@jkotas jkotas merged commit 0a69f02 into dotnet:master Sep 23, 2020
@jkotas jkotas deleted the GetTypeFromProgId branch September 23, 2020 01:08
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
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.

3 participants