How to determine if another assembly is available for my application or not

I have a command line winforms executable that invokes a windows winforms application.

Occassionally Ops forget to include Windows exe with the exe command line when deploying the application, resulting in an error.

How I gracefully handle this and show a nice error, not:

Unhandled exception: System.IO.FileNotFoundException: it is possible not to load the file or ass in "MyappFoo", Version = 5.1.4303.0, Culture = neutral, PublicKeyToken = null or one of its dependencies. The system cannot find the specified file. File name: 'MyAppFoo, Version = 5.1.4303.0, Culture = Neutral, PublicKeyToken = null' in AppFoo.Program.Main (String [] args)

WRN: Assembly binding registration is off. To enable assembly error logging, set the registry value to [HKLM \ Software \ M icrosoft \ Fusion! EnableLog] (DWORD) to 1. Note. There is some performance limitation associated with assembly binding failure. To turn this feature off, delete the registry value [HKLM \ Software \ Microsoft \ Fus ion! EnableLog].

Edit:

To clarify a bit how to catch a FileNotFoundExcception when

static int Main(string[] args)
{
   try
   {
      Console.WriteLine"MyPhooApp Command Line (c) PhooSoft 2008");
   }
   catch (System.IO.FileNotFoundException fe)
   {
      Console.WriteLine("Unable to find foo.exe");
      return -1;
   }
}

does not work.

+1
source share
2 answers

You can use the Reflection-Only download function introduced in .NET 2.0. This allows you to load the assembly for verification without loading it into the application.

Assembly.ReflectionOnlyLoad

Assembly.ReflectionOnlyLoadFrom

+4
source

FileInfo.Exists?

0

All Articles