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)

See Also:
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

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.

Note You need to log in before you can comment on or make changes to this bug.