Process.Start() causing TypeLoadException

I have a console application that uses Process.Start(full_path_to_myapplication.exe, "command_line_arg_1 command_line_arg_2") to start a Windows Forms application that has command-line arguments. (By the way, neither command line argument contains a space.) Trying to do this gives me the following error:

Error
An unexpected error has occurred in myapplication.exe. Select Quit and then restart this program, or select Details for more information.

File or assembly name "YourLibrary, Version=1.0.0.0, culture=neutral, PublicKeyToken=null', or one of its dependencies, was not found.

Clicking on details lets me know that this was a TypeLoadException.

YourLibrary.dll is clearly there in the same folder as myapplication.exe. If, instead, I write a simple one-line batch file with the following

full_path_to_myapplication.exe command_line_arg_1 command_line_arg_2

and run it (which is equivalent to opening a shell and launching it from the command line there), it works just fine.

Is there something inherent in Process.Start() that is different from a direct command-line start How can I convince my program that the missing DLL is, in fact, right in front of its nose

This is Windows CE 5.0, .NET CF 2.0 service pack 1.

Thanks,
Deborah




Answer this question

Process.Start() causing TypeLoadException

  • paso

    imed-deborah wrote:
    I apologize if I wasn't clear; I have a single bin directory with *everything* in it. I tried using ProcessStartInfo (setting the executable, command line args, and also UseShellExecute=true and WorkingDirectory=fullPathToMyBinDir) and got the same result. (Even UseShellExecute=false still gave me the same result.) It would appear that what I'm doing should be equivalent to running it from the command line, which works just fine. I can't figure out what is different with the two ways of launching it.

    Any insights

    Thanks,
    Deborah

    can you process.start the exe without command line args


  • Rob Wheeler

    My entire setup is pretty complicated. Here is a description in a nutshell:

    1. All of my executables and dlls live in ~/bin/, and the only things in that directory were written by me. All .NET stuff is elsewhere.
    2. I start Process A, which is a UI-less application. It connects to the server to get software updates (new versions of all the exes and dlls in the current bin directory) and places them all in ~/bin_new/.
    3. Process A starts Process B using Process.Start() with a couple of command line arguments. Process B is another UI-less application that relies on none of my dlls. Process A then shuts itself down.
    4. Process B waits for a few seconds to make sure that Process A has shut itself down and then moves ~/bin/ to ~/bin_bak/ and ~/bin_new/ to ~/bin/. (This moving of directories doesn't seem to be related to my problem below because the problem appears even if I don't actually do the directory move.)
    5. Process B then launches Process C using Process.Start() with command-line arguments. It uses the full path to the executable in the ~/bin/ directory (as noted in above posts, I've tried every possible permutation of Process.Start(), setting the working directory and so forth). Process C is a Windows Forms application that pulls in several of my dlls, all of which are definitely present in ~/bin/. It always gives the TypeLoadException on the first of my dlls that gets called; when I comment out the use of one, then it is the next one that seems to give it the problem. Process B then just exits because it has finished its tasks.
    6. When I replace Process C with a simple Windows Forms application that merely writes the command line arguments in a text box, then it works fine.
    7. When I type the equivelent of the command line I use to start the real Process C into a shell, everything works just fine. It is able to find the dlls in ~/bin/ that it didn't seem able to find before.
    8. At no time has a loader log ever been produced for Process B or Process C when they were started using Process.Start().

    I'm fresh out of ideas; it seems that I've tweaked almost all of my variables and I'm left with the unhelpful prospect that Process.Start() could just be broken when requiring assemblies that can't be loaded from the GAC. I really hope I'm wrong.

    Deborah

  • tremault

    I apologize if I wasn't clear; I have a single bin directory with *everything* in it. I tried using ProcessStartInfo (setting the executable, command line args, and also UseShellExecute=true and WorkingDirectory=fullPathToMyBinDir) and got the same result. (Even UseShellExecute=false still gave me the same result.) It would appear that what I'm doing should be equivalent to running it from the command line, which works just fine. I can't figure out what is different with the two ways of launching it.

    Any insights

    Thanks,
    Deborah

  • Peter Ritchie

    It is created for the first one but not for the subsequent one. I made sure that I had put in the correct registry keys to force unique file names so that the subsequent loader log wouldn't clobber the earlier one.

    Deborah

  • Adam Lofts

    I'm still having no luck. The loader log doesn't seem to work for thing started with Process.Start(), and I'm at a loss as to where to even look. I still can't figure out why Process.Start() would be functionally different from typing something into a command line.

    Any thoughts
    Deborah

  • Philip Jaques

    The odd thing is that the loader log isn't even being created for the process I'm trying to start with Process.Start().

    Deborah

  • billqu

    So what would happen if both EXEs and DLL are in the same folder Also, have you tried loader log

    http://blogs.msdn.com/stevenpr/archive/2005/02/28/381744.aspx



  • Michael Herman - Parallelspace

    What's in the loader log



  • enric vives

    No, I still get the same error.

    Deborah

  • rabbiwan

    Ilya Tumanov wrote:
    AndrewBadera wrote:

    I think she said the DLL and EXE _are_ in the same folder already ...

    Are they I only see what second exe is in the same folder as DLL.

    what's the second EXE myapplication.exe is the only one I'm seeing in her post ... two command args, but just one EXE


  • R.Tutus

    Deborah,

    Just a few questions that might help:
    • Have you tried starting a 'helloworld' kinda application that only has the required commandline arguments and nothing else
    • Are there other assemblies copied into your application folder (CF related assemblies that conflict with the ones installed )
    • Can you pinpoint which Type is responsible for the exception that is thrown
    • Are there custom assemblies required by the second application that are somehow more 'exotic' than others (By naming, by location, OpenNETCF )
    It is just a longshot, and i do not know if it wil lead to a solution, but is it possible to step by step extend your application (if the project isn't too big) Disabling most of your code/references and then step-by step enabling them should show if there is a specific assembly that is causing your problem. I guess that if this is the case (one single 'rogue' assembly that is messing it all up) all code related to other assemblies should just work fine.

    - Just my two pennies -

    Greetings from the cold Netherlands,

    Peter Vrenken


  • IrishWolf

    Ilya Tumanov wrote:

    So what would happen if both EXEs and DLL are in the same folder Also, have you tried loader log

    http://blogs.msdn.com/stevenpr/archive/2005/02/28/381744.aspx

    I think she said the DLL and EXE _are_ in the same folder already ...

    Deborah, have you tried starting the process with a ProcessStartInfo object containing your command line args

    http://msdn2.microsoft.com/en-US/library/system.diagnostics.processstartinfo.aspx


  • Ofer Gal

    AndrewBadera wrote:

    I think she said the DLL and EXE _are_ in the same folder already ...

    Are they I only see what second exe is in the same folder as DLL.



  • aztec2_step

    Is it created for first process



  • Process.Start() causing TypeLoadException