HighTechTalks DotNet Forums  

Catching FileNotFoundException when unable to load an

Dotnet Framework (CLR) microsoft.public.dotnet.framework.clr


Discuss Catching FileNotFoundException when unable to load an in the Dotnet Framework (CLR) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Prashanth Uppunda
 
Posts: n/a

Default Catching FileNotFoundException when unable to load an - 07-03-2003 , 01:55 AM






Hi,

I want to catch FileNotFoundException in case my
application is unable to find a required assembly file,
for logging a error message to my log file. Is it possible
to handle this exception ? I treid catching this exception
in Main(). But it wont work! Please let me know if any one
has any idea.

Thanks,
Prashanth


Reply With Quote
  #2  
Old   
Fabian Schmied
 
Posts: n/a

Default Re: Catching FileNotFoundException when unable to load an - 07-03-2003 , 01:36 PM






Quote:
I want to catch FileNotFoundException in case my
application is unable to find a required assembly file,
for logging a error message to my log file. Is it possible
to handle this exception ? I treid catching this exception
in Main(). But it wont work! Please let me know if any one
has any idea.
You could use the AssemblyResolve event of the AppDomain to log this.

Fabian




Reply With Quote
  #3  
Old   
Suzanne Cook [MS]
 
Posts: n/a

Default Re: Catching FileNotFoundException when unable to load an - 07-09-2003 , 06:29 PM



It sounds like there's a static reference to this assembly in Main(), which
the JIT will load before that method is executed. You should move that
reference to another method (which can be called by Main()) in order to
catch the exception. For example:

public static void Main(String[] args)
{
try {
OtherMethod();
}
catch (FileNotFoundException) {
}
}

public static void OtherMethod()
{
// code that uses the assembly that may not be found
}

Note that, if this is the cause of the problem, the AssemblyResolve event
will not be subscribed to in time to be useful, for the same reason (unless,
of course, you move the static reference to another method).

Suzanne Cook
My .NET CLR Loader blog: http://blogs.gotdotnet.com/suzcook/
--
Please do not respond directly to this alias. This alias is for newsgroup
purposes only. This posting is provided "AS IS" with no warranties, and
confers no rights.



"Fabian Schmied" <fabian.schmied (AT) fhs-hagenberg (DOT) ac.at> wrote

Quote:
I want to catch FileNotFoundException in case my
application is unable to find a required assembly file,
for logging a error message to my log file. Is it possible
to handle this exception ? I treid catching this exception
in Main(). But it wont work! Please let me know if any one
has any idea.

You could use the AssemblyResolve event of the AppDomain to log this.

Fabian





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.