Skip to content

Commit

Permalink
-Implement support for optionally multi-targeting .NET 8
Browse files Browse the repository at this point in the history
-Fix .NET 8 warnings
  • Loading branch information
lordmilko committed Jun 15, 2023
1 parent 6c694eb commit 294682f
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 7 deletions.
3 changes: 2 additions & 1 deletion ClrDebug/ClrDebug.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<Import Project="..\NuGet.props" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks Condition="'$(MultiBuild)' == 'true'">netstandard2.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition="'$(MultiBuild)' == ''">netstandard2.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\ClrDebug.xml</DocumentationFile>
<NoWarn>1701;1702;CS1591</NoWarn>
Expand Down
2 changes: 2 additions & 0 deletions ClrDebug/Extensions/DbgEng/Extensions.WinDbgExtensionAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions ClrDebug/Extensions/Exceptions/DbgEngArgumentException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public DbgEngArgumentException(string message, Exception inner) : base(message,
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
[Obsolete]
protected DbgEngArgumentException(SerializationInfo info, StreamingContext context) : base(info, context)
{
base.HResult = unchecked((int) HRESULT.E_INVALIDARG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public DbgEngInvalidStateException(string message, Exception inner) : base(messa
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
[Obsolete]
protected DbgEngInvalidStateException(SerializationInfo info, StreamingContext context) : base(info, context)
{
base.HResult = unchecked((int) HRESULT.E_UNEXPECTED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public DbgEngItemNotFoundException(string message, Exception inner) : base(messa
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
[Obsolete]
protected DbgEngItemNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
{
base.HResult = unchecked((int) HRESULT.E_NOINTERFACE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public DbgEngNotImplementedException(string message, Exception inner) : base(mes
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
[Obsolete]
protected DbgEngNotImplementedException(SerializationInfo info, StreamingContext context) : base(info, context)
{
base.HResult = unchecked((int) HRESULT.E_NOTIMPL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public DbgEngOperationFailedException(string message, Exception inner) : base(me
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
[Obsolete]
protected DbgEngOperationFailedException(SerializationInfo info, StreamingContext context) : base(info, context)
{
base.HResult = unchecked((int) HRESULT.E_FAIL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public DbgEngOutOfMemoryException(string message, Exception inner) : base(messag
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
[Obsolete]
protected DbgEngOutOfMemoryException(SerializationInfo info, StreamingContext context) : base(info, context)
{
base.HResult = unchecked((int) HRESULT.E_OUTOFMEMORY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public DbgEngPartialResultsException(string message, Exception inner) : base(mes
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
[Obsolete]
protected DbgEngPartialResultsException(SerializationInfo info, StreamingContext context) : base(info, context)
{
base.HResult = (int) HRESULT.S_FALSE;
Expand Down
1 change: 1 addition & 0 deletions ClrDebug/Extensions/Exceptions/DebugException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public DebugException(HRESULT hr) : base($"Error HRESULT {hr} has been returned
/// <param name="info">The <see cref="SerializationInfo" /> object that holds the serialized object data.</param>
/// <param name="context">The <see cref="StreamingContext" /> object that supplies the contextual information about the source or destination.</param>
/// <exception cref="System.ArgumentNullException"><paramref name="info" /> is <see langword="null" />.</exception>
[Obsolete]
protected DebugException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
Expand Down
27 changes: 24 additions & 3 deletions ClrDebug/Extensions/ManualInterfaceMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
6 changes: 6 additions & 0 deletions ClrDebug/Extensions/RuntimeCallableWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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<T>(ref T @delegate, IntPtr vtablePtr)
Expand All @@ -129,7 +133,9 @@ protected void InitDelegate<T>(ref T @delegate, IntPtr vtablePtr)
/// <returns>A real RCW of type <typeparamref name="T"/>.</returns>
public T AsInterface<T>()
{
#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;
}
Expand Down
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit 294682f

Please sign in to comment.