dont use generic version of Marshal.SizeOf

pull/12127/head
Jan Tattermusch 7 years ago
parent 271cb36f56
commit 9210293d9e
  1. 7
      src/csharp/Grpc.Core.Tests/Internal/CompletionQueueEventTest.cs
  2. 5
      src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs
  3. 3
      src/csharp/Grpc.Core/Internal/AuthContextSafeHandle.cs

@ -29,9 +29,12 @@ namespace Grpc.Core.Internal.Tests
public class CompletionQueueEventTest public class CompletionQueueEventTest
{ {
[Test] [Test]
public void CreateAndDestroy() public void CompletionQueueEventSizeIsNativeSize()
{ {
Assert.AreEqual(CompletionQueueEvent.NativeSize, Marshal.SizeOf<CompletionQueueEvent>()); #pragma warning disable 0618
// We need to use the obsolete non-generic version of Marshal.SizeOf because the generic version is not available in net45
Assert.AreEqual(CompletionQueueEvent.NativeSize, Marshal.SizeOf(typeof(CompletionQueueEvent)));
#pragma warning restore 0618
} }
} }
} }

@ -60,7 +60,10 @@ namespace Grpc.Core.Internal.Tests
[Test] [Test]
public void TimespecSizeIsNativeSize() public void TimespecSizeIsNativeSize()
{ {
Assert.AreEqual(Timespec.NativeSize, Marshal.SizeOf<Timespec>()); #pragma warning disable 0618
// We need to use the obsolete non-generic version of Marshal.SizeOf because the generic version is not available in net45
Assert.AreEqual(Timespec.NativeSize, Marshal.SizeOf(typeof(Timespec)));
#pragma warning restore 0618
} }
[Test] [Test]

@ -75,8 +75,7 @@ namespace Grpc.Core.Internal
private AuthProperty PtrToAuthProperty(IntPtr authPropertyPtr) private AuthProperty PtrToAuthProperty(IntPtr authPropertyPtr)
{ {
#pragma warning disable 0618 #pragma warning disable 0618
// We need to use the obsolete non-generic version of Marshal.PtrToStructure, because the generic version is not available // We need to use the obsolete non-generic version of Marshal.PtrToStructure, because the generic version is not available in net45
// in net45 on Windows.
var nativeAuthProperty = (NativeAuthProperty) Marshal.PtrToStructure(authPropertyPtr, typeof(NativeAuthProperty)); var nativeAuthProperty = (NativeAuthProperty) Marshal.PtrToStructure(authPropertyPtr, typeof(NativeAuthProperty));
#pragma warning restore 0618 #pragma warning restore 0618
var name = Marshal.PtrToStringAnsi(nativeAuthProperty.Name); var name = Marshal.PtrToStringAnsi(nativeAuthProperty.Name);

Loading…
Cancel
Save