none
Path too long? - System.IO.PathTooLongException

    Question

  • Hi,

     

    I am using the EnvDTE80.Solution2.AddFromTemplate method to create and add a project to a solution. This works fine for shorter paths. But today it was tested with a longer path and it produced the System.IO.PathTooLongException exception within the AddFromTemplate method.

     

    The full error message is as follows: "System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters."

     

    I have checked the path where the project is to be created and it is only 169 characters in length, I have also checked the length of the path where the template is located and it is only 161 characters in length. I have also checked the deaper level folders that the AddFromTemplate method creates such as the bin/debug folder and the maximum length of path that I can see the AddFromTemplate method requiring to create is only 207 characters in length.

     

    Has anyone had any similar experiences with the System.IO.PathTooLongException exception being thrown when you wouldn't expect it to be or any quirks in the AddFromTemplate method?

     

    Thanks,

    Alan

    Thursday, April 10, 2008 11:20 AM

Answers

  • I test your code under both VS2005SP1 and VS2008 and reproduce this issue. Seems like an issue with the VS automation model.

    You may also submit it to the following site in the formal way, and I'd appreciate if you can post the feedback address so that it can be found by the community members having the similar issue.

    http://connect.microsoft.com/VisualStudio/


    Thanks for your valuable feedback

    Tuesday, April 15, 2008 2:42 AM

All replies

  • Could you please post the "a longer path" in more details? And what's the version of VS you're talking about?

    To troubleshoot this issue, we really need the source code and the detailed repro steps to reproduce the problem, so that we can investigate the issue in house. It is not necessary that you send out the complete source of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business logic from it.


    Monday, April 14, 2008 3:50 AM
  • Hi Feng,

     

    Thanks for getting back to me.

     

    Here is an example of the path that I am referring to: "C:\My Files\From Work PC\aaaaaaaaaaaaaa\Development\aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\aaaaaaaaaaaaaaaaaaaa\aaaaaaaaaaaaaaaaaaaa\bin\Release". I have censored my original path but have tested this one and it produces the same exception (System.IO.PathTooLongException). I am using Visual Studio 2005.

     

    Here is piece of source code that produces the exception:

     

    EnvDTE.DTE dte = (EnvDTE.DTE)System.Activator.CreateInstance(System.Type.GetTypeFromProgID("VisualStudio.DTE.8.0"), true);

    EnvDTE80.DTE2 dte2 = (EnvDTE80.DTE2)dte;

     

    string solution_path = "C:\\My Files\\From Work PC\\aaaaaaaaaaaaaa\\Development\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\aaaaaaaaaaaaaaaaaaaa\\aaaaaaaaaaaaaaaaaaaa\\bin\\Release\\vs_MyNewSolution";

     

    Directory.CreateDirectory(solution_path);

     

    EnvDTE80.Solution2 vsSolution = (EnvDTE80.Solution2)dte2.Solution;

    vsSolution.Create(solution_path, "MyNewSolution");

     

    string template_path = "C:\\My Files\\From Work PC\\aaaaaaaaaaaaaa\\Development\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\aaaaaaaaaaaaaaaaaaaa\\aaaaaaaaaaaaaaaaaaaa\\bin\\Release\\Templates\\Template.csproj";

     

    if (File.Exists(template_path))

    {

    string project_code_path = solution_path + "\\vs_MyNewSolution";

    EnvDTE.Project vsProject = (EnvDTE.Project)vsSolution.AddFromTemplate(template_path, project_code_path, "vs_MyNewSolution", false);

    vsProject.Save(vsProject.FullName);

    vsSolution.SaveAs(vsSolution.FullName);

    }

     

    The above code assumes that there is a folder called Templates within this folder "C:\\My Files\\From Work PC\\aaaaaaaaaaaaaa\\Development\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\aaaaaaaaaaaaaaaaaaaa\\aaaaaaaaaaaaaaaaaaaa\\bin\\Release\\" that contains a template C# project file called "Template.csproj". This is just an empty C# project.

     

    The exception occurs on the following line of code:

    EnvDTE.Project vsProject = (EnvDTE.Project)vsSolution.AddFromTemplate(template_path, project_code_path, "vs_MyNewSolution", false);

     

    I hope this is enough details - please let me know if there is anything else you need to know.

     

    Thanks,

    Alan

    Monday, April 14, 2008 8:24 AM
  • I test your code under both VS2005SP1 and VS2008 and reproduce this issue. Seems like an issue with the VS automation model.

    You may also submit it to the following site in the formal way, and I'd appreciate if you can post the feedback address so that it can be found by the community members having the similar issue.

    http://connect.microsoft.com/VisualStudio/


    Thanks for your valuable feedback

    Tuesday, April 15, 2008 2:42 AM
  • I post the feedback address of this issue here so that it can be found by community members having the similar issue:
    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=338223&wa=wsignin1.0

    Thanks!
    Wednesday, April 16, 2008 2:50 AM
  • Thanks Feng,

     

    Alan

    Wednesday, April 16, 2008 8:29 AM