Need for someone to analyze code to find out why it gives me an exception


  • I have this large class in another C# application. I placed it in GitHub because of the size. It is a Microsoft Class that I copied about 10 years or so ago. Since then they removed the page that hosted it. The link is now broken.

    It is all about reading raw memory. It worked when I first used it but now I get an exception. The exception is thrown at line 239 and it says: "Arithmetic operation resulted in overflow." At the bottom of the class there is another class "sizeT" which I copied from the link I posted. The author claims that class and another one solve the size problem. I suspect that PInvokeWin32 class was created in lieu of old hardware/disks which had much less memory and now it is all in Terabytes. I have no idea if it is true.

    I will appreciate any help.

    Thanks, - Alex

    • Edited by MyCatAlex Saturday, January 12, 2019 12:23 AM
    Saturday, January 12, 2019 12:12 AM

All replies

  • You should post the source for SizeT so those who want to assist have a clue what this method does, otherwise it's a guessing game.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, January 12, 2019 1:45 AM
  • There is a link there. That is the source. If not enough, here it is again: The code itself is there as well.

    • Edited by MyCatAlex Saturday, January 12, 2019 3:47 AM
    Saturday, January 12, 2019 3:46 AM
  • Hi,

    Please refer to the following documents to debug your project:

    First look at the Visual Studio Debugger

    Quickstart: Debug with C# or Visual Basic using the Visual Studio debugger

    How to trace and debug in Visual C#



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, January 14, 2019 9:18 AM
  • This is just P/Invoke code into Win32 which supports stuff far larger than TB. The code itself also supports well over TB because a ulong is 64-bits.

    The error you're getting indicates that you've tried to add a numeric value to an integral value and it exceeded the maximum size of the type. Line 239 (in GitHub) isn't in the middle of any arithmetic operations so it doesn't line up with the error you're getting. Personally it looks like you're throwing an exception trying to handle the underlying exception. You need to step through this code to identify the actual line of code.

    All this code looks really old and so I wonder if you've bothered to see if there are newer .NET libraries to handle this logic. I don't really understand what it is trying to do. You mention reading raw memory but it looks like it is reading file systems, not memory. What I wonder is if your code is making assumptions about file system layout that isn't valid anymore. Over the years NTFS has been modified to make adjustments for larger disks and newer features. If you're trying to do raw reads of the disk I suspect you're now reading the disk wrong. That's just a guess though.

    Michael Taylor

    Monday, January 14, 2019 3:28 PM