can't trap missing dll exception

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

I have a managed executable that references 2 managed dll's. In my Main method, all code is inside a
try/catch block. If dll A (a Compact Framwork project) is missing the System.IO.FileNotFound error is
trapped, but if dll B (a non-Compact Framwork project) is missing the FileNotFound error is not
trapped. I'd like to be able to trap the missing dll B error. What could I be doing wrong or not
understanding?

Thanks!
Tim
 
The second scenario will throw MissingMethodException. You may want to trap
a generic Exception and then make decisions based on its runtime type

--
Alex Feinman
---
Visit http://www.opennetcf.org
Tim said:
I have a managed executable that references 2 managed dll's. In my Main method, all code is inside a
try/catch block. If dll A (a Compact Framwork project) is missing the
System.IO.FileNotFound error is
 
I should have mentioned that I was indeed trapping the generic Exception.

The second scenario will throw MissingMethodException. You may want to trap
a generic Exception and then make decisions based on its runtime type

--
Alex Feinman
---
Visit http://www.opennetcf.org
Tim said:
I have a managed executable that references 2 managed dll's. In my Main method, all code is inside a
try/catch block. If dll A (a Compact Framwork project) is missing the
System.IO.FileNotFound error is
 
Nothing. The exception crashes the app. Could it be possible for it to choke before it gets to Main? I
have no using directives in Main's module for dll B

What are you getting in case B, if anything?
 
If it crashes the app, it means most likely something like access violation
inside the unmanaged code. A missing DLL would never cause a crash. Can you
single-step inside Main? What exactly does it say on the screen when the app
crashes? WHat does your PInvoke definition look like (and the corresponding
unmanaged functiuon signature)?



--
Alex Feinman
---
Visit http://www.opennetcf.org
Tim said:
Nothing. The exception crashes the app. Could it be possible for it to
choke before it gets to Main? I
 
MissingMethodException might be thrown while JITing. If some stuff is
missing, entire method won't be JIT'ed.
That includes any try/catch located in this method. Since try/catch never
JITed, exception won't be caught.

Samples to illustrate:

In that case exception won't be caught:

void foo () {
try {
object o = new MissingClass();
}
catch {
}
}

In that case exception will be caught:

void bar () {
try {
foo();
}
catch {
}
}

void foo () {
object o = new MissingClass();
}

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
I can't single step inside main when I change the name of dll B to make it missing. I can single step
of course if I change the name to dll A only. Both dll A and B are .NET class libraries, and my
project that crashes on missing dll B has references set in VStudio to both. Dll B does not make use
of any unmanaged code, whereas dll A does use umnanaged code.

The error on the screen on missing dll B is the same message as the trapped message for dll A (except
that A was handled): "An unhandled exception of type 'FileNotFoundException' occurred in Unknown
Module. Additional information: File or assembly name dllB, or one of its dependencies, was not
found."


If it crashes the app, it means most likely something like access violation
inside the unmanaged code. A missing DLL would never cause a crash. Can you
single-step inside Main? What exactly does it say on the screen when the app
crashes? WHat does your PInvoke definition look like (and the corresponding
unmanaged functiuon signature)?



--
Alex Feinman
---
Visit http://www.opennetcf.org
Tim said:
Nothing. The exception crashes the app. Could it be possible for it to
choke before it gets to Main? I
 
This solved my problem.

Thank you Ilya and Alex for your help!

MissingMethodException might be thrown while JITing. If some stuff is
missing, entire method won't be JIT'ed.
That includes any try/catch located in this method. Since try/catch never
JITed, exception won't be caught.

Samples to illustrate:

In that case exception won't be caught:

void foo () {
try {
object o = new MissingClass();
}
catch {
}
}

In that case exception will be caught:

void bar () {
try {
foo();
}
catch {
}
}

void foo () {
object o = new MissingClass();
}

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
Back
Top