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

Notification

Icon
Error

NChrunch and Dependancy Inject via Spring.Net
Heiko
#1 Posted : Thursday, December 15, 2011 1:42:43 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/15/2011(UTC)
Posts: 4

There is a problem with loading Assemblys in the ApplicationDomain of NCrunch while using NCrunch:

Assembly A - *.cs file:
Code:


namespace ClassLibrary2
{
   public interface IInterface
   {
      int I { get; set; }
   }

   public class ClassInterface : IInterface
   {
      public int I { get; set; }
   }

   public class ClassFactory
   {
      public static object GetClassInterface()
      {
         var context = new Spring.Context.Support.XmlApplicationContext("WeavingInfo.xml");
         return context.GetObject("abc");
      }
   }
}


Assembly B (Tests) - WeavingInfo.xml file:
Code:

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" default-lazy-init="true">

  <object id="abc" type="ClassLibrary2.ClassInterface"/>

</objects>


Assembly B (Tests) - *.cs file:
Code:

namespace Tests
{
   [TestFixture]
   public class TestClass
   {
      [Test]
      public void test()
      { //////////
         IInterface x = null;
         //object y = new ClassABC();

         x = (IInterface)ClassFactory.GetClassInterface();
      }

   }
}


If you activate the Flag "CopyReferencedAssembliesToWorkspace" for the Test-Assembly than the test will crash because NChrunch has the Assembly A 2 Times:

DirectView:

?System.AppDomain.CurrentDomain.GetAssemblies()
{System.Reflection.RuntimeAssembly[28]}
[0]: {mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
[1]: {nCrunch.TaskRunner, Version=1.35.0.16, Culture=neutral, PublicKeyToken=01d101bf6f3e0aea}
[2]: {System.Runtime.Remoting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
[3]: {System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
[4]: {nCrunch.Common, Version=1.35.0.16, Culture=neutral, PublicKeyToken=01d101bf6f3e0aea}
[5]: {nCrunch.TestExecution, Version=1.35.0.16, Culture=neutral, PublicKeyToken=01d101bf6f3e0aea}
[6]: {System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
[7]: {Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
[8]: {Common.Logging, Version=1.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e}
[9]: {Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a}
[10]: {nunit.framework, Version=2.5.7.10213, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77}
[11]: {Spring.Aop, Version=1.3.1.40711, Culture=neutral, PublicKeyToken=65e474d141e25e07}
[12]: {Spring.Core, Version=1.3.1.40711, Culture=neutral, PublicKeyToken=65e474d141e25e07}
[13]: {System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
[14]: {System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
[15]: {System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
[16]: {System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
[17]: {ClassLibrary2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
[18]: {System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a}
[19]: {nunit.core.interfaces, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77}
[20]: {nunit.core, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77}
[21]: {System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a}
[22]: {nunit.framework, Version=2.5.7.10213, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77}
[23]: {nCrunch.TestRuntime, Version=1.35.0.16, Culture=neutral, PublicKeyToken=01d101bf6f3e0aea}
[24]: {nCrunch.Reflection, Version=1.35.0.16, Culture=neutral, PublicKeyToken=01d101bf6f3e0aea}
[25]: {ClassLibrary2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
[26]: {Spring.Core, Version=1.3.1.40711, Culture=neutral, PublicKeyToken=65e474d141e25e07}
[27]: {Common.Logging, Version=1.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e}

?System.AppDomain.CurrentDomain.GetAssemblies()[17].CodeBase
"file:///C:/Users/mk/AppData/Local/NCrunch/4564/53/ClassLibrary2/bin/Debug/ClassLibrary2.dll"
?System.AppDomain.CurrentDomain.GetAssemblies()[25].CodeBase
"file:///C:/Users/mk/AppData/Local/NCrunch/4564/59/Tests/bin/Debug/ClassLibrary2.DLL"

It throws a InvalidCastException because it has the Class from the one loaded Assembly (25) and the Interface from the other loaded Assembly (17):
ExceptionText:
Das Objekt des Typs "ClassLibrary2.ClassInterface" kann nicht in Typ "ClassLibrary2.IInterface" umgewandelt werden.
Translated: The object can't cast from the Type "ClassLibrary2.ClassInterface" to the Type "ClassLibrary2.IInterface".

If you deactivate the Flag "CopyReferencedAssembliesToWorkspace" for the Test-Assembly than the test will run perfectly.
But in my case I need the Assemblies in the Bin-Folder for other operations e.g. DynamicCodeCompilation.

So, to deactivate is no solution for me.
I Think there is a problem with the order of dynamic loading of assemblies over Activator or something like this.

If you need the complete VS-Solution than Mail me and I send it to you.

Best regards Heiko
Remco
#2 Posted : Thursday, December 15, 2011 9:07:56 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
Hi Heiko,

Thanks for posting! You're correct in that it does look as though this is a problem caused by the runtime resolver. I'd really like to have a look at your sample solution if you can make it available.

My knowledge of spring is very limited, but is it possible for you to supply your own path to the assembly you want to resolve inside your app domain? If so, you may be able to pick up the path of the correct assembly by pulling it out of the current application domain. There's an example of this in the troubleshooting test issues area of the wiki.

Cheers,

Remco
Heiko
#3 Posted : Friday, December 16, 2011 8:38:18 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/15/2011(UTC)
Posts: 4

How can I make the solution aviable, I don't find a function for attachments
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.041 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download