473,795 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unhandled Exception in Form Load in EXE but not in IDE

I have a weird error trapping problem. When running the IDE everything works
fine but not when running in an EXE I get the Unhandled Exception Error
message box intead of the one in my Try....Catch Block.

To see this create a simple application with two forms. Form 1 should have
one button. The code is follows. Run this in the IDE and observe the error
and then compare that behavior to what happens when you run the built EXE.

Has anyone seen this?

Thanks,

Mark

=============== =============== =============== ==

Public Class Form1

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim f As New Form2
Try

f.Show()

Catch ex As Exception

MessageBox.Show (ex.Message)
f.Dispose()

End Try
End Sub
End Class
Public Class Form2

Private Sub Form2_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Throw New ApplicationExce ption("error thrown in form2 load")

End Sub

End Class
Aug 7 '06 #1
15 2340
Hi Mark,

First, the fix to this issue is one of following options:
1) Create an application config file "app.config " for your project and edit:

<configuratio n>
<system.windows .forms jitDebugging="t rue" />
</configuration>

You need to release this <yourapp>.exe.c onfig file with your main app to
your user.

2) If your purpose of installing your own exception handler is to show the
exception, you don't have to. By default, WinForm has a built-in global
exception handler which will catch the exception and show the default
exception dialog. You can also customize this dialog:
http://samples.gotdotnet.com/quickst...FormsAppErrorH
andler.aspx

To understand the background of this issue, read along.

======

The built-in exception dialog is shown because the message pump exception
handler is working.

If you use Reflector to see the disassembled code of
System.Windows. Forms.NativeWin dow, you will see two private methods
"Callback" and "DebuggableCall back". In "Callback", we wrap the message
pump in an exception handler so that unhandled exception that gets as far
as the message pump does not actually unwind the message pump causing the
app to crash.

When an application is run in the debugger, we don't catch exceptions in
NativeWindow.De buggableCallbac k because we typically want the JIT debugger
to stop the app.

We believe that the behavior we have now represents the best possible ease
of use combined with flexibility -- if you do nothing your app won't crash
if you don't handle an exception, you can customize the dialog that gets
shown and you can turn off the behavior completely.

======

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

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

Aug 8 '06 #2
Thanks.

The App.config change fixed this. It would seem to be more of a bug than a
feature to me<g>.... that was with my old VB6 hat on..... I had found an
MSKB article that mentioned this but it
http://support.microsoft.com/?kbid=836674

Indicates that 2005 behaved differently. Perhaps that article should be
corrected to indicate the issue is with both 2003 and 2005.

By the way, is there any disadvantages of adding this JIT line to the config
in terms of security or performance?

Thanks again,

Mark
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:ra******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi Mark,

First, the fix to this issue is one of following options:
1) Create an application config file "app.config " for your project and
edit:

<configuratio n>
<system.windows .forms jitDebugging="t rue" />
</configuration>

You need to release this <yourapp>.exe.c onfig file with your main app to
your user.

2) If your purpose of installing your own exception handler is to show the
exception, you don't have to. By default, WinForm has a built-in global
exception handler which will catch the exception and show the default
exception dialog. You can also customize this dialog:
http://samples.gotdotnet.com/quickst...FormsAppErrorH
andler.aspx

To understand the background of this issue, read along.

======

The built-in exception dialog is shown because the message pump exception
handler is working.

If you use Reflector to see the disassembled code of
System.Windows. Forms.NativeWin dow, you will see two private methods
"Callback" and "DebuggableCall back". In "Callback", we wrap the message
pump in an exception handler so that unhandled exception that gets as far
as the message pump does not actually unwind the message pump causing the
app to crash.

When an application is run in the debugger, we don't catch exceptions in
NativeWindow.De buggableCallbac k because we typically want the JIT debugger
to stop the app.

We believe that the behavior we have now represents the best possible ease
of use combined with flexibility -- if you do nothing your app won't crash
if you don't handle an exception, you can customize the dialog that gets
shown and you can turn off the behavior completely.

======

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

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

Aug 8 '06 #3
Actually it did not fix the problem. My error in testing. Using the small
program mentioned below I added an app.config with these contents:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<system.windows .forms jitDebugging="t rue" />
</configuration>

The application behaves the same way with or without this line. I have
attached the source if that is of any help.

Any other ideas?

Thanks,

Mark

"Mark Lewis" <md*****@newsgr oups.nospamwrot e in message
news:Oq******** ******@TK2MSFTN GP04.phx.gbl...
Thanks.

The App.config change fixed this. It would seem to be more of a bug than a
feature to me<g>.... that was with my old VB6 hat on..... I had found an
MSKB article that mentioned this but it
http://support.microsoft.com/?kbid=836674

Indicates that 2005 behaved differently. Perhaps that article should be
corrected to indicate the issue is with both 2003 and 2005.

By the way, is there any disadvantages of adding this JIT line to the
config
in terms of security or performance?

Thanks again,

Mark
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:ra******** ******@TK2MSFTN GXA01.phx.gbl.. .
>Hi Mark,

First, the fix to this issue is one of following options:
1) Create an application config file "app.config " for your project and
edit:

<configuratio n>
<system.windows .forms jitDebugging="t rue" />
</configuration>

You need to release this <yourapp>.exe.c onfig file with your main app
to
your user.

2) If your purpose of installing your own exception handler is to show
the
exception, you don't have to. By default, WinForm has a built-in global
exception handler which will catch the exception and show the default
exception dialog. You can also customize this dialog:
http://samples.gotdotnet.com/quickst...FormsAppErrorH
andler.aspx

To understand the background of this issue, read along.

======

The built-in exception dialog is shown because the message pump exception
handler is working.

If you use Reflector to see the disassembled code of
System.Windows .Forms.NativeWi ndow, you will see two private methods
"Callback" and "DebuggableCall back". In "Callback", we wrap the message
pump in an exception handler so that unhandled exception that gets as far
as the message pump does not actually unwind the message pump causing the
app to crash.

When an application is run in the debugger, we don't catch exceptions in
NativeWindow.D ebuggableCallba ck because we typically want the JIT
debugger
to stop the app.

We believe that the behavior we have now represents the best possible
ease
of use combined with flexibility -- if you do nothing your app won't
crash
if you don't handle an exception, you can customize the dialog that gets
shown and you can turn off the behavior completely.

======

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

============== =============== =============== ======
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
============== =============== =============== ======

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


Aug 8 '06 #4
Hi Mark,

Thank you for your quick update.

App.config is added to your project, during runtime, it should have been
copied as <yourapp>.exe.c onfig, which the compiler should do that for you.
So, you need to make sure the config file is renamed as
<yourapp>.exe.c onfig and put to the same directory as <yourapp>.exe .

As for the KB, thank you for pointing out that it should state it applies
to Visual Studio 2005 too.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

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

Aug 9 '06 #5
Hi Mark,

How's my suggestion in my previous reply? Please feel free to post here if
anything is unclear.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

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

Aug 11 '06 #6
Thanks, it was clear. Sorry about my dealy getting back to you but I was
away for a few days.

I tried a config, properly named, with

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<system.windows .forms jitDebugging="t rue" />
</configuration>

It didn't make any difference on my machine or on two others we have tried.
Also tried removing the config and putting in a False instead of a True.

Mark
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:fp******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi Mark,

How's my suggestion in my previous reply? Please feel free to post here if
anything is unclear.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

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

Aug 14 '06 #7
One more thing. The config entry does fix the problem for EXE's built with
the default DEBUG options. It did not work, as I note below, for me when I
built a RELEASE Exe using the default options. Perhaps there is some
compiler option to set to work around this.

Thanks again for your help.

Mark

"Mark Lewis" <md*****@newsgr oups.nospamwrot e in message
news:el******** ******@TK2MSFTN GP02.phx.gbl...
Thanks, it was clear. Sorry about my dealy getting back to you but I was
away for a few days.

I tried a config, properly named, with

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<system.windows .forms jitDebugging="t rue" />
</configuration>

It didn't make any difference on my machine or on two others we have
tried. Also tried removing the config and putting in a False instead of a
True.

Mark
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:fp******** ******@TK2MSFTN GXA01.phx.gbl.. .
>Hi Mark,

How's my suggestion in my previous reply? Please feel free to post here
if
anything is unclear.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

============== =============== =============== ======
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============== =============== =============== ======

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


Aug 14 '06 #8
Hi Mark,

Have you got time to test the project I attached in my previous reply?
Please feel free to post here if you still have problem in Release mode.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

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

Aug 17 '06 #9
Walter,

Thanks. I have just tested that. I do see that your Button 1 works when the
Advanced Compile Time option is set to generate a PDB and the JIT line is
set in the config. If I turn off the generation of the PDB in release, as I
had in my project, then your project also fails on Button 1.

Naturally removing the JIT setting also causes your Release project to fail.

So to summarize.

1. the error is always trapped in the IDE
2. Builds either in Debug or Release mode that have the JIT setting and
build PDB files trap the error in the same manner as the IDE.
3. Builds in Release mode without PDB generation and the JIT setting do not
trap the error.
4. If I build in Release mode with JIT and tell the app to generate the
PDB..then delete it...the app does trap the error.

I would not want to ship my release with a PDB file but we might consider
shipping without one - Option 4 above.

A bit of a mystery.

Mark

"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:wO******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi Mark,

Have you got time to test the project I attached in my previous reply?
Please feel free to post here if you still have problem in Release mode.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

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

Aug 17 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
536
by: Rafael | last post by:
Hi, I hope I can find some help for this problem IDE: Visual Studio.NET 2003 Developer Editio Language: C# Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll. Additional information: Object reference not set to an instance of an object. Visual Studio's IDE is not allowing me to develop projects in C#... I've trying to create a simple Windows Forms project using Visual Studio.NET...
7
2707
by: Chuck Hartman | last post by:
I have a Windows service that requests web pages from a site using an HttpWebRequest object. When I try to request a page from an ASP.NET 2 site, I get a WebException with message "The remote server returned an error: (500) Internal Server Error." I found a post that suggested to catch the WebException to retrieve the actual HttpWebResponse object for more information. The response returned is shown below. At first I thought this was a...
1
2105
by: mike | last post by:
My program is crashing, but it doesn't crash on a single line of code. Below is what the output tab displays. I have no idea where to start inorder to debug this problem. Is there any suggesstions on how to start debuging the problem 'DefaultDomain': Loaded 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols loaded 'StoredProcedure': Loaded 'N:\Dev\Programs\MNTEST3.net\Template.NET\bin\StoredProcedure.exe', No symbols...
5
5751
by: Lucvdv | last post by:
Can someone explain why this code pops up a messagebox saying the ThreadAbortException wasn't handled? The first exception is reported only in the debug pane, as expected. The second (caused by thread.Abort()) is reported twice: once in the debug window, and once through the message box. Is it because the thread was sleeping when the exception occurred?
5
4544
by: Sam Loveridge | last post by:
Hi All. I'm hoping someone can point me in the direction of a solution to unhandled exceptions in MDI child forms causing the application to crash. I've found various articles describing a method using Application.Run(new MyMainParentForm) to place in the application's Sub Main to allow catching of unhandled exceptions in the application. The problem I'm facing is that I want to be able to trap unhandled exceptions at the MDI child...
0
1991
by: Colmeister | last post by:
I recently read Jason Clark's excellent article on Unhandled Exceptions (http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx) and have attempted to incorporate the features he talks about in a new application I'm writing. However, when I try to use ThreadStart to do some work in a separate thread from my GUI, the methods Jason described don't seem to catch the exception. Take the following source code: Public Class...
5
3404
by: Simon Tamman {Uchiha Jax} | last post by:
Now this is bugging me. I just released software for a client and they have reported an unhandled stack overflow exception. My first concern is that the entirity of the UI and any threaded operations are all within Try Catches to help me locate the problem and the origination of any problem by specifiying an error code in the "Catch" section. So theoretically this shouldn't have been possible (at which point we all say "yeah,...
6
1671
by: Viktar Zhardzetski | last post by:
Hi everybody, let me start with a simple sample to replicate the problem: 1. Create a new Windows Application C# project with 2 forms - MainForm and FaultyForm; 2. In the faulty form override the OnLoad method to throw an exception: public partial class FaultyForm : Form ...
5
3212
lotus18
by: lotus18 | last post by:
WaAh! My form was working fine earlier but later it displays Invalid Operation Exception was unhandled. I don't know what's wrong with my form every time I load it.I checked its codes but I find what's wrong with it. If I'm going to remove Transaction.Courses.Show(False, txtSearch.Text) at line #2 of frmCourses it works fine. Of course I cannot filter the records : ( This is my sample codes clsCourses
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.