From 294682f859045fb9de24270759b1aaa6b5092c27 Mon Sep 17 00:00:00 2001 From: lordmilko Date: Thu, 15 Jun 2023 19:46:49 +1000 Subject: [PATCH] -Implement support for optionally multi-targeting .NET 8 -Fix .NET 8 warnings --- ClrDebug/ClrDebug.csproj | 3 ++- .../DbgEng/Extensions.WinDbgExtensionAPI.cs | 2 ++ .../Exceptions/DbgEngArgumentException.cs | 1 + .../Exceptions/DbgEngInvalidStateException.cs | 1 + .../Exceptions/DbgEngItemNotFoundException.cs | 1 + .../DbgEngNotImplementedException.cs | 1 + .../DbgEngOperationFailedException.cs | 1 + .../Exceptions/DbgEngOutOfMemoryException.cs | 1 + .../DbgEngPartialResultsException.cs | 1 + .../Extensions/Exceptions/DebugException.cs | 1 + .../Extensions/ManualInterfaceMarshaler.cs | 27 ++++++++++++++++--- ClrDebug/Extensions/RuntimeCallableWrapper.cs | 6 +++++ appveyor.yml | 6 ++--- 13 files changed, 45 insertions(+), 7 deletions(-) diff --git a/ClrDebug/ClrDebug.csproj b/ClrDebug/ClrDebug.csproj index a520dbba..084f2ffa 100644 --- a/ClrDebug/ClrDebug.csproj +++ b/ClrDebug/ClrDebug.csproj @@ -3,7 +3,8 @@ - netstandard2.0 + netstandard2.0;net8.0 + netstandard2.0 true bin\$(Configuration)\$(TargetFramework)\ClrDebug.xml 1701;1702;CS1591 diff --git a/ClrDebug/Extensions/DbgEng/Extensions.WinDbgExtensionAPI.cs b/ClrDebug/Extensions/DbgEng/Extensions.WinDbgExtensionAPI.cs index 1a1fc88f..fa63c188 100644 --- a/ClrDebug/Extensions/DbgEng/Extensions.WinDbgExtensionAPI.cs +++ b/ClrDebug/Extensions/DbgEng/Extensions.WinDbgExtensionAPI.cs @@ -328,7 +328,9 @@ public unsafe bool TryGetClrDataInterface(out XCLRDataProcess process) if (api.Ioctl(IG.GET_CLR_DATA_INTERFACE, new IntPtr(buffer), size) == 1) { +#pragma warning disable CA1416 //This call site is reachable on all platforms var iface = Marshal.GetObjectForIUnknown(buffer->Iface); +#pragma warning restore CA1416 //This call site is reachable on all platforms process = new XCLRDataProcess((IXCLRDataProcess)iface); return true; } diff --git a/ClrDebug/Extensions/Exceptions/DbgEngArgumentException.cs b/ClrDebug/Extensions/Exceptions/DbgEngArgumentException.cs index c0ef1e57..bcb82ad4 100644 --- a/ClrDebug/Extensions/Exceptions/DbgEngArgumentException.cs +++ b/ClrDebug/Extensions/Exceptions/DbgEngArgumentException.cs @@ -46,6 +46,7 @@ public DbgEngArgumentException(string message, Exception inner) : base(message, /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. + [Obsolete] protected DbgEngArgumentException(SerializationInfo info, StreamingContext context) : base(info, context) { base.HResult = unchecked((int) HRESULT.E_INVALIDARG); diff --git a/ClrDebug/Extensions/Exceptions/DbgEngInvalidStateException.cs b/ClrDebug/Extensions/Exceptions/DbgEngInvalidStateException.cs index e6019bb9..5c4d8a8e 100644 --- a/ClrDebug/Extensions/Exceptions/DbgEngInvalidStateException.cs +++ b/ClrDebug/Extensions/Exceptions/DbgEngInvalidStateException.cs @@ -46,6 +46,7 @@ public DbgEngInvalidStateException(string message, Exception inner) : base(messa /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. + [Obsolete] protected DbgEngInvalidStateException(SerializationInfo info, StreamingContext context) : base(info, context) { base.HResult = unchecked((int) HRESULT.E_UNEXPECTED); diff --git a/ClrDebug/Extensions/Exceptions/DbgEngItemNotFoundException.cs b/ClrDebug/Extensions/Exceptions/DbgEngItemNotFoundException.cs index b733312c..360bf20b 100644 --- a/ClrDebug/Extensions/Exceptions/DbgEngItemNotFoundException.cs +++ b/ClrDebug/Extensions/Exceptions/DbgEngItemNotFoundException.cs @@ -46,6 +46,7 @@ public DbgEngItemNotFoundException(string message, Exception inner) : base(messa /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. + [Obsolete] protected DbgEngItemNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { base.HResult = unchecked((int) HRESULT.E_NOINTERFACE); diff --git a/ClrDebug/Extensions/Exceptions/DbgEngNotImplementedException.cs b/ClrDebug/Extensions/Exceptions/DbgEngNotImplementedException.cs index ca0d7c45..83efad43 100644 --- a/ClrDebug/Extensions/Exceptions/DbgEngNotImplementedException.cs +++ b/ClrDebug/Extensions/Exceptions/DbgEngNotImplementedException.cs @@ -46,6 +46,7 @@ public DbgEngNotImplementedException(string message, Exception inner) : base(mes /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. + [Obsolete] protected DbgEngNotImplementedException(SerializationInfo info, StreamingContext context) : base(info, context) { base.HResult = unchecked((int) HRESULT.E_NOTIMPL); diff --git a/ClrDebug/Extensions/Exceptions/DbgEngOperationFailedException.cs b/ClrDebug/Extensions/Exceptions/DbgEngOperationFailedException.cs index f771b3d3..31cf39db 100644 --- a/ClrDebug/Extensions/Exceptions/DbgEngOperationFailedException.cs +++ b/ClrDebug/Extensions/Exceptions/DbgEngOperationFailedException.cs @@ -46,6 +46,7 @@ public DbgEngOperationFailedException(string message, Exception inner) : base(me /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. + [Obsolete] protected DbgEngOperationFailedException(SerializationInfo info, StreamingContext context) : base(info, context) { base.HResult = unchecked((int) HRESULT.E_FAIL); diff --git a/ClrDebug/Extensions/Exceptions/DbgEngOutOfMemoryException.cs b/ClrDebug/Extensions/Exceptions/DbgEngOutOfMemoryException.cs index 286d8de6..bc6b56d4 100644 --- a/ClrDebug/Extensions/Exceptions/DbgEngOutOfMemoryException.cs +++ b/ClrDebug/Extensions/Exceptions/DbgEngOutOfMemoryException.cs @@ -46,6 +46,7 @@ public DbgEngOutOfMemoryException(string message, Exception inner) : base(messag /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. + [Obsolete] protected DbgEngOutOfMemoryException(SerializationInfo info, StreamingContext context) : base(info, context) { base.HResult = unchecked((int) HRESULT.E_OUTOFMEMORY); diff --git a/ClrDebug/Extensions/Exceptions/DbgEngPartialResultsException.cs b/ClrDebug/Extensions/Exceptions/DbgEngPartialResultsException.cs index 3a3f63cb..5f22a973 100644 --- a/ClrDebug/Extensions/Exceptions/DbgEngPartialResultsException.cs +++ b/ClrDebug/Extensions/Exceptions/DbgEngPartialResultsException.cs @@ -46,6 +46,7 @@ public DbgEngPartialResultsException(string message, Exception inner) : base(mes /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. + [Obsolete] protected DbgEngPartialResultsException(SerializationInfo info, StreamingContext context) : base(info, context) { base.HResult = (int) HRESULT.S_FALSE; diff --git a/ClrDebug/Extensions/Exceptions/DebugException.cs b/ClrDebug/Extensions/Exceptions/DebugException.cs index 7f9be114..ad5dcf91 100644 --- a/ClrDebug/Extensions/Exceptions/DebugException.cs +++ b/ClrDebug/Extensions/Exceptions/DebugException.cs @@ -26,6 +26,7 @@ public DebugException(HRESULT hr) : base($"Error HRESULT {hr} has been returned /// The object that holds the serialized object data. /// The object that supplies the contextual information about the source or destination. /// is . + [Obsolete] protected DebugException(SerializationInfo info, StreamingContext context) : base(info, context) { } diff --git a/ClrDebug/Extensions/ManualInterfaceMarshaler.cs b/ClrDebug/Extensions/ManualInterfaceMarshaler.cs index 6e234cea..edc8e457 100644 --- a/ClrDebug/Extensions/ManualInterfaceMarshaler.cs +++ b/ClrDebug/Extensions/ManualInterfaceMarshaler.cs @@ -8,14 +8,35 @@ internal class ManualInterfaceMarshaler : ICustomMarshaler { public static ICustomMarshaler GetInstance(string pstrCookie) => new ManualInterfaceMarshaler(); - public void CleanUpManagedData(object ManagedObj) => Marshal.ReleaseComObject(ManagedObj); + public void CleanUpManagedData(object ManagedObj) + { +#if NETSTANDARD + Marshal.ReleaseComObject(ManagedObj); +#else + throw new NotImplementedException("Custom Marshalling for non-Windows is not implemented."); +#endif + } public void CleanUpNativeData(IntPtr pNativeData) => Marshal.Release(pNativeData); public int GetNativeDataSize() => IntPtr.Size; - public IntPtr MarshalManagedToNative(object ManagedObj) => Marshal.GetIUnknownForObject(ManagedObj); + public IntPtr MarshalManagedToNative(object ManagedObj) + { +#if NETSTANDARD + return Marshal.GetIUnknownForObject(ManagedObj); +#else + throw new NotImplementedException("Custom Marshalling for non-Windows is not implemented."); +#endif + } - public object MarshalNativeToManaged(IntPtr pNativeData) => Marshal.GetObjectForIUnknown(pNativeData); + public object MarshalNativeToManaged(IntPtr pNativeData) + { +#if NETSTANDARD + return Marshal.GetObjectForIUnknown(pNativeData); +#else + throw new NotImplementedException("Custom Marshalling for non-Windows is not implemented."); +#endif + } } } diff --git a/ClrDebug/Extensions/RuntimeCallableWrapper.cs b/ClrDebug/Extensions/RuntimeCallableWrapper.cs index c9ffce20..7951c416 100644 --- a/ClrDebug/Extensions/RuntimeCallableWrapper.cs +++ b/ClrDebug/Extensions/RuntimeCallableWrapper.cs @@ -54,8 +54,10 @@ private int? RCWRefCount if (hr != HRESULT.S_OK) return null; +#pragma warning disable CA1416 //This call site is reachable on all platforms var o = Marshal.GetObjectForIUnknown(Raw); return Marshal.ReleaseComObject(o); +#pragma warning restore CA1416 //This call site is reachable on all platforms } } } @@ -108,7 +110,9 @@ private static IntPtr GetIUnknownPointer(object value) if (!value.GetType().IsCOMObject) throw new ArgumentException("Value is not a COM object.", nameof(value)); +#pragma warning disable CA1416 //This call site is reachable on all platforms return Marshal.GetIUnknownForObject(value); +#pragma warning restore CA1416 //This call site is reachable on all platforms } protected void InitDelegate(ref T @delegate, IntPtr vtablePtr) @@ -129,7 +133,9 @@ protected void InitDelegate(ref T @delegate, IntPtr vtablePtr) /// A real RCW of type . public T AsInterface() { +#pragma warning disable CA1416 //This call site is reachable on all platforms var unk = Marshal.GetObjectForIUnknown(Raw); +#pragma warning restore CA1416 //This call site is reachable on all platforms return (T)unk; } diff --git a/appveyor.yml b/appveyor.yml index 268fde17..5ad98db6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,14 +2,14 @@ version: 'Build #{build}' image: Visual Studio 2017 configuration: Release before_build: -- dotnet restore +- dotnet restore /p:MultiBuild=true build_script: -- dotnet build +- dotnet build /p:MultiBuild=true test_script: - vstest.console /logger:Appveyor ClrDebug.Tests\bin\%CONFIGURATION%\net461\ClrDebug.Tests.dll /platform:x86 /InIsolation /TestCaseFilter:TestCategory!=SkipCI - vstest.console /logger:Appveyor ClrDebug.Tests\bin\%CONFIGURATION%\net461\ClrDebug.Tests.dll /platform:x64 /InIsolation /TestCaseFilter:TestCategory!=SkipCI after_test: -- dotnet pack ClrDebug\ClrDebug.csproj +- dotnet pack ClrDebug\ClrDebug.csproj /p:MultiBuild=true - 7z a ClrDebug.zip .\ClrDebug\bin\%CONFIGURATION%\netstandard2.0\* -xr!*.json #on_finish: # - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))