Hi All,
I am subscribed to the AppDomain.CurrentDomain.AssemblyLoad event,
which fires whenever a new assembly is loaded. Our application loads an
assembly, then through this event, checks to see that the assembly
conforms to a set of rules. If the assembly does not conform, then I
throw an exception that (for now) should cause the whole application to
come to a crashing halt, as it is unhandled by any of my code.
However the problem is, and you don't hear this everyday, but "My
application ISN'T crashing!". It appears as though the whoever is
calling the AssemblyLoad event, is also catching my exception. I dont
think this is normal, or intended. I cant see what else could be doing
it.
Anyway hopefully I have it all wrong, and some "kind soul" out there
can sort me out.
Waiting with anticipation,
Shane.
Here is some sample code to illustrate the problem. It was an example
console app, you will need to replace C:\src\bin\Debug\SomeAssembly.dll
with a path to some assembly on your machine if you wish to run it. You
will see that the application runs perfectly fine, where I believe it
should fall in a heap:
BTW: Is there a formating block I can put around code when posting?
using System;
using System.Reflection;
namespace TestConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(CurrentDomain_Unhan dledException);
AppDomain.CurrentDomain.AssemblyLoad += new
AssemblyLoadEventHandler(CurrentDomain_AssemblyLoa d);
Assembly.LoadFrom( @"C:\src\bin\Debug\SomeAssembly.dll" );
Console.WriteLine( "Press Enter to Exit: " );
string farts = Console.ReadLine();
}
private static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)
{
Console.WriteLine( "Wow, the exception was unhandled, and finally
arrived here. Yeah, Yeah Yeah!" );
}
private static void CurrentDomain_AssemblyLoad(object sender,
AssemblyLoadEventArgs args)
{
throw new Exception( "Here is the Exception" );
}
}
}