0

When I construct a new DirectoryInfo using a network path like this:

using Delimon.Win32.IO;

DirectoryInfo di = new DirectoryInfo(@"\\a\path\to\a\place\you\are\not\allowed\to\know")

I know the path is correct since it opens in my browser when I copy paste. But I am getting an error:

"System.OverflowException: Arithmetic operation resulted in an overflow."

This is all the call stack info I can give.

System.OverflowException: Arithmetic operation resulted in an overflow.
at Delimon.Win32.IO.Helpers.GetFileInformation(String path)
at Delimon.Win32.IO.FileSystemInfo.Refresh()
at Delimon.Win32.IO.DirectoryInfo..ctor(String dir)

The path is 67 characters long. So its not a long path.

I can't find any documentation on System.OverflowException resulting from the construction of DirectoryInfo objects.

Any help?

akinuri
  • 10,690
  • 10
  • 65
  • 102
G. H.
  • 35
  • 3
  • Are you sure you are using slashes and not backslashes? Backslashes should be escaped, just in case. – Flot2011 Jun 19 '17 at 21:05
  • Looking at reference source and complete calls stack is the way to solve it if you can't post [MCVE]. – Alexei Levenkov Jun 19 '17 at 21:06
  • I am using backslashes. And they are properly escaped. I have edited the question to reflect that. sorry about the confusion. – G. H. Jun 19 '17 at 21:09
  • Without a stack trace, this is impossible to diagnose. It shouldn't be hard to supply one, given that you apparently know `new DirectoryInfo` is producing the exception. (How, by the way? If you're going by mere line numbers, be aware that those can be off if you have a release build, or your .pdb file is not up to date.) – Jeroen Mostert Jun 19 '17 at 21:10
  • 3
    There we go, it's rather vital to know you're using `Delimon.Win32.IO.DirectoryInfo`, which is not the `System.IO.DirectoryInfo` we all know and love. This appears to be [rather old and unmaintained](https://gallery.technet.microsoft.com/DelimonWin32IO-Library-V40-7ff6b16c) (no NuGet package for it either), so any bugs in it will probably not get fixed. – Jeroen Mostert Jun 19 '17 at 21:15
  • I know it is throwing the error because when I step through the code and get to the constructor, I catch the exception. – G. H. Jun 19 '17 at 21:15
  • 1
    See https://gallery.technet.microsoft.com/DelimonWin32IO-Library-V40-7ff6b16c/view/Discussions#content, you're not the only one with the problem – C.Evenhuis Jun 19 '17 at 21:16
  • 1
    sounds similiar to https://stackoverflow.com/questions/33893164/overflowexception-with-delimon-directory-exists, EDIT: I keep forgetting enter submits on comments....any way it sounds like an issue with the library your using to access long file names, are you sure you need it? – Steve Jun 19 '17 at 21:18
  • Jeroen Mostert was right. It works now. thank you so much. – G. H. Jun 19 '17 at 21:23

2 Answers2

2

I was getting this exact error just now

System.OverflowException: 'Arithmetic operation resulted in an overflow.'

and managed to isolate the cause.

The following line was giving the error:

string[] files = Delimon.Win32.IO.Directory.GetFiles(@"d:\temp");

This line is from an old app that I'm rewriting. Knowing that it works in the old version, but not in the new version, I've removed everything and everything in the new version and was left with an empty form. I still got the error.

Then I created a new empty project and tried the code in it, and it worked. So even though I removed everything in my new app, I still get the error. This suggests there's something wrong with the settings. So I started comparing project files.

In the *.csproj file, there was this line:

<Prefer32Bit>false</Prefer32Bit>

and it was not in the old app nor in the new project.

It seems that when a new project is created, "Prefer 32-bit" (Project -> Properties -> Build -> General) is checked by default, but in my new app, this was not checked. I don't remember unchecking it myself, so I don't know how it got unchecked. Once I checked it, I no longer get the error.

akinuri
  • 10,690
  • 10
  • 65
  • 102
0

I was using Delimon.Win32.IO.DirectoryInfo which is apparently an old, un-maintained code base. I should have been using System.IO.DirectoryInfo

G. H.
  • 35
  • 3