Different behavior between desktop and .NET Core for API - Marshal.WriteByte(object ptr, int ofs, byte val)
There is an “improvement“ which cause this issue(different behavior). See line
https://github.com/dotnet/coreclr/blob/master/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs#L779
"NETFX x86 Release Build" throws AccessViolationException while other throws ArgumentNullException
Affected test code example:
AssertExtensions.Throws<ArgumentNullException>("ptr", () => { Marshal.WriteByte(null, 0, 0); });
@jiangzeng This should be addressed now. Please try with the latest coreclr - see referenced PR. Thanks!
Eh, all PR unit tests now consistently fail because of this.
It's not exactly because of this. This PR added tests, which passed CI. Concurrently a PR updated corefx to use a new coreclr that changed a behavior (by design), and it passed CI. I merged both, but they were incompatible, so together one of the new tests fails. I'll fix it later today when I'm back at my machine.
@stephentoub Thanks!
@AaronRobinsonMSFT I tested with latest CoreFx code, after I remove the ActiveBug tag of the test and tested locally, it still failed in NetFx (ArchGroup=x86;TargetGroup=netfx;ConfigurationGroup=Release).
But It throws "AccessViolationException" in NetCoreApp as expected.
Following exception is happening for NetFx:
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Runtime.InteropServices.Marshal.WriteByte(Object ptr, Int32 ofs, Byte val)
at Xunit.Assert.RecordException(Action testCode) in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.assert\Asserts\Record.cs:line 23
at Xunit.Assert.Throws[T](Action testCode) in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.assert\Asserts\ExceptionAsserts.cs:line 22
at System.Runtime.InteropServices.Tests.ObjectTests.NullValueArguments_ThrowsArgumentNullException() in F:\GitRepo\corefx\src\System.Runtime.InteropServices\tests\System\Runtime\InteropServices\Marshal\ReadWrite\ObjectTests.cs:line 32
Discussed with Aaron, the Exception is wrapped in a TargetInvocationException in the .NET Framework. So will disable this test for NetFx build