Missing .NET and Exceptions

J

John Bowman

Hi All,

I've been reading about Application.ThreadException,
Application.SetUnhandledExceptionMode &
AppDomain,CurrentDomain.UnhandledException. I'm trying to determine if there
is a mechanism where if the .NET framework is missing, is there any way at
all to gracefully catch it in my code and inform the user of what's wrong.
Is this even possible? If so, how can I catch it and nicely inform the user
of the problem - Microsoft's "The application failed to initialize
properly..." message is basically useless to a user. If it's even possible &
anyone has any code to share, I'd be much appreciative.

TIA,

--
John C. Bowman
Software Engineer II
Thermo Fisher Scientific
<Remove this before reply> (e-mail address removed)


WORLDWIDE CONFIDENTIALITY NOTE: Dissemination, distribution or copying of
this e-mail or the information herein by anyone other than the intended
recipient, or an employee or agent of a system responsible for delivering
the message to the intended recipient, is prohibited. If you are not the
intended recipient, please inform the sender and delete all copies.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Not, unfortunatelly all those events, classes, etc that you mention, well
they are part of the framework in tehr first place :)

You would have to create an unmanaged process to detect the presence of the
framework.

Or convince MS to create another message :D
 
N

Nicholas Paldino [.NET/C# MVP]

John,

It's impossible, since the code you would write is managed code, and
without the framework installed, managed code won't run.

You would have to create an unmanaged stub to check for the existence of
the framework, and then show the appropriate message if it is not installed.
If it is, then you would just create a new process and run your managed
executable then.
 
J

John Bowman

Ignacio & Nicholas,

Thanks for the info. That's what I suspected. Unfortunately, the case in
question is a setup/installation like process that already has a stub
written in C++ that does exactly that, once the framework is installed, then
the stub runs the main C# .exe program. Unfortunately, there's no way to
prevent the user from trying to run the main .exe program directly w/o the
stub 1st. If the user does this, then they crash and have no idea why
because the message is "engineerese". What's really needed is the loader's
crash message to be more usfully informative to the average non-engineer
user, or the ability to substitute your own graceful message into the loader
in the event the proper .NET framework is not present.

John

Nicholas Paldino said:
John,

It's impossible, since the code you would write is managed code, and
without the framework installed, managed code won't run.

You would have to create an unmanaged stub to check for the existence
of the framework, and then show the appropriate message if it is not
installed. If it is, then you would just create a new process and run your
managed executable then.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

John Bowman [email protected]> said:
Hi All,

I've been reading about Application.ThreadException,
Application.SetUnhandledExceptionMode &
AppDomain,CurrentDomain.UnhandledException. I'm trying to determine if
there is a mechanism where if the .NET framework is missing, is there any
way at all to gracefully catch it in my code and inform the user of
what's wrong. Is this even possible? If so, how can I catch it and nicely
inform the user of the problem - Microsoft's "The application failed to
initialize properly..." message is basically useless to a user. If it's
even possible & anyone has any code to share, I'd be much appreciative.

TIA,

--
John C. Bowman
Software Engineer II
Thermo Fisher Scientific
<Remove this before reply> (e-mail address removed)


WORLDWIDE CONFIDENTIALITY NOTE: Dissemination, distribution or copying of
this e-mail or the information herein by anyone other than the intended
recipient, or an employee or agent of a system responsible for delivering
the message to the intended recipient, is prohibited. If you are not the
intended recipient, please inform the sender and delete all copies.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

John Bowman [email protected]> said:
Ignacio & Nicholas,

Thanks for the info. That's what I suspected. Unfortunately, the case in
question is a setup/installation like process that already has a stub
written in C++ that does exactly that, once the framework is installed,
then the stub runs the main C# .exe program. Unfortunately, there's no way
to prevent the user from trying to run the main .exe program directly w/o
the stub 1st. If the user does this, then they crash and have no idea why
because the message is "engineerese". What's really needed is the loader's
crash message to be more usfully informative to the average non-engineer
user, or the ability to substitute your own graceful message into the
loader in the event the proper .NET framework is not present.

What if you rename your managed EXE to some other extension , like _EX. in
this way t will not be executed.

As a step in your install process you can rename it back to the correct
extension.
 
J

John Bowman

Ignacio,

Thanks for the idea, but that won't work either because it's distributed on
a CD/DVD - so renaming it as part of hte install process is not an option.
However, this does give me an idea I hadn'tr considered before. I wonder if
the CreateProcess Win32 API method which is used in the stub to launch the
..NET .EXE can handle something that's not named .EXE? I've never
tried/thhought of that. If so, then I could rename the .NET .EXE and the
user could never double click it & try to run it directly. But the stub
could then successfully launch it. I'll have to look into this possibility.
A quick look at the MSDN for CreateProcess doesn't really mention anything
directly, but it does mention the possibility of not having a file
extension.

Thanks!

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top