Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Tests that require TestIsolation in new AppDomain
GibSral
#1 Posted : Tuesday, June 2, 2020 10:49:18 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/1/2014(UTC)
Posts: 27
Location: Germany

Thanks: 3 times
Was thanked: 3 time(s) in 3 post(s)
Hi,

i have to isolate some tests in a new AppDomain.
I followed the instructions on https://www.ncrunch.net/...ld-their-own-appdomains

In my code and in the provided sample i get a StackoverflowException when calling runCodeInReferencedAssembly();
It even does not enter the method.
I am in a new project and we are using msbuild 1 at the moment (working on it to be replaced with at least version 2 or nunit/xunit).

I just tested it with the current nunit resuling in the same behavior.

Of course i could just enable "copy refrenced assemblies" but the build times are already very long due to large projects (also working on it :) )

Is there any solution for my problem?

Thanks in advance
Lars
Remco
#2 Posted : Tuesday, June 2, 2020 11:09:43 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi Lars,

Is there any chance you could share the stack trace and a code sample?
GibSral
#3 Posted : Monday, June 8, 2020 9:00:42 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/1/2014(UTC)
Posts: 27
Location: Germany

Thanks: 3 times
Was thanked: 3 time(s) in 3 post(s)
Hi,

of course. But not much information there :)
I can send you a test project (seems I cannot upload it here?) but I simply used the sample code provided in your documentation: https://www.ncrunch.net/...ld-their-own-appdomains

System.StackOverflowException
HResult=0x800703E9
Message=Exception of type 'System.StackOverflowException' was thrown.

[External Code]
> NcrunchCrossDomainTests.dll!NcrunchCrossDomainTests.ClassInApplicationDomain.RunCodeInApplicationDomain() Line 58 C#
[External Code]
NcrunchCrossDomainTests.dll!NcrunchCrossDomainTests.AppDomainTest.TestThatCreatesAnApplicationDomainIncludingAReferencedAssembly() Line 42 C#
[External Code]

Remco
#4 Posted : Monday, June 8, 2020 10:04:17 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
Do you have the sample in a project that compiles for you? If you can submit it through the NCrunch contact form, I should hopefully be able to get to the bottom of this quickly. It's been quite a while since I wrote the code sample you've quoted in the documentation, but I was fairly certain it worked when I wrote it.
GibSral
#5 Posted : Monday, June 8, 2020 12:01:16 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/1/2014(UTC)
Posts: 27
Location: Germany

Thanks: 3 times
Was thanked: 3 time(s) in 3 post(s)
I just sent you the vs solution via the contact form. Used the ThreadName as Title.
Remco
#6 Posted : Tuesday, June 9, 2020 12:33:34 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
Thanks for sending this through. The code you submitted gave an interesting result on my end... It seems to work without throwing a stack overflow.

I think the cause of this might be something related to the assembly resolution logic in your environment. Perhaps there is a recursive loop happening in the custom assembly resolver.

Do you still experience the problem if you set the 'Instrument output assembly' NCrunch setting to 'False' for the project?
GibSral
#7 Posted : Thursday, June 11, 2020 6:47:30 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/1/2014(UTC)
Posts: 27
Location: Germany

Thanks: 3 times
Was thanked: 3 time(s) in 3 post(s)
unfortunately disabling instrumentation does not solve the problem
Remco
#8 Posted : Friday, June 12, 2020 6:14:21 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
GibSral;14793 wrote:
unfortunately disabling instrumentation does not solve the problem


Can the test run on your machine using a different test runner? (i.e. VSTest)
GibSral
#9 Posted : Friday, June 12, 2020 12:19:05 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/1/2014(UTC)
Posts: 27
Location: Germany

Thanks: 3 times
Was thanked: 3 time(s) in 3 post(s)
Remco;14794 wrote:
GibSral;14793 wrote:
unfortunately disabling instrumentation does not solve the problem


Can the test run on your machine using a different test runner? (i.e. VSTest)


The test runs fine with the Resharper TestRunner
GibSral
#10 Posted : Friday, June 12, 2020 12:36:43 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/1/2014(UTC)
Posts: 27
Location: Germany

Thanks: 3 times
Was thanked: 3 time(s) in 3 post(s)
It seems that the runtime cannot find ncrunch.framework.dll that i had to add as a reference to enable this.
Here is the fuslog binding error.

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable c:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\extensions\remco software\ncrunch for visual studio 2019\nCrunch.TestHost48.x86.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = NCrunch.Framework, Version=4.0.0.1, Culture=neutral, PublicKeyToken=01d101bf6f3e0aea
(Fully-specified)
LOG: Appbase = file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Application
Calling assembly : NcrunchCrossDomainTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\extensions\remco software\ncrunch for visual studio 2019\nCrunch.TestHost48.x86.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: NCrunch.Framework, Version=4.0.0.1, Culture=neutral, PublicKeyToken=01d101bf6f3e0aea
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug/NCrunch.Framework.DLL.
LOG: Attempting download of new URL file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug/NCrunch.Framework/NCrunch.Framework.DLL.
LOG: Attempting download of new URL file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug/NCrunch.Framework.EXE.
LOG: Attempting download of new URL file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug/NCrunch.Framework/NCrunch.Framework.EXE.
LOG: All probing URLs attempted and failed.


The Test-project has this as a nuget package reference
GibSral
#11 Posted : Friday, June 12, 2020 12:40:22 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/1/2014(UTC)
Posts: 27
Location: Germany

Thanks: 3 times
Was thanked: 3 time(s) in 3 post(s)
Additional Entries in the fuslog:

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable c:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\extensions\remco software\ncrunch for visual studio 2019\nCrunch.TestHost48.x86.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb
(Fully-specified)
LOG: Appbase = file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Application
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Download of application configuration file was attempted from file:///c:/program files (x86)/microsoft visual studio/2019/professional/common7/ide/extensions/remco software/ncrunch for visual studio 2019/nCrunch.TestHost48.x86.exe.Config.
LOG: Found application configuration file (c:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\extensions\remco software\ncrunch for visual studio 2019\nCrunch.TestHost48.x86.exe.Config).
LOG: Using application configuration file: c:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\extensions\remco software\ncrunch for visual studio 2019\nCrunch.TestHost48.x86.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug/nunit.framework.DLL.
LOG: Attempting download of new URL file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug/nunit.framework/nunit.framework.DLL.
LOG: Attempting download of new URL file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug/nunit.framework.EXE.
LOG: Attempting download of new URL file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug/nunit.framework/nunit.framework.EXE.
LOG: All probing URLs attempted and failed.



*** Assembly Binder Log Entry (12.06.2020 @ 14:34:06) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable c:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\extensions\remco software\ncrunch for visual studio 2019\nCrunch.TestHost48.x86.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = ClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Application
Calling assembly : NcrunchCrossDomainTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\extensions\remco software\ncrunch for visual studio 2019\nCrunch.TestHost48.x86.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug/ClassLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug/ClassLibrary/ClassLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug/ClassLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/lbaldes/AppData/Local/NCrunch/37588/13/NcrunchCrossDomainTests/bin/Debug/ClassLibrary/ClassLibrary.EXE.
LOG: All probing URLs attempted and failed.
GibSral
#12 Posted : Friday, June 12, 2020 12:46:08 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/1/2014(UTC)
Posts: 27
Location: Germany

Thanks: 3 times
Was thanked: 3 time(s) in 3 post(s)
When i instrument the AssemblyResolver with exceptions (Debug.Writeline does not seem to work cross appdomain) I can see that the foreach loop does not get executed.
If i place exceptions above the loop the coverage indicator shows the exception as a cross.
Exception inside or after the loop get ignored. It seems to me that NCrunch.Framework.NCrunchEnvironment.GetAllAssemblyLocations() throws an exception while trying to load the assembly (see first fuslog entry) and that causes a neverending ResolveAssembly-Loop?
Remco
#13 Posted : Saturday, June 13, 2020 12:25:02 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
Thanks for the extra details. This is making sense now.

It seems this code requires the referenced version of NCrunch.Framework DLL to be installed in the GAC. In most cases, this is a safe assumption, as NCrunch automatically installs this DLL into the GAC during installation. I guess in this case because the DLL is being referenced via Nuget, it has been possible for you to tie into a version of the assembly that does not exist in your GAC.

There's a couple of ways you can solve this. The first and easiest way is to make sure you reference the version of NCrunch.Framework that is consistent with the one you have installed in your GAC.

The second option is to make the call to NCrunch.Framework.NCrunchEnvironment.GetAllAssemblyLocations() outside the constructed appdomain and pass the resulting value directly into the unwrapped type inside the appdomain, so that the assembly resolver method doesn't need to depend directly on NCrunch.Framework for the assembly resolution.

I'm going to update the documentation with a warning about this so that the code doesn't trip anyone else up. Sorry for the trouble and thanks for bringing it to my attention.
GibSral
#14 Posted : Saturday, June 13, 2020 9:31:23 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/1/2014(UTC)
Posts: 27
Location: Germany

Thanks: 3 times
Was thanked: 3 time(s) in 3 post(s)
Ahh ok, i will fiddle arround with this. As I am the only one in my team using ncrunch i need a solution that works for me and the others without installing ncrunch specific dlls in the gac of the other teammembers, so i am stuck with the nuget.
I will take a look at my GAC maybe i can exchange the dll or use a policy assembly to redirect to the installed version
GibSral
#15 Posted : Wednesday, June 17, 2020 12:53:42 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/1/2014(UTC)
Posts: 27
Location: Germany

Thanks: 3 times
Was thanked: 3 time(s) in 3 post(s)
Unfortunately I would need to use the same key for signing the policy assembly as you use to sign the ncrunch.framework.dll. Any chance that you could include such a policy dll in your ncrunch installation bundle?
Remco
#16 Posted : Thursday, June 18, 2020 1:10:42 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
I may have a better solution. Here is the code for the method you're calling. Just include this in your own project and there will be no need to resolve the assembly at all:

Code:

/// <summary>
/// Returns all assemblies detected by NCrunch as being required or referenced by this runtime environment.
/// </summary>
     public static string[] GetAllAssemblyLocations()
     {
var dependencies = Environment.GetEnvironmentVariable("NCrunch.AllAssemblyLocations");
if (dependencies == null)
return null;

const string filePrefix = "file:";

if (dependencies.StartsWith(filePrefix))
{
using (var fileStream = new FileStream(dependencies.Substring(filePrefix.Length), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (var reader = new StreamReader(fileStream, Encoding.UTF8, true))
return reader.ReadToEnd().Split(';');
}

return dependencies.Split(';');
}
1 user thanked Remco for this useful post.
GibSral on 6/18/2020(UTC)
GibSral
#17 Posted : Thursday, June 18, 2020 6:39:28 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/1/2014(UTC)
Posts: 27
Location: Germany

Thanks: 3 times
Was thanked: 3 time(s) in 3 post(s)
I will try this one today and hopefully report my success :D
GibSral
#18 Posted : Thursday, June 18, 2020 7:27:45 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/1/2014(UTC)
Posts: 27
Location: Germany

Thanks: 3 times
Was thanked: 3 time(s) in 3 post(s)
Works in my test project and in the production tests! Thank you very much!
Remco
#19 Posted : Thursday, June 18, 2020 8:42:17 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
GibSral;14809 wrote:
Works in my test project and in the production tests! Thank you very much!


Excellent! Thanks for confirming :)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.103 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download