System.ArgumentException 'illegal characters in path.' RRS feed

  • Question

  • Hello everyone,

    I have got this weird and annoying issue, when I run my program on another PC.

    I've created a program called "The Lab" which is using C#, ASP.NET, MSSQLLocalDB 2016.

    Everything was installed using InstallShield (VS 2015).

    When I install the program on my PC and I run it, everything goes just fine but when I install it on another PC I get an error

    when trying to pass the stage where I use the DB.

    This is part of the error:

    System.ArgumentException: illegal characters in path.
       ב-  System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
       ב-  System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
       ב-  System.IO.Path.GetFullPath(String path)
       ב-  System.Drawing.IntSecurity.UnsafeGetFullPath(String fileName)
       ב-  System.Drawing.IntSecurity.DemandReadFileIO(String fileName)
       ב-  System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
       ב-  The_Lab.frmSetup3.frmSetup3_Load(Object sender, EventArgs e)
       ב-  System.EventHandler.Invoke(Object sender, EventArgs e)
       ב-  System.Windows.Forms.Form.OnLoad(EventArgs e)
       ב-  System.Windows.Forms.Form.OnCreateControl()
       ב-  System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       ב-  System.Windows.Forms.Control.CreateControl()
       ב-  System.Windows.Forms.Control.WmShowWindow(Message& m)
       ב-  System.Windows.Forms.Control.WndProc(Message& m)
       ב-  System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       ב-  System.Windows.Forms.Form.WmShowWindow(Message& m)
       ב-  System.Windows.Forms.Form.WndProc(Message& m)
       ב-  System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       ב-  System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       ב-  System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    Most of it doesn't really make sense to me, the only command I recognize there is:

    The_Lab.frmSetup3.frmSetup3_Load(Object sender, EventArgs e)

    This is the loading of the form where I actually start using the DB.

    Here is some of it's code:

    string que = "SELECT CompanyName FROM CompanyTbl";
    Object obj = DaS.ExecuteScalar(que);

    This is my connection string in 'App.config':

            <add name="ConnectionString"
                connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False" providerName="System.Data.SqlClient"/>

    The form which is loaded is inheriting from a Master Form, the way I use the path in the Master Form is this:

    string finalpath = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    DaS.Path = finalpath;

    I tried to make it as much informative as possible without making it too much complicated for you guys.

    Hopefully you could assist me with the issue and help me fix it :)

    Saturday, December 15, 2018 3:15 PM

All replies

  • MSSQLLocalDB 2016.

    And is LocalDB installed on the machine where the error occurs? If it is, can you start an instance of LocalDB?

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Saturday, December 15, 2018 4:59 PM
  • I started the instance.. "sqllocaldb start MSSQLLocalDB"

    Tried to run the program again but again got the same error.

    Saturday, December 15, 2018 5:30 PM
  • So LocalDB exists and can run; I don't see anything SQL Server related in the error message.

    The first part of the error message mention file I/O permissions, does to app load/write some files? What about .MDF database file, where is it located?

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Saturday, December 15, 2018 5:35 PM
  • I assume it has something to do with SQL since on my own PC it is working just fine.

    Of course I might just be wrong but this is my assumption.

    As for the location of the files, I selected the .mdf and .ldf files from my project while creating the

    InstallShield project so when the application is being installed, it's basically one folder in C:\

    contains .exe, .mdf, .ldf and .config

    Saturday, December 15, 2018 6:08 PM
  • Good day <?!?>.

    This error "System.ArgumentException: illegal characters in path" is not specifically for SQL Server connection but to .Net exception. As the message say it related to illegal characters in path. It can be related to invisible character in the PATH like Carriage return CHAR(13) or CHAR(0) for example.

    In this case, copy the connection string to the forum will not help as the invisible character is after all invisible :-)
    But it can be related to languages issue, which explain why in one machine it works well while in the other it does not,if these two machines has different configuration for the non-Unicode characters.

    ------------- Moving to the guessing Game ----------

    There can be multiple reasons for this error, but my first guess (AND IT IS ONLY A GUESS at time since we don't have enough information to point on specific reason yet), is that you use Hebrew in the machine that this is working well - I noticed a Hebrew character in the error.

    The English Error should be like:

    System.ArgumentException: illegal characters in path.
      At System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)

    but your text is:

    System.ArgumentException: illegal characters in path.
       ב-  System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)

    At in English is ב in Hebrew, and based on this I did my first guess

    Please confirm if you are using any language which is not English in one of these machines

    signature   Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]    [Linkedin]

    Saturday, December 15, 2018 11:20 PM
  • Hi Ronen,

    It is indeed in Hebrew, I translated part of the error but didn't see a reason to translate the whole :P

    I am using Hebrew on both machines but of course not in the code,

    I do need to point out that this application did work in the past but I left it unfinished for quite a while.

    After deciding to come back to it, as this project needs to be done soon, I did reinstall the whole Visual Studio

    and SQL Server on my PC as I formatted it.

    As you pointed, this is a .NET error, maybe it has something to do with the framework?

    This is the startup code in the App.config file:

            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0.2" />

    As for the connection string, I don't think it is language related but just in case it is, is there anything I can

    do to avoid it? Thanks alot.

    Monday, December 17, 2018 3:22 PM
  • Well I found out that on another PC it does work.

    Then tried completely other computer again and it doesn't work on him also.

    The only difference I see:

    The computers it does work on them are all English.

    The others are using different languages (Russian, Hebrew).

    The thing is, the applcation is located on C:\ so I don't see why is it happening.

    What can I do?

    Tuesday, December 18, 2018 1:26 PM