Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Marshal type #18

Closed
weshaggard opened this issue Sep 13, 2016 · 4 comments
Closed

Marshal type #18

weshaggard opened this issue Sep 13, 2016 · 4 comments
Assignees

Comments

@weshaggard
Copy link
Member

weshaggard commented Sep 13, 2016

The Marshal type currently has lot members which are related to COM and other things which are missing in Xamarin:

public static partial class Marshal
{
//INTEROP public static void CleanupUnusedObjectsInCurrentContext() { }
//INTEROP public static object CreateWrapperOfType(object o, System.Type t) { throw null; }
//INTEROP public static TWrapper CreateWrapperOfType<T, TWrapper>(T o) { throw null; }
//INTEROP public static int FinalReleaseComObject(object o) { throw null; }
//INTEROP public static System.Guid GenerateGuidForType(System.Type type) { throw null; }
//INTEROP public static string GenerateProgIdForType(System.Type type) { throw null; }
//INTEROP public static object GetActiveObject(string progID) { throw null; }
//INTEROP public static System.IntPtr GetComInterfaceForObject(object o, System.Type T) { throw null; }
//INTEROP public static System.IntPtr GetComInterfaceForObject(object o, System.Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode) { throw null; }
//INTEROP public static System.IntPtr GetComInterfaceForObject<T, TInterface>(T o) { throw null; }
//INTEROP public static System.IntPtr GetComInterfaceForObjectInContext(object o, System.Type t) { throw null; }
//INTEROP public static object GetComObjectData(object obj, object key) { throw null; }
//INTEROP public static int GetComSlotForMethodInfo(System.Reflection.MemberInfo m) { throw null; }
//INTEROP public static int GetEndComSlot(System.Type t) { throw null; }
//INTEROP public static int GetExceptionCode() { throw null; }
//INTEROP public static System.IntPtr GetExceptionPointers() { throw null; }
//INTEROP public static System.IntPtr GetHINSTANCE(System.Reflection.Module m) { throw null; }
//INTEROP public static int GetHRForException(System.Exception e) { throw null; }
//INTEROP public static int GetHRForLastWin32Error() { throw null; }
//INTEROP public static System.IntPtr GetIDispatchForObject(object o) { throw null; }
//INTEROP public static System.IntPtr GetIDispatchForObjectInContext(object o) { throw null; }
//INTEROP public static System.IntPtr GetITypeInfoForType(System.Type t) { throw null; }
//INTEROP public static System.IntPtr GetIUnknownForObject(object o) { throw null; }
//INTEROP public static System.IntPtr GetIUnknownForObjectInContext(object o) { throw null; }
//INTEROP [System.ObsoleteAttribute("The GetManagedThunkForUnmanagedMethodPtr method has been deprecated and will be removed in a future release.", false)]
//INTEROP public static System.IntPtr GetManagedThunkForUnmanagedMethodPtr(System.IntPtr pfnMethodToWrap, System.IntPtr pbSignature, int cbSignature) { throw null; }
//INTEROP public static System.Reflection.MemberInfo GetMethodInfoForComSlot(System.Type t, int slot, ref System.Runtime.InteropServices.ComMemberType memberType) { throw null; }
//INTEROP public static void GetNativeVariantForObject(object obj, System.IntPtr pDstNativeVariant) { }
//INTEROP public static void GetNativeVariantForObject<T>(T obj, System.IntPtr pDstNativeVariant) { }
//INTEROP public static object GetObjectForIUnknown(System.IntPtr pUnk) { throw null; }
//INTEROP public static object GetObjectForNativeVariant(System.IntPtr pSrcNativeVariant) { throw null; }
//INTEROP public static T GetObjectForNativeVariant<T>(System.IntPtr pSrcNativeVariant) { throw null; }
//INTEROP public static object[] GetObjectsForNativeVariants(System.IntPtr aSrcNativeVariant, int cVars) { throw null; }
//INTEROP public static T[] GetObjectsForNativeVariants<T>(System.IntPtr aSrcNativeVariant, int cVars) { throw null; }
//INTEROP public static int GetStartComSlot(System.Type t) { throw null; }
//INTEROP [System.ObsoleteAttribute("The GetThreadFromFiberCookie method has been deprecated.  Use the hosting API to perform this operation.", false)]
//INTEROP public static System.Threading.Thread GetThreadFromFiberCookie(int cookie) { throw null; }
//INTEROP public static object GetTypedObjectForIUnknown(System.IntPtr pUnk, System.Type t) { throw null; }
//INTEROP public static System.Type GetTypeForITypeInfo(System.IntPtr piTypeInfo) { throw null; }
//INTEROP public static System.Type GetTypeFromCLSID(System.Guid clsid) { throw null; }
//INTEROP public static string GetTypeInfoName(System.Runtime.InteropServices.ComTypes.ITypeInfo typeInfo) { throw null; }
//INTEROP [System.ObsoleteAttribute("Use System.Runtime.InteropServices.Marshal.GetTypeInfoName(ITypeInfo pTLB) instead. http://go.microsoft.com/fwlink/?linkid=14202&ID=0000011.", false)]
//INTEROP public static string GetTypeInfoName(System.Runtime.InteropServices.UCOMITypeInfo pTI) { throw null; }
//INTEROP public static System.Guid GetTypeLibGuid(System.Runtime.InteropServices.ComTypes.ITypeLib typelib) { throw null; }
//INTEROP [System.ObsoleteAttribute("Use System.Runtime.InteropServices.Marshal.GetTypeLibGuid(ITypeLib pTLB) instead. http://go.microsoft.com/fwlink/?linkid=14202&ID=0000011.", false)]
//INTEROP public static System.Guid GetTypeLibGuid(System.Runtime.InteropServices.UCOMITypeLib pTLB) { throw null; }
//INTEROP public static System.Guid GetTypeLibGuidForAssembly(System.Reflection.Assembly asm) { throw null; }
//INTEROP public static int GetTypeLibLcid(System.Runtime.InteropServices.ComTypes.ITypeLib typelib) { throw null; }
//INTEROP [System.ObsoleteAttribute("Use System.Runtime.InteropServices.Marshal.GetTypeLibLcid(ITypeLib pTLB) instead. http://go.microsoft.com/fwlink/?linkid=14202&ID=0000011.", false)]
//INTEROP public static int GetTypeLibLcid(System.Runtime.InteropServices.UCOMITypeLib pTLB) { throw null; }
//INTEROP public static string GetTypeLibName(System.Runtime.InteropServices.ComTypes.ITypeLib typelib) { throw null; }
//INTEROP [System.ObsoleteAttribute("Use System.Runtime.InteropServices.Marshal.GetTypeLibName(ITypeLib pTLB) instead. http://go.microsoft.com/fwlink/?linkid=14202&ID=0000011.", false)]
//INTEROP public static string GetTypeLibName(System.Runtime.InteropServices.UCOMITypeLib pTLB) { throw null; }
//INTEROP public static void GetTypeLibVersionForAssembly(System.Reflection.Assembly inputAssembly, out int majorVersion, out int minorVersion) { majorVersion = default(int); minorVersion = default(int); }
//INTEROP public static object GetUniqueObjectForIUnknown(System.IntPtr unknown) { throw null; }
//INTEROP [System.ObsoleteAttribute("The GetUnmanagedThunkForManagedMethodPtr method has been deprecated and will be removed in a future release.", false)]
//INTEROP public static System.IntPtr GetUnmanagedThunkForManagedMethodPtr(System.IntPtr pfnMethodToWrap, System.IntPtr pbSignature, int cbSignature) { throw null; }
//INTEROP public static bool IsComObject(object o) { throw null; }
//INTEROP public static bool IsTypeVisibleFromCom(System.Type t) { throw null; }
//INTEROP public static int NumParamBytes(System.Reflection.MethodInfo m) { throw null; }
//INTEROP public static int ReleaseComObject(object o) { throw null; }
//INTEROP [System.ObsoleteAttribute("This API did not perform any operation and will be removed in future versions of the CLR.", false)]
//INTEROP public static void ReleaseThreadCache() { }
//INTEROP public static bool SetComObjectData(object obj, object key, object data) { throw null; }
}

We need to decide whether or not we add these to the netstandard or if we make people that want to use them cross-compile to .NET Framework?

cc @yizhang82 @tijoytom

@weshaggard weshaggard self-assigned this Sep 13, 2016
weshaggard added a commit that referenced this issue Sep 13, 2016
1. Remove TypeLib APIs as they aren't needed or compatible
(see #2).
2. Remove System.Runtime.Interop.ComTypes namespace as it is only
COM interfaces and structs which aren't applicable to all OS's and
we can easily make that a compat library as needed.
3. Removed all obsolete structs that were also in ComTypes.
4. Marshal type was sub-setted to match what Xamarin exposeds
(see #18).
weshaggard added a commit that referenced this issue Sep 14, 2016
1. Remove TypeLib APIs as they aren't needed or compatible
(see #2).
2. Remove System.Runtime.Interop.ComTypes namespace as it is only
COM interfaces and structs which aren't applicable to all OS's and
we can easily make that a compat library as needed.
3. Removed all obsolete structs that were also in ComTypes.
4. Marshal type was sub-setted to match what Xamarin exposeds
(see #18).
@weshaggard
Copy link
Member Author

Another set of interesting APIs on Marshal to consider are the SecureString marshalling APIs.

        public static System.IntPtr SecureStringToBSTR(System.Security.SecureString s) { throw null; }
        public static System.IntPtr SecureStringToCoTaskMemAnsi(System.Security.SecureString s) { throw null; }
        public static System.IntPtr SecureStringToCoTaskMemUnicode(System.Security.SecureString s) { throw null; }
        public static System.IntPtr SecureStringToGlobalAllocAnsi(System.Security.SecureString s) { throw null; }
        public static System.IntPtr SecureStringToGlobalAllocUnicode(System.Security.SecureString s) { throw null; }

For .NET Core we have SecureString implemeneted as a standalone library and have introduced SecureStringMarshal (https://github.com/dotnet/corefx/blob/master/src/System.Security.SecureString/ref/System.Security.SecureString.cs#L26) to break this dependency. To help support this factoriziation I'm thinking we will remove the SecureString APIs from Marshal.

weshaggard added a commit that referenced this issue Sep 14, 2016
See details at #18.

For people that need these they should use SecureStringMarshal type
instead. Currently that isn't part of netstandard but should work
on any platform.
@terrajobst
Copy link
Member

terrajobst commented Sep 16, 2016

We should look at usage from NuGet and APIPort to see whether any APIs are affected that have high usage. Our current goal is parity with Xamarin; so we don't need them. However we also want to make porting from .NET FX to .NET Core easier. So I'd say: let's make sure we don't cut highly used ones. Those, we should ask Xamarin to add and throw, if they can't implement it.

We should add the methods on Marshal which means SecureString has to go into the corlib assembly.

@tijoytom-zz
Copy link

@terrajobst @weshaggard @yizhang82

Here is Marshal.SecureString usage stat
SecureString: APIport :4.4% Nuget : 1.9%

weshaggard added a commit that referenced this issue Sep 20, 2016
This reverts commit 63ce191.

We decided to keep SecureString methods on Marshal see discussion in
#18
@weshaggard
Copy link
Member Author

Reverted the SecureString Marshal removals with 8fc5b7f.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants