Keyboard.AbortKey and System.AppDomainUnloadedExcepti

Class library usage, coding and language questions.
JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Keyboard.AbortKey and System.AppDomainUnloadedExcepti

Post by JSH_QA » Tue Oct 21, 2014 10:59 am

In our coded tests, if we set Keyboard.AbortKey, a System.AppDomainUnloadedException is reported when the test completes.

We set the key using:
Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;

And this is what is recorded:
System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain. This can happen if the test(s) started a thread but did not stop it. Make sure that all the threads started by the test(s) are stopped before completion.

Is there any way of preventing this exception, whilst still setting AbortKey ?

Thanks,

John H.

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Keyboard.AbortKey and System.AppDomainUnloadedExcepti

Post by JSH_QA » Tue Oct 21, 2014 12:51 pm

Interestingly, use of the following also results in the same exception:

IList<Form> forms = Host.Local.Find<Form>(String.Format("/form[@processname='{0}']", processName));

Whilst the exception is not causing any major problems, it does generate noise that distracts from failures in the code under test.

Any ideas?

Thanks,

John H.

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Keyboard.AbortKey and System.AppDomainUnloadedExcepti

Post by JSH_QA » Tue Oct 21, 2014 11:24 pm

I should add that we run our coded Ranorex tests as MSTest tests, using TestInitialize to ensure a known state before each test and TestCleanup to tidy up afterwards.

Regards,

John H

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Keyboard.AbortKey and System.AppDomainUnloadedExcepti

Post by Support Team » Thu Oct 23, 2014 12:16 pm

Hi John,

Unfortunately I was not able to reproduce this exception on my machine.
May I ask you to provide us a sample solution in which this problem occurs?

If you don’t want to post the solution in this public forum you can send it to [email protected]
Thank you in advance.

Regards,
Markus (S)
.
Image

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Keyboard.AbortKey and System.AppDomainUnloadedExcepti

Post by JSH_QA » Wed Oct 29, 2014 2:07 pm

Hi Markus,

My understanding of that exception suggests that within the Ranorex libraries, one or more threads are being started, but they are not ending. As a result, as we run our tests from MSTest, MSTest detects that there are threads still running at the end of a test, and generates that exception.

So, the question is - is there any way that in TestCleanup (where cleanup code is placed for MSTest tests), we can tell the Ranorex libraries that we are finished with them and that they should end any threads that they started? What we need is something skin to Ranorex.Shutdown or Ranorex.End.

Thanks,

John H.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Keyboard.AbortKey and System.AppDomainUnloadedExcepti

Post by Support Team » Wed Nov 05, 2014 3:12 pm

Hi Josh,

Ranorex does not start any threads which are not closed at the end. May I ask you, if you have started an additional thread? For example: a PopupWatcher?
May I also ask you to provide a small sample of your test where this exception occurs.

Additionally: Please let me know which version of Ranorex is currently installed on your system.

This will help us to analyze the issue in more detail.

regards,
Markus(S)
.
Image

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Keyboard.AbortKey and System.AppDomainUnloadedExcepti

Post by JSH_QA » Wed Nov 05, 2014 3:23 pm

Hi Markus,

Whilst we do normally have a PopupWatcher in use, we still see this exception being reported if the PopupWatcher code is completely removed.

I'll put together a small piece of code to demo the problem.

Thanks,

John H

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Keyboard.AbortKey and System.AppDomainUnloadedExcepti

Post by JSH_QA » Wed Nov 05, 2014 3:32 pm

Hi Markus,

Here you go. The following results in the error appearing, using 5.1.1.18898:

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DemoOfExceptionForRanorex
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
Ranorex.Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
}
}
}

If I remove the line setting AbortKey, then the exception no longer happens.

Regards,

John H.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Keyboard.AbortKey and System.AppDomainUnloadedExcepti

Post by Support Team » Tue Nov 11, 2014 1:42 pm

Hi John,

Sorry for the slow response. I tried several times to reproduce this issue.

I regret to inform you that I was not able to reproduce the problem on our side.
Please find below two screenshots, where you can see that the code works as expected.
Code.png
Code.png (11.05 KiB) Viewed 1523 times
Result.png
Result.png (4.88 KiB) Viewed 1523 times
Unfortunately, it seems that this problem is not related to Ranorex. May I ask you to have a look at this entry on the MSDN forum

Regards,
Markus (S)
.
Image

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Keyboard.AbortKey and System.AppDomainUnloadedExcepti

Post by JSH_QA » Tue Nov 11, 2014 3:00 pm

Hi Markus,

Thanks for your response.

Using the Threads window when debugging in Visual Studio, I see that the following three threads are started when I set Keyboard.AbortKey:

Ranorex.Core.dll!Ranorex.Core.InputDispatcher.DispatcherThread
Ranorex.Core.dll!Ranorex.Core.InputDispatcher.RegeneratorThread
Ranorex.Core.dll!WinApi.dll!Ranorex.Core.WinApi.Hooks.MessageLoop

Is there any way that tests can cleanly exit these threads, perhaps a Shutdown or Cleanup type method in the Ranorex API?

I assume that the test runner is reporting the exception mentioned before as a result of these threads being started during a test, but at least one of them not being closed at the end of the test.

Thanks again,

John H.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Keyboard.AbortKey and System.AppDomainUnloadedExcepti

Post by Support Team » Fri Nov 14, 2014 1:20 pm

Hi John,

Thank you for the response.

Unfortunately we were still not able to reproduce this System.AppDomainUnloadedException.

May I ask you to contact us by email to handle this problem personally with us?

Thank you for your understanding and your patience.

Regards,
Markus (S)
.
Image