Tech Off Thread

6 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Shortcut with Args - Error! Shortcut without - a-okay!

Back to Forum: Tech Off
  • User profile image

    I believe the problem is just my lack of understanding, but hopefully someone can point me in the right direction.

    So situation is, I have a VB .NET solution with 2 projects; the exe and a class library (which I'm using to hold interfaces, base classes, resources etc.

    It basically creates orders via a 3rd party web service, so to allow me to test I have a couple of arguments that tell the program to use the test version of the web service rather than the live.

    I've then built created an installer project in which I create a shortcut to the app on the desktop. Finally when the app launches I display the version number of the exe and the class library in the status bar so that should an issue arise we can see immediately which version is running from a screenshot.

    All good so far, and when installed and run from the shortcut (without args) everything loads without issue.

    However if I copy the shortcut created and add my arguments to it (/test added to the end of the Start in: field) I get the following error;

    Could not load file or assembly 'C:\Documents and Settings\user\Desktop\MyLibrary.dll' or one of its dependencies. The system cannot find the file specified.

    I've tracked down what is causing the error to these lines;

    Dim _asm as System.Reflection.AssemblyName = Nothing
    _asm = System.Reflection.AssemblyName.GetAssemblyName("MyLibrary.dll") 
    Return _asm.Version.ToString() 

    What I'm failing to understand is why it works when;
    • I run the shortcut without arguments
    • When I manually create the shortcut and add my argument rather than using the one created by the installer.

    If anyone has any ideas or answers I'd love to hear what you have to say.

  • User profile image

    @StinkyPants: Maybe something with the working directory of the shortcut? It sounds like the program is looking on the desktop for the DLL.

  • User profile image

    I think you're right spivonius, but it's still confusing why it works when I don't set any arguments.

    BTW I managed to resolve it by using;

    _asm = System.Reflection.AssemblyName.GetAssemblyName( _
    	IO.Path.Combine(My.Application.Info.DirectoryPath, "MyLibrary.dll"))

    This works whichever shortcut I use. It'd just be nice to know what the problem was in the first place if only to expand my knowledge.

  • User profile image

    @StinkyPants:Probably because shortcuts created by an Installer project are magical COM-based Windows Installer shortcuts, rather than just bog standard .lnk shortcuts.

  • User profile image

    Yep.  It is a path search problem.  The working directory isn't the same.  Put a little debug message in your app and test to verify.

  • User profile image

    Thanks guys. I figured it was something to do with the shortcuts as I could clearer see there was a difference between the one created by the installer and the one created by me which worked fine with arguments.

    Please don't bother to loose any more sleep over this one as I have it working fine now.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.