VHD Get Partitions throws Exception: Source array was not long enough. Check srcIndex and length, and the array's lower bounds

Apr 17, 2014 at 11:44 AM
Edited Apr 17, 2014 at 11:46 AM

An exception is being thrown when retrieving the partitions of a particular VHD with an NTFS filesystem. The exception is a .NET exception which is being thrown from DiscUtils. The following is the stack trace.
[Exception Message]: Source array was not long enough. Check srcIndex and length, and the array's lower bounds.
[Exception Stacktrace]:    at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
   at DiscUtils.Partitions.GptHeader.ReadFrom(Byte[] buffer, Int32 offset)
   at DiscUtils.Partitions.GuidPartitionTable.Init(Stream disk, Geometry diskGeometry)
   at DiscUtils.Partitions.DefaultPartitionTableFactory.DetectPartitionTable(VirtualDisk disk)
   at DiscUtils.Partitions.PartitionTable.GetPartitionTables(VirtualDisk disk)
   at DiscUtils.VirtualDisk.get_Partitions()
   at MyClass.VHD.get_Partitions()
The strange part is that I tried to replicate it from my end but the ReadFrom method is not even being executed. I tried both a VHD and a VHDX but the ReadFrom method did not execute on neither of them. Since this method is being executed on the client's VHD I cannot properly replicate it.

When is this method (ReadFrom) supposed to execute? In the VHDs which I tested, it is not executing and everything is working fine.

As a side note, DiscUtils change version being used is b20326937bff

Your help on this matter would be greatly appreciated.

Thank you.