locked
Issues using HostType("Moles") and Enterprise Library 5.0 RRS feed

  • Question

  • It gives exception (details given below), when i debug this test. It stops on a line where its trying to log something using EL 5.0 in SoftDeleteActionValidatior

    However if I comment out/remove [HostType("Moles")] then it just works fine. So that shows that somehow Moles is not working with EL 5.0. Please help in resolving this issue. I am using 94.51006.1 version of Pex and Moles.

    My Test Method:

     

    namespace MockUnitTests.DataRetentionTest
    {
        [TestClass]
        public class SoftDeleteActionValidatiorTest
        {
            [TestMethod]
            [HostType("Moles")]
            public void TestMethod1()
            {
                SoftDeleteActionValidatior softDeleteActionValidatior = new SoftDeleteActionValidatior(new List<RRLAssignment>());
            }
        }
    }

     

    Exception:

     

    Microsoft.Practices.ServiceLocation.ActivationException occurred

      Message=Activation error occured while trying to get instance of type LogWriter, key ""

      Source=Microsoft.Practices.ServiceLocation

      StackTrace:

           at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)

           at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]()

           at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer()

           at Microsoft.Practices.EnterpriseLibrary.Logging.Tracer..ctor(String operation)

           at Deloitte.Oim.GlobalRisk.Drms.Domain.ProcessManagement.CaseProcessFactory.Create() in C:\Projects2010\DRMS\DRMS\Dev\DRMS3.0\Application\Domain\ProcessManagement\CaseProcessFactory.cs:line 22

      InnerException: Microsoft.Practices.Unity.ResolutionFailedException

           Message=Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", name = "(none)".

    Exception occurred while: while resolving.

    Exception is: InvalidOperationException - The type LogWriter cannot be constructed. You must configure the container to supply this value.

    -----------------------------------------------

    At the time of the exception, the container was:

     

      Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)

     

           Source=Microsoft.Practices.Unity

           TypeRequested=LogWriter

           StackTrace:

                at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)

                at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides)

                at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)

                at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key)

                at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)

           InnerException: System.InvalidOperationException

                Message=The type LogWriter cannot be constructed. You must configure the container to supply this value.

                Source=Microsoft.Practices.Unity

                StackTrace:

                     at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor)

                     at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context)

                     at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

                     at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey)

                     at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)

                     at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

                     at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)

                InnerException: 


     

    Friday, February 25, 2011 2:03 PM

Answers

All replies

  • I get this same message, but I thought it was because I had the EL stuff in the GAC.
    Friday, February 25, 2011 3:55 PM
  • The issue might be due to the fact that the Moles host does not support the test configuration file currently. I suspect EL heavily relies on the .config file.
    Jonathan "Peli" de Halleux - Try Pex online at www.pexforfun.com!
    Friday, February 25, 2011 6:58 PM
  • I'll mole System.Configuration and make it return a typeRegistrationProvidersConfiguration section (which is what is used to fix normal apps when EL is in the GAC per - http://entlib.codeplex.com/workitem/26903).

     

    If that works then yes, that's exactly it.

     

    Would be nice if Moles would support the test app config file.

    Friday, February 25, 2011 8:22 PM
  • Uday,

     

    Please refer this thread: http://social.msdn.microsoft.com/Forums/is/pex/thread/9b4b9ec5-582c-41e8-8b9c-1bb9457ba3f6

    It has some code that will give some idea about what is suggested by Peter below.

    Solution in the thread mentioned above worked for me.

     

    • Marked as answer by Uday Chavda Wednesday, March 2, 2011 7:16 AM
    Saturday, February 26, 2011 2:57 PM
  • Thanks vinmacji,

    This solved my problem. Now my tests (using Moles host) is working fine.

    Wednesday, March 2, 2011 7:22 AM
  • Has there been a fix to Moles?  It would be nice for things to just work instead of having to add these "fixes".

     

    Thursday, March 31, 2011 5:34 PM