Make GetHRForException to return e.HResult on non-Windows platforms (dotnet/coreclr...
authorJan Kotas <jkotas@microsoft.com>
Fri, 26 Aug 2016 01:14:28 +0000 (18:14 -0700)
committerGitHub <noreply@github.com>
Fri, 26 Aug 2016 01:14:28 +0000 (18:14 -0700)
Fixes https://github.com/dotnet/corefx/issues/11144

Commit migrated from https://github.com/dotnet/coreclr/commit/9caa82a7b334836b474a89188f2ffb0def582785

src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs
src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/NonPortable.cs
src/coreclr/src/vm/ecalllist.h

index 5e6e782..86e8830 100644 (file)
@@ -1148,24 +1148,6 @@ namespace System.Runtime.InteropServices
 
 
         //====================================================================
-        // Converts the CLR exception to an HRESULT. This function also sets
-        // up an IErrorInfo for the exception.
-        //====================================================================
-        [System.Security.SecurityCritical]  // auto-generated_required
-        [MethodImplAttribute(MethodImplOptions.InternalCall)]
-        public static extern int GetHRForException(Exception e);
-
-        //====================================================================
-        // Converts the CLR exception to an HRESULT. This function also sets
-        // up an IErrorInfo for the exception.
-        // This function is only used in WinRT and converts ObjectDisposedException
-        // to RO_E_CLOSED
-        //====================================================================
-        [System.Security.SecurityCritical]  // auto-generated_required
-        [MethodImplAttribute(MethodImplOptions.InternalCall)]
-        internal static extern int GetHRForException_WinRT(Exception e);
-
-        //====================================================================
         // This method is intended for compiler code generators rather
         // than applications. 
         //====================================================================
@@ -1336,6 +1318,24 @@ namespace System.Runtime.InteropServices
 
 #if FEATURE_COMINTEROP
 
+        //====================================================================
+        // Converts the CLR exception to an HRESULT. This function also sets
+        // up an IErrorInfo for the exception.
+        //====================================================================
+        [System.Security.SecurityCritical]  // auto-generated_required
+        [MethodImplAttribute(MethodImplOptions.InternalCall)]
+        public static extern int GetHRForException(Exception e);
+
+        //====================================================================
+        // Converts the CLR exception to an HRESULT. This function also sets
+        // up an IErrorInfo for the exception.
+        // This function is only used in WinRT and converts ObjectDisposedException
+        // to RO_E_CLOSED
+        //====================================================================
+        [System.Security.SecurityCritical]  // auto-generated_required
+        [MethodImplAttribute(MethodImplOptions.InternalCall)]
+        internal static extern int GetHRForException_WinRT(Exception e);
+
                internal static readonly Guid ManagedNameGuid = new Guid("{0F21F359-AB84-41E8-9A78-36D110E6D2F9}"); 
        
         //====================================================================
index 130a48a..408f56c 100644 (file)
@@ -5,9 +5,15 @@
 // Dummy implementations of non-portable interop methods that just throw PlatformNotSupportedException
 
 namespace System.Runtime.InteropServices
-{    
+{
     public  static partial class Marshal
     {
+        [System.Security.SecurityCritical]
+        public static int GetHRForException(Exception e)
+        {
+            return (e != null) ? e.HResult : 0;
+        }
+
         [System.Security.SecurityCriticalAttribute]
         public static int AddRef(System.IntPtr pUnk)
         {
index 5992b29..c693acd 100644 (file)
@@ -1600,11 +1600,11 @@ FCFuncStart(gInteropMarshalFuncs)
     FCFuncElement("StructureToPtr", MarshalNative::StructureToPtr)
     FCFuncElement("ThrowExceptionForHRInternal", MarshalNative::ThrowExceptionForHR)
     FCFuncElement("GetExceptionForHRInternal", MarshalNative::GetExceptionForHR)
-    FCFuncElement("GetHRForException", MarshalNative::GetHRForException)
-    FCFuncElement("GetHRForException_WinRT", MarshalNative::GetHRForException_WinRT)
     FCFuncElement("GetDelegateForFunctionPointerInternal", MarshalNative::GetDelegateForFunctionPointerInternal)
     FCFuncElement("GetFunctionPointerForDelegateInternal", MarshalNative::GetFunctionPointerForDelegateInternal)
 #ifdef FEATURE_COMINTEROP
+    FCFuncElement("GetHRForException", MarshalNative::GetHRForException)
+    FCFuncElement("GetHRForException_WinRT", MarshalNative::GetHRForException_WinRT)
     FCFuncElement("GetRawIUnknownForComObjectNoAddRef", MarshalNative::GetRawIUnknownForComObjectNoAddRef)
     FCFuncElement("IsComObject", MarshalNative::IsComObject)
     FCFuncElement("GetObjectForIUnknown", MarshalNative::GetObjectForIUnknown)