harriyott.com

Tuesday, November 21, 2006

FileNotFoundException with CustomActions in Windows Installer

I'm building an installer with .NET 2.0 at the moment. I've been adding CustomActionData to the CustomAction dll, which includes a path. After adding a couple of new parameters, I started getting this message:
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: Could not load file or assembly
'file:///C:\Windows\system32\Files\Company\Product\CustomActions.dll' or one of its dependencies. The system cannot find the file specified..

Now, I'm not actually trying to put the custom action in system32, it should be going under Program Files. The problem turned out to be a CustomActionData parameter. Here are the two values I tried - the first works and the second fails:

/installpath="[ProgramFilesFolder][Manufacturer]\[ProductName]"
/installpath="[ProgramFilesFolder][Manufacturer]\[ProductName]\"

What seems to be happening is that the \" is escaping the quote. The installer must be putting extra parameters after the supplied string, which are used to locate the CustomActions dll. Because the last quote is escaped, the value of the hidden parameters is appended to my installpath parameter, and the installer "loses" the CustomActions dll. I think that this probably counts as a bug in the installer.

This one has been bugging me all afternoon, and I didn't have much luck with Google. I've laden this post with keywords, so hopefully someone else will benefit from my hideous afternoon. [n.b. we have no internal mechanism for recording findings like this, so I use this blog as a personal store for non-IPR work stuff].

Update: I needed too use [SourceDir] to, but this didn't work, unless there trailing slash was present!. This is the opposite of the previous behaviour, so the second one of these works and the first one fails. Weird.

/installedfrom="[SourceDir]"
/installedfrom="[SourceDir]\"

12 Comments:

Anonymous Anonymous said...

Are you supposed to post stuff that you write during work hours? Surely anything you produce during working time is owned by the company and is not yours to post for others to use.

November 23, 2006 9:37 AM  
Anonymous Simon said...

Thanks for your comment - are you a colleague of mine? It's an interesting point you make, and one that I have considered in the past.

Firstly, when I started working for EurotaxGlass's, I told the CTO about my blog, and asked him what was appropriate to post. He replied that the only out-of-bounds area was source code that would give our competitors insight into our workings, and jeopardise our competitive advantage. So firstly, I have permission.

Secondly, this particular post doesn't relate to anything I have produced for the company, it is a work-around for bug in the installer technology in Visual Studio.

Thirdly, the principle I adhere to when blogging about things I do at work is to ask myself whether the company will lose out financially or otherwise from a particular post. I believe in this case, the company won't be harmed.

As a developer, when I come across a problem like this, one of the first things I do is to check out Google to see if anyone else has solved the problem before. More often than not, it's the bloggers who have the most useful information. This approach has saved me so much time I don't know how I coped before having internet access at work.

Because of this, and also because I'm a community sort of guy, I like to do the same thing. I get a buzz out of helping people solve problems. If you check out the comments on this post, that sums up why I put this kind of stuff on my blog.

We don't have a mechanism inside the company for logging this kind of issue, and if there was I would post it there too (although I think I'd still try Google first anyway).

You may be interested to know that one of my colleagues had an issue that he Googled for, and my blog came up in the results, and my blog post solved his problem. I actually helped the company by blogging - isn't that cool?

Anyway, thanks for taking time to comment.

November 23, 2006 7:56 PM  
Anonymous Anonymous said...

Wow, thats a really naive comment.
How can something that somebody has learned (whether it be at work or not) be property of a company.

I think you are confusing the posting of generic (and helpful) information with the posting of company property (such as segments of actual source code).
By your logic when I change jobs, I would have to unlearn anything I learned in my current position.

November 24, 2006 10:17 AM  
Anonymous Anonymous said...

by the way, the comment above is aimed at the original commenter, not Simon!

November 24, 2006 10:20 AM  
Anonymous Anonymous said...

As the original poster, let me clarify what I mean:

No you dont have to unlearn anything (that is daft!), but work you do for a company in their time is their property. Work you do coding in your own time is yours to do with what you like.

Anyway, its your concience at the end of the day isnt it.

November 29, 2006 2:07 PM  
Blogger ureyes84 said...

Man, you are really stubborn, do a favor to the world and let the developer's community grow. Simon you saved me so much time with your post!! You are the best

April 19, 2007 7:12 PM  
Blogger ureyes84 said...

By the way....

I just asked my boss and she said it was OK to post -according to the Anonymous poster- my company's intellectual property:

I'm working on an installer for a web application which includes a CustomAction and it was working fine with the next parameters:

/OracleInstance=[EDTA1ORACLEINSTANCE]@/TargetDir="[TARGETDIR]\"

until I added one more:

/OracleInstance=[EDTA1ORACLEINSTANCE]@/TargetDir="[TARGETDIR]\"@/TargetVDir="[TARGETVDIR]\"

When I tried to run it I got this FileNotFoundException and after I read your blog I figured it out:

"[TARGETVDIR]" does not need an ending "\" whereas "[TARGETDIR]\" does.

/OracleInstance=[EDTA1ORACLEINSTANCE]@/TargetDir="[TARGETDIR]\"@/TargetVDir="[TARGETVDIR]"

Hope this helps some one else

April 19, 2007 7:30 PM  
Blogger Simon said...

Thanks for adding this ureyes84, and your kind comments. I'm glad you found it useful.

April 20, 2007 7:45 AM  
Anonymous Anonymous said...

Thanks for posting this. I spent about 2 hours messing with this until I found your post. I owe you one, maybe I'll be able to share a tip with you some day.

July 03, 2007 1:56 AM  
Anonymous Anonymous said...

Simon, these sort of pages are what makes the Web so fantastic. I've also been mucking around for hours on exactly the same problem, and this seems to be the only site that makes the problem & its solution clear. Thanks again!

August 14, 2007 12:49 AM  
Blogger Hayrob said...

Thanks for this, and like your previuos commenter, this is a great help. Unfortunately for me, I encountered the problem, found the the solution after hours of abortive searching!
What I did not do is post the answer on my blog - more fool me.

Well done- keep up the good work.

August 14, 2007 11:00 AM  
Blogger Paul Wh said...

This may be obvious, but it hasn't been explicit stated.
The reason that some variables require the added trailing slash and some don't is that if the variable itself contains a trailing slash, a second slash will cause the first one to act as an escape character, so that you don't escape the end quote.
Example

if [TargetDir] is C:\My Program then no trailing slash is necessary since the quoted string "[TargetDir]" ends up looking like "C:\My Program"

If [TargetDir] is C:\My Program\ on the other hand, then "[TargetDir]" would yeild "C:\My Program\" and thus the end quote would get escaped, and your paramater would swallow ub the next parameter in line up to the next unescaped quote (i.e. bad things happen). To prevent this you can either add the trailing slash which yields "C:\My Program\\" thereby escaping the \ rather than the " or, if the program consuming the parameter is forgiving and Trims paths you could use a trailing space like so: "[TargetDir] ". The advantage of the trailing space is that it avoids the "does my variable end in a trailing slash or not?" question altogether and should work either way.

February 14, 2008 10:55 PM  

Post a Comment

Links to this post:

Create a Link

<< Home