0

Following the reference source link in the answer to this question, System.IO.FileStream.Init only throws the NotSupportedException once with the Argument_PathFormatNotSupported string, in the circumstance of an erroneously positioned ":" character.

However, in my code this "The given path's format is not supported" error is thrown even when this condition is not present, e.g.

PHS shape = new PHS();
try
{
    string filePath = Path.GetFullPath(Path.GetDirectoryName(Application.ExecutablePath) + "\\..\\..\\Maps\\ne_50m_urban_areas.shp");
    if (filePath.IndexOf(':', 2) != -1)
       MessageBox.Show("filePath bad");
    else
       MessageBox.Show("filePath okay");

    shape.LoadFile(Populated, filePath);
}
catch (NotSupportedException ee)
{
    MessageBox.Show(ee.StackTrace);
}

Running this code first gives me "filePath okay", but then gives me a NotSupportedException with the following stack:

stack

The LoadFile method is calling FileStream via System.IO.File.OpenRead(). What is curious is that this error is thrown only when the filePath is of a certain length - if the filePath is short, the error isn't thrown. This behaviour can be seen on copies of Win10, Win8.1 and Win2003.

Any explanations for this behaviour gratefully received, thank you.

Community
  • 1
  • 1
Shunyata Kharg
  • 927
  • 3
  • 14
  • 26
  • What *is* the file path? How long is it? – Panagiotis Kanavos Aug 11 '15 at 11:46
  • Can you add an example of a path name that doesn't work? – Luaan Aug 11 '15 at 11:46
  • 1
    There's at least one more `NotSupportedException` thrown from that method on [line 894](http://referencesource.microsoft.com/#mscorlib/system/io/filestream.cs,894) - do you have the message contained within the exception? – James Thorpe Aug 11 '15 at 11:47
  • As far as I know the file path length limit for windows is 255 characters (https://msdn.microsoft.com/en-us/library/aa365247.aspx#maxpath) Maybe its too long? – DerApe Aug 11 '15 at 11:48
  • Also what is the message? Init also throws NotSupportedException with a message explaining why if the path isn't a disk file - in line 894 as @JamesThorpe commented – Panagiotis Kanavos Aug 11 '15 at 11:48
  • 1
    _"if the filePath is short, the error isn't thrown"_ Is the short one you're testing with a local drive, as opposed to a long one that's on a network share perhaps? – James Thorpe Aug 11 '15 at 11:50
  • You need to fix your error reporting, use `ee.ToString()` instead. Now you know. – Hans Passant Aug 11 '15 at 11:53
  • What's the exception *message*? The stack trace isn't quite enough. – Luaan Aug 11 '15 at 11:55
  • +James Thorpe the NotSupportedException uses the Argument_PathFormatNotSupported string, and there is only one of these thrown in that method. – Shunyata Kharg Aug 11 '15 at 12:20
  • +derape the filePath which throws the error is 136 characters long, including the executable name. – Shunyata Kharg Aug 11 '15 at 12:22
  • +Luaan the exception message is Argument_PathFormatNotSupported = "The given path's format is not supported" – Shunyata Kharg Aug 11 '15 at 12:24
  • See if it works Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath) + "\\..\\..\\Maps\\ne_50m_urban_areas.shp")); – Sandeep Aug 11 '15 at 12:57
  • +Sandeep thank you, I had tried the 'magic wand' of Path.Combine without success, and unfortunately I still get the error with your suggestion. – Shunyata Kharg Aug 11 '15 at 13:12
  • What makes you think that stack trace of an optimized release version executable is reliable??? Moreover you have an exception message. It'll exactly tell you what's wrong. No need to guess anything inspecting or disassembling source code.... – Adriano Repetti Aug 11 '15 at 15:03
  • +Adriano Repetti The exception message is now in the original question. Maybe you could please tell me exactly what is wrong? – Shunyata Kharg Aug 11 '15 at 15:07
  • @ShunyataKharg I do not see any message in original question. Moreover: post you linked is a _case_, if you check MSDN you won't see any mention of that (it's just a case because : not as 2nd character will throw NotSupportedException - when non NTFS - because it's format used to identify devices). Error message... – Adriano Repetti Aug 11 '15 at 21:06

0 Answers0