net Setup Project >> Custom Actions >> [TARGETDIR], error when user inputs path with spaces

Posted on 2006-04-05
Last Modified: 2008-11-28
I have created a Setup Project in .Net studio 2005, an install class that is included in the setup project and launched as a custom action on install and commit phases.
This install class requires path of the installation for some of its functions - which i attempted to pass to it by adding following line


to the CustomActionData property of the custom action.
During installation if the path the user selects contains no spaces, install goes through fine. If it does install throws System.IO.FileNotFoundException (this is being thrown by installer, not my class because the error happens even with an empty Installer class)

Attempted install path: c:\Program Files\MyCompany\MyProgram
Error message:

Exception occured while initializing the installation:
System.IO.FileNotFoundException: Could not load file or assembly
file:///C:\WINDOWS\System32\Files\MyCompany\MyProgram\ or one of its dependancies. The system could not find file specified.

No error if path is given as c:\ProgramFiles\MyCompany\MyProgram

I have found my way arround the error by writing [TARGETDIR] to registry and then retrieving it from there in my install class. But it seems strange for windows installer to crash when it encounters file system path with spaces.

So I want to know if i did something wrong to stumble on this error, since from other posts i read about setup projects other people seem to be having no such problems with the TARGETDIR property
Question by:creepy42
    LVL 4

    Accepted Solution

    Actually this is one of the more stupid and unnecessary problems i've come across in visual studio. I haven't found much documentation on why this is so, but it has to do with the way the installer invokes your custom action with arguments.
    I've found that the following

    Write /MyAppPath="[TARGETDIR]\" instead of /MyAppPath="[TARGETDIR]" (Note the enclosing "" and trailing \) in the CustomActionData property of the custom action. Play around with " and \ and you'll normally find a way.

    Author Comment

    Thank you, the magic slash did the trick.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now