One of my constructors was throwing a "ArgumentNullException", so I start debugging.
And I found this weird issue. As you can see, the debugger says my propsSegment is NOT null; yet the Debug.Assert says it IS null.
What is going on here?
This is a .Net Core 2.0 project, being compiled to x64. I'm running a single thread and have plenty of memory to spare.
If you guys want to check the source, the project is hosted here. I created a branch just to show this issue. If you try to compile it, you'll need a "otbm" file. The one I'm using is zipped here
Edit: the downvotes makes me think I'm missing something obvious. Could someone please just tell me what is it?
And the full stack trace:
System.ArgumentNullException
HResult=0x80004003
Message=Value cannot be null.
Source=System.Private.CoreLib
StackTrace:
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.ArraySegment`1.op_Implicit(T[] array)
at COTS.GameServer.World.WorldLoader.ConvertingParsingNode(Byte[] serializedWorldData, ParsingWorldNode subtree) in C:\Source\CoreOpenTibiaServer\CoreOpenTibiaServer\src\COTS.GameServer\World\WorldLoader.Methods.cs:line 153
at COTS.GameServer.World.WorldLoader.<>c__DisplayClass10_0.<ConvertingParsingNode>b__0(ParsingWorldNode c) in C:\Source\CoreOpenTibiaServer\CoreOpenTibiaServer\src\COTS.GameServer\World\WorldLoader.Methods.cs:line 148
at System.Linq.Enumerable.SelectListIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at COTS.GameServer.World.WorldLoader.ConvertingParsingNode(Byte[] serializedWorldData, ParsingWorldNode subtree) in C:\Source\CoreOpenTibiaServer\CoreOpenTibiaServer\src\COTS.GameServer\World\WorldLoader.Methods.cs:line 146
at COTS.GameServer.World.WorldLoader.<>c__DisplayClass10_0.<ConvertingParsingNode>b__0(ParsingWorldNode c) in C:\Source\CoreOpenTibiaServer\CoreOpenTibiaServer\src\COTS.GameServer\World\WorldLoader.Methods.cs:line 148
at System.Linq.Enumerable.SelectListIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at COTS.GameServer.World.WorldLoader.ConvertingParsingNode(Byte[] serializedWorldData, ParsingWorldNode subtree) in C:\Source\CoreOpenTibiaServer\CoreOpenTibiaServer\src\COTS.GameServer\World\WorldLoader.Methods.cs:line 146
at COTS.GameServer.World.WorldLoader.<>c__DisplayClass10_0.<ConvertingParsingNode>b__0(ParsingWorldNode c) in C:\Source\CoreOpenTibiaServer\CoreOpenTibiaServer\src\COTS.GameServer\World\WorldLoader.Methods.cs:line 148
at System.Linq.Enumerable.SelectListIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at COTS.GameServer.World.WorldLoader.ConvertingParsingNode(Byte[] serializedWorldData, ParsingWorldNode subtree) in C:\Source\CoreOpenTibiaServer\CoreOpenTibiaServer\src\COTS.GameServer\World\WorldLoader.Methods.cs:line 146
at COTS.GameServer.World.WorldLoader.<>c__DisplayClass10_0.<ConvertingParsingNode>b__0(ParsingWorldNode c) in C:\Source\CoreOpenTibiaServer\CoreOpenTibiaServer\src\COTS.GameServer\World\WorldLoader.Methods.cs:line 148
at System.Linq.Enumerable.SelectListIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at COTS.GameServer.World.WorldLoader.ConvertingParsingNode(Byte[] serializedWorldData, ParsingWorldNode subtree) in C:\Source\CoreOpenTibiaServer\CoreOpenTibiaServer\src\COTS.GameServer\World\WorldLoader.Methods.cs:line 146
at COTS.GameServer.World.WorldLoader.ConvertParsingTree(Byte[] serializedWorldData, ParsingWorldNode root) in C:\Source\CoreOpenTibiaServer\CoreOpenTibiaServer\src\COTS.GameServer\World\WorldLoader.Methods.cs:line 135
at COTS.GameServer.World.WorldLoader.ParseWorld(Byte[] serializedWorldData) in C:\Source\CoreOpenTibiaServer\CoreOpenTibiaServer\src\COTS.GameServer\World\WorldLoader.Methods.cs:line 31
at COTS.GameServer.Program.Main(String[] args) in C:\Source\CoreOpenTibiaServer\CoreOpenTibiaServer\src\COTS.GameServer\Program.cs:line 20
This is an open issue with ArraySegment. See https://github.com/dotnet/coreclr/issues/14012
Note though, that you do not need to check for null since ArraySegment is a struct.
My guess is that the equality operator for ArraySegment is trying to implicitly convert the null to an ArraySegment, and that may be what is generating the actual NullReference exception.
User contributions licensed under CC BY-SA 3.0