471,594 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

.Net 2.0 runtime error, Event id: 5000

Hi,
I have made some software that uses one of the COM ports to
communicate with an external device. The software is written in C# and
uses the new SerialPort class in .Net 2.0.
It works perfectly when I use the COM ports that are integrated in my
PC. It also works if I use a COM->RS232 converter as long as I don't
unplug the converter when the software is running. If I unplug the
converter I get a .Net runtime 2.0 error:
http://therkelsen.info/images/blandet/atrack_prob.JPG

This error makes the .Net runtime environment shut down my software
and it seems like there is nothing I can do about it. I can not catch
the "objectDisposedException" because it is thrown inside the .Net
environment and makes the environment crash.
Any ideas about what I can do to stop the framework from crashing?
Is this a known bug in the .Net framework?

Best regards,
Kim Therkelsen

Feb 8 '07 #1
5 19362
In .NET 2.0, if there is an unhandled exception in your code, the appDomain
unloads, and "That's the end of that". What you need to do is provide robust
exception handling code in all the places needed to avoid this.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"ki***********@gmail.com" wrote:
Hi,
I have made some software that uses one of the COM ports to
communicate with an external device. The software is written in C# and
uses the new SerialPort class in .Net 2.0.
It works perfectly when I use the COM ports that are integrated in my
PC. It also works if I use a COM->RS232 converter as long as I don't
unplug the converter when the software is running. If I unplug the
converter I get a .Net runtime 2.0 error:
http://therkelsen.info/images/blandet/atrack_prob.JPG

This error makes the .Net runtime environment shut down my software
and it seems like there is nothing I can do about it. I can not catch
the "objectDisposedException" because it is thrown inside the .Net
environment and makes the environment crash.
Any ideas about what I can do to stop the framework from crashing?
Is this a known bug in the .Net framework?

Best regards,
Kim Therkelsen

Feb 8 '07 #2
The problem is that the exception can not be caught inside my code -
it is internally in the .Net framework!
And when the .Net Framework "brakes down" it also kills my software.
In fact if I do not press the "Ok" button my software just continues
to run in the background and still works as intended.
In more detail the problem is that I keep trying to write to the port
even though the port has disappeared (USB converter has been
unplugged) - but I am not able to detect exactly when the port
disappears inside the code. Therefore I have a try-catch around this
section but it is unable to catch the objectDisposedException which I
believe i generated internally in the .Net Framework and not caught
where it should have been caught.

Kim

On Feb 8, 5:38 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
In .NET 2.0, if there is an unhandled exception in your code, the appDomain
unloads, and "That's the end of that". What you need to do is provide robust
exception handling code in all the places needed to avoid this.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

"kimtherkel...@gmail.com" wrote:
Hi,
I have made some software that uses one of the COM ports to
communicate with an external device. The software is written in C# and
uses the new SerialPort class in .Net 2.0.
It works perfectly when I use the COM ports that are integrated in my
PC. It also works if I use a COM->RS232 converter as long as I don't
unplug the converter when the software is running. If I unplug the
converter I get a .Net runtime 2.0 error:
http://therkelsen.info/images/blandet/atrack_prob.JPG
This error makes the .Net runtime environment shut down my software
and it seems like there is nothing I can do about it. I can not catch
the "objectDisposedException" because it is thrown inside the .Net
environment and makes the environment crash.
Any ideas about what I can do to stop the framework from crashing?
Is this a known bug in the .Net framework?
Best regards,
Kim Therkelsen
Feb 8 '07 #3
Hi Kim,
Therefore I have a try-catch around this
section but it is unable to catch the objectDisposedException which I
believe i generated internally in the .Net Framework and not caught
where it should have been caught.
I suspect you may be correct about this. There is an unfortunate change of
behaviour in the 2.0 framework which kills the app if a thread has an
unhandled exception instead of just quietly killing the thread. This is all
very fine in theory if it is *your* code but if it is a third party
component or perhaps even the framework itself then life gets very
difficult. You can get around this behaviour with an app config file
containing this:
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<runtime>

<legacyUnhandledExceptionPolicy enabled="true" />

</runtime>

</configuration>

Save it in the same directory as your app and call it something like
myApp.exe.config.
This *is* a kludge - there is no guarantee that the component code will
behave correctly in this situation but its worth a try. If it does work you
will then need to find some way of detecting that the event has happened.
Good luck.

Cheers
Doug Forster
Feb 8 '07 #4
Nice, Doug.
Forgot about that - glad you reminded.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Doug Forster" wrote:
Hi Kim,
Therefore I have a try-catch around this
section but it is unable to catch the objectDisposedException which I
believe i generated internally in the .Net Framework and not caught
where it should have been caught.

I suspect you may be correct about this. There is an unfortunate change of
behaviour in the 2.0 framework which kills the app if a thread has an
unhandled exception instead of just quietly killing the thread. This is all
very fine in theory if it is *your* code but if it is a third party
component or perhaps even the framework itself then life gets very
difficult. You can get around this behaviour with an app config file
containing this:
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<runtime>

<legacyUnhandledExceptionPolicy enabled="true" />

</runtime>

</configuration>

Save it in the same directory as your app and call it something like
myApp.exe.config.
This *is* a kludge - there is no guarantee that the component code will
behave correctly in this situation but its worth a try. If it does work you
will then need to find some way of detecting that the event has happened.
Good luck.

Cheers
Doug Forster
Feb 9 '07 #5
Thanks Doug!

That stopped the .Net Framework from shutting down the application and
the application keeps working as it should - I can run the scenario
over and over again and it keeps working.

It is quite difficult to detect that the COM port has disappeared.
That means I have to check if the COM port exists every time I want to
access it/every time when I want to read or write something.
Unfortunately there is nothing in the SerialPort class that can tell
if the port has been disposed except you can subscribe to an "port
disposed event" or I can use SerialPort.GetPortNames() and check if
the port is still in the list. But none of these things will really
solve the problem - the port could have been removed right after I had
done the check and was going to write to the port.

Best regards,
Kim Therkelsen

On 8 Feb., 20:57, "Doug Forster"
<doug_ZAPTHIS_AT_ZAPTHIS_TONIQ_DOT_CO_DOT_NZwrot e:
HiKim,
Therefore I have a try-catch around this
section but it is unable to catch the objectDisposedException which I
believe i generated internally in the .Net Framework and not caught
where it should have been caught.

I suspect you may be correct about this. There is an unfortunate change of
behaviour in the 2.0 framework which kills the app if a thread has an
unhandled exception instead of just quietly killing the thread. This is all
very fine in theory if it is *your* code but if it is a third party
component or perhaps even the framework itself then life gets very
difficult. You can get around this behaviour with an app config file
containing this:
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<runtime>

<legacyUnhandledExceptionPolicy enabled="true" />

</runtime>

</configuration>

Save it in the same directory as your app and call it something like
myApp.exe.config.
This *is* a kludge - there is no guarantee that the component code will
behave correctly in this situation but its worth a try. If it does work you
will then need to find some way of detecting that the event has happened.
Good luck.

Cheers
Doug Forster

Feb 11 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Aleks A. | last post: by
reply views Thread by raagzcd | last post: by
4 posts views Thread by news.citenet.net | last post: by
reply views Thread by kimtherkelsen | last post: by
4 posts views Thread by Bernard Borsu | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

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.