Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2006

Tip: Looking for answers? Try searching our database.

Catching unhandled exceptions in the finalizer under .NET 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stefan Kühnel - 24 Oct 2006 11:24 GMT
Hi!

We're having a problem with converting a program from .NET 1.1 to .NET
2.0. The program is kind of an AppServer (which can run as NT service or
as a console application), where we don't control which applications are
run inside it. Now we have a problem with one application which uses a
third party library and this library causes an unhandled exception in a
finalizer. This then brings down the whole server.

The cause of this is the different treatment of unhandled exceptions in
.NET 2.0 (http://msdn2.microsoft.com/en-us/library/ms228965.aspx). We
could work around this problem by setting the application compatibility
flag <legacyUnhandledExceptionPolicy enabled="1"/>. But I was wondering
if there is a better way to deal with this?

Thanks for any insight,
Stefan
Dave Sexton - 24 Oct 2006 16:33 GMT
Hi Stefan,

Try calling GC.SuppressFinalize on the incriminating object.  If that's too
much of a pain because you are constantly constructing new instances then
create a class factory.

Signature

Dave Sexton

> Hi!
>
[quoted text clipped - 13 lines]
> Thanks for any insight,
> Stefan
Stefan Kühnel - 25 Oct 2006 10:29 GMT
Hi Dave,

> Try calling GC.SuppressFinalize on the incriminating object.  If that's too
> much of a pain because you are constantly constructing new instances then
> create a class factory.

since we're not controlling the creation of those objects in any way,
this is nothing we can do.

Since we need to have a solution that works independent of any
particular application and we don't know in advance if the objects of
any particular class have a buggy finalizer, I think all solutions based
on modifying the creation won't work.

Thanks anyway,
Stefan
David Levine - 24 Oct 2006 20:38 GMT
Can you contact the author/vendor and have them fix the problem? That is the
easiest and best way to fix the problem.

There are some extreme measures you could use but they are non-trivial. You
could host the runtime yourself and set your own policy. You could
diassemble the offending library using ILDASM, fix the bug yourself in IL,
and then reassemble it using ILASM. There are other measures but I don't
recommend it for production code (e.g. use the profiling API to watch
for/deal with exceptions before the runtime escalates it to a UE, or even
dynamically rewrite the code on the fly).

These are probably not worth the effort - the legacy workaround is easier
and less error prone.

> Hi!
>
[quoted text clipped - 13 lines]
> Thanks for any insight,
> Stefan
Stefan Kühnel - 25 Oct 2006 10:35 GMT
Hi David,

> Can you contact the author/vendor and have them fix the problem? That is the
> easiest and best way to fix the problem.

Certainly, but since we already have a version out and we need to be
backward compatible, this is sadly not an option.

> There are some extreme measures you could use but they are non-trivial. You
> could host the runtime yourself and set your own policy.

Yes, this seems from all I can tell the only viable if nontrivial
alternative. Do you have a good reference for this?

> You could
> diassemble the offending library using ILDASM, fix the bug yourself in IL,
> and then reassemble it using ILASM.

This would work only for the one known offender, but is not a general
solution, so sadly not an option either.

> There are other measures but I don't
> recommend it for production code (e.g. use the profiling API to watch
> for/deal with exceptions before the runtime escalates it to a UE, or even
> dynamically rewrite the code on the fly).

Haven't thought of these but then I'd rather do the hosting. ;-)

> These are probably not worth the effort - the legacy workaround is easier
> and less error prone.

Yes, that's probably the way we go for the moment, even though it is not
really satisfactory.

Thanks a lot,
Stefan
David Levine - 26 Oct 2006 02:12 GMT
> Hi David,
>
[quoted text clipped - 11 lines]
> Yes, this seems from all I can tell the only viable if nontrivial
> alternative. Do you have a good reference for this?

There's a book written by Steven Pratschner.called Customizing the .NET
Runtime,
http://www.amazon.com/Customizing-Microsoft-Framework-Pro-Developer-Paperback/dp
/0735619883

Great book, gets into all the low-level APIs used to take control over the
runtime.

He also authored this article:
http://msdn.microsoft.com/msdnmag/issues/01/03/clr/

I found this link but I have not evaluated it....
http://www.codeproject.com/dotnet/simpleclrhost.asp
Stefan Kühnel - 31 Oct 2006 11:46 GMT
Hi David,

> >> There are some extreme measures you could use but they are non-trivial.
> >> You
[quoted text clipped - 14 lines]
> I found this link but I have not evaluated it....
> http://www.codeproject.com/dotnet/simpleclrhost.asp

Thanks a lot for those references. Will look into those for a future
release.

Stefan

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.