Bug 28367 - Passing invalid filename chars to System.IO.FileInfo() yields different results in .NET vs. Mono
Summary: Passing invalid filename chars to System.IO.FileInfo() yields different resul...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib (show other bugs)
Version: 3.12.0
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-03-24 12:19 UTC by Ben Schalley
Modified: 2015-03-25 05:24 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
screenshot of command windows mono and .net side by side (83.13 KB, image/png)
2015-03-25 05:24 UTC, Ben Schalley
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 28367 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Ben Schalley 2015-03-24 12:19:27 UTC
In .Net on Windows * and ? are illegal path characters. In Mono on Windows however they are allowed. This causes different behavior when instantiating a System.IO.FileInfo() object with a path containing one of these characters, Mono accepts it but .Net throws a System.ArgumentException. This was tested on the same machine and OS.

This Bug was already reported in the time that Novell was the primary backer of the Mono-project, hence the following bug-report from 7 (seven) years ago https://bugzilla.novell.com/show_bug.cgi?id=383905

To reproduce execute the following code in a console application with the .Net Framework and Mono.



using System;

namespace FileInfoTest
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            foreach (char illegalChar in System.IO.Path.GetInvalidFileNameChars()) {
                try {
                    string path = illegalChar.ToString();
                    Console.Write(@path + ": ");
                    System.IO.FileInfo dir = new System.IO.FileInfo(illegalChar.ToString());
                    Console.WriteLine("No exception thrown!");
                } catch (Exception ex) {
                    Console.WriteLine(ex.GetType() + ": " + ex.Message);
                }
            }
            Console.Read();
        }
    }
}




EXPECTED OUTPUT:
": System.ArgumentException: Illegal characters in path.
<: System.ArgumentException: Illegal characters in path.
>: System.ArgumentException: Illegal characters in path.
|: System.ArgumentException: Illegal characters in path.
 : System.ArgumentException: Illegal characters in path.
☺: System.ArgumentException: Illegal characters in path.
☻: System.ArgumentException: Illegal characters in path.
♥: System.ArgumentException: Illegal characters in path.
♦: System.ArgumentException: Illegal characters in path.
♣: System.ArgumentException: Illegal characters in path.
♠: System.ArgumentException: Illegal characters in path.
: System.ArgumentException: Illegal characters in path.
: System.ArgumentException: Illegal characters in path.
        : System.ArgumentException: The path is not of a legal form.

: System.ArgumentException: The path is not of a legal form.
♂: System.ArgumentException: The path is not of a legal form.
♀: System.ArgumentException: The path is not of a legal form.
: System.ArgumentException: The path is not of a legal form.
♫: System.ArgumentException: Illegal characters in path.
☼: System.ArgumentException: Illegal characters in path.
►: System.ArgumentException: Illegal characters in path.
◄: System.ArgumentException: Illegal characters in path.
↕: System.ArgumentException: Illegal characters in path.
‼: System.ArgumentException: Illegal characters in path.
¶: System.ArgumentException: Illegal characters in path.
§: System.ArgumentException: Illegal characters in path.
▬: System.ArgumentException: Illegal characters in path.
↨: System.ArgumentException: Illegal characters in path.
↑: System.ArgumentException: Illegal characters in path.
↓: System.ArgumentException: Illegal characters in path.
→: System.ArgumentException: Illegal characters in path.
←: System.ArgumentException: Illegal characters in path.
∟: System.ArgumentException: Illegal characters in path.
↔: System.ArgumentException: Illegal characters in path.
▲: System.ArgumentException: Illegal characters in path.
▼: System.ArgumentException: Illegal characters in path.
:: System.ArgumentException: The path is not of a legal form.
*: System.ArgumentException: Illegal characters in path.
?: System.ArgumentException: Illegal characters in path.
\: No exception thrown!
/: No exception thrown!


ACTUAL OUTPUT FROM MONO:
 : System.ArgumentException: Illegal characters in path.
☺: System.ArgumentException: Illegal characters in path.
☻: System.ArgumentException: Illegal characters in path.
♥: System.ArgumentException: Illegal characters in path.
♦: System.ArgumentException: Illegal characters in path.
♣: System.ArgumentException: Illegal characters in path.
♠: System.ArgumentException: Illegal characters in path.
: System.ArgumentException: Illegal characters in path.
: System.ArgumentException: Illegal characters in path.
        : System.ArgumentException: Illegal characters in path.

: System.ArgumentException: Illegal characters in path.
♂: System.ArgumentException: Illegal characters in path.
♀: System.ArgumentException: Illegal characters in path.
: System.ArgumentException: Illegal characters in path.
♫: System.ArgumentException: Illegal characters in path.
☼: System.ArgumentException: Illegal characters in path.
►: System.ArgumentException: Illegal characters in path.
◄: System.ArgumentException: Illegal characters in path.
↕: System.ArgumentException: Illegal characters in path.
‼: System.ArgumentException: Illegal characters in path.
¶: System.ArgumentException: Illegal characters in path.
§: System.ArgumentException: Illegal characters in path.
▬: System.ArgumentException: Illegal characters in path.
↨: System.ArgumentException: Illegal characters in path.
↑: System.ArgumentException: Illegal characters in path.
↓: System.ArgumentException: Illegal characters in path.
⌂: System.ArgumentException: Illegal characters in path.
←: System.ArgumentException: Illegal characters in path.
→: System.ArgumentException: Illegal characters in path.
↔: System.ArgumentException: Illegal characters in path.
▲: System.ArgumentException: Illegal characters in path.
▼: System.ArgumentException: Illegal characters in path.
": System.ArgumentException: Illegal characters in path.
<: System.ArgumentException: Illegal characters in path.
>: System.ArgumentException: Illegal characters in path.
|: System.ArgumentException: Illegal characters in path.
:: System.ArgumentException: path
*: No exception thrown!
?: No exception thrown!
\: No exception thrown!
/: No exception thrown!
Comment 1 Ben Schalley 2015-03-25 05:11:45 UTC
Found when using Mono 3.2.3 and now confirmed to still being present in version 3.12.1.
Comment 2 Ben Schalley 2015-03-25 05:24:09 UTC
Created attachment 10490 [details]
screenshot of command windows mono and .net side by side

In this screenshot two command windows are shown side by side. The left command window is a Mono 3.12.1 command window showing the result of the test console app. The right command window is a standard Windows command window showing the result from the test console app run with .Net Framework 4.0. Both command windows are executed with elevated permissions.