System.AppDomainUnloadedException: Attempted to ac

System.AppDomainUnloadedException: Attempted to ac

Hello,

I'm currently having a problem when I run NCover from command line to perform coverage of my dll containing Unit Tests. Within this dll, I create and load a new .NET Application Domain (refer to the end of this post for the command issued).

If I do the same from within NCover-Explorer, all works fine! However, when it is run from command line using the command generated by the NCover-Explorer wizard, it generates an AppDomainUnloadedException exception at the end of the NCover processing. The situation is the same if I execute this as a MSBUILD task.

I have tried not to unload the AppDomain in my UnitTest dll. However, behaviour is the same.

Any help is more than welcome... :-)

José


C:\Documents and Settings\abc>"C:\Program Files\NCover\NCover.Console.exe" //reg //w "S:\ACFW_NET\trunk\MessageService\Workspace\bin\Debug" //v //l "Coverage.lo g" "S:\NUnit\ACFW_2.0__2.4.0.2\bin\nunit-console.exe" TR.ACFW_NET.MessageServiceUnitTest.dll NCover.Console v2.1.0 (Administrator x86) - Code Coverage Analysis for .NET Copyright (c) 2008 Gnoso Inc. http://www.ncover.com

Registered to Customer #: 11769 NCover Enterprise Edition (1 User)

Command: S:\NUnit\ACFW_2.0__2.4.0.2\bin\nunit-console.exe Command Args: "TR.ACFW_NET.MessageServiceUnitTest.dll" Working Directory: S:\ACFW_NET\trunk\MessageService\Workspace\bin\Debug Assemblies:

Program Output NUnit version 2.4.0 Copyright (C) 2002-2007 Charlie Poole. Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. Copyright (C) 2000-2002 Philip Craig. All Rights Reserved.

Runtime Environment - OS Version: Microsoft Windows NT 5.1.2600 Service Pack 2 CLR Version: 2.0.50727.1433 ( Net 2.0.50727.1433 )

........................................ Tests run: 41, Failures: 0, Not run: 0, Time: 171.688 seconds

Unhandled exceptions: 1) : System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain. End Program Output

Execution Time: 00:02:55s Sequence Point Coverage: 52.9% Branch Coverage: 48.7%

Coverage Xml: C:\Documents and Settings\acs\Coverage.Xml Coverage Log: C:\Documents and Settings\acs\Coverage.log


RE: System.AppDomainUnloadedException: Attempted to ac

it looks like you're getting coverage though. Can you get Nunit to show you a stack-trace for the unhandled exception?

Stephen


RE: System.AppDomainUnloadedException: Attempted to ac

Thanks for your quick response.

In fact, I was not too sure how to let Nunit to show me the stack of unhandled exception. Therfore, I installed 3 event handlers: AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); _otherAppDomain.UnhandledException += new UnhandledExceptionEventHandler(SecondDomain_UnhandledException); System.Windows.Forms.Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

Within these handlers, I issued some console.writeline(). However, nothing has been written.

What I should also add is that I use NCover as a msbuild task within my continuous integration process. Due to this error, an error code of 2 is returned and the NCover task is considered as failed.

Also notice that it works if it is run from within Ncover-Explorer (I mean that the report is seen and no such error is notified).

José


RE: System.AppDomainUnloadedException: Attempted to ac

yeah, the exception handlers didn't work b/c Nunit installs its own handlers before yours and they mark the exception as handled. You might be able to prevent that by setting the exception handlers to null before you add your own, but no guarantees.

I am emailing you a special build of Nunit 2.4.6 that will print out a stack trace for each exception it encounters.

Stephen


RE: System.AppDomainUnloadedException: Attempted to ac

Hi, I tried assigning it to Null. However, as I thought, it does not compile. The solution would be to play with reflection. This will be my next step if the modified version of NUnit could not point the problem. By the way, I have checked my email and have not received the file so far.

Thanks, José


RE: System.AppDomainUnloadedException: Attempted to ac

I have re-sent the email


RE: System.AppDomainUnloadedException: Attempted to ac

Hello, I tried you amended version and could not see more details.

I also did some more experiments: 1) within the small executable call the Setup(), Tests() and TearDown(). This was executed without problem and no exception was thrown.

2) Run NUnit.exe (from the zip you sent me). Using this program, the tests are considered as successfull. however, in the "Error and Failure" tab, the following message is shown: TR.ACFW_NET.MessageService.UnitTest.ControllerAlarmingUnitTests.TestSendingMappedAlarmsThatTranslateAndCombine: An unhandled System.AppDomainUnloadedException was thrown while executing this test : Attempted to access an unloaded AppDomain.

3) Tried to enable the log4net appender as defined in nunit.exe.config -> no extra information.

José


RE: System.AppDomainUnloadedException: Attempted to ac

in the trace monitor, are you seeing a line line:

"Unhandled exceptions : "

and if so, what value is after that string?


RE: System.AppDomainUnloadedException: Attempted to ac

also, would it be possible for you to send me the complete Trace output from a failing run? just email it to support at gnoso dot com.


RE: System.AppDomainUnloadedException: Attempted to ac

Hello, I sent you the information at the requested email address

José