runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Different behavior between desktop and .NET Core for API - Marshal.WriteByte(object ptr, int ofs, byte val)

Open jiangzeng opened this issue 8 years ago • 6 comments

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 avatar Jul 04 '18 01:07 jiangzeng

@jiangzeng This should be addressed now. Please try with the latest coreclr - see referenced PR. Thanks!

AaronRobinsonMSFT avatar Jul 05 '18 21:07 AaronRobinsonMSFT

Eh, all PR unit tests now consistently fail because of this.

filipnavara avatar Jul 07 '18 19:07 filipnavara

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 avatar Jul 07 '18 20:07 stephentoub

@stephentoub Thanks!

filipnavara avatar Jul 07 '18 20:07 filipnavara

@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

jiangzeng avatar Jul 10 '18 05:07 jiangzeng

Discussed with Aaron, the Exception is wrapped in a TargetInvocationException in the .NET Framework. So will disable this test for NetFx build

jiangzeng avatar Jul 10 '18 07:07 jiangzeng