ResolutionFailedException on diferent AppDomains

Topics: Logging Application Block
Jul 27, 2010 at 8:49 AM

Hello:

I'm using the log in an environment with multiple AppDomains. This is my code:

AppDomainSetup setup = new AppDomainSetup();
				setup.ShadowCopyFiles = "true";
				dom = AppDomain.CreateDomain("Agents", AppDomain.CurrentDomain.Evidence, setup);
				dom.DoCallBack(DoCallBack);

void DoCallBack()
		{
			Logger.Log("DoCallBack");
			try
			{
				DirectoryCatalog dirCat = new DirectoryCatalog(@"Agents");
				CompositionContainer con = new CompositionContainer(dirCat);
				con.ComposeParts(this);
				//agent = con.GetExportedValue<IMefAgent>();
				Debug.WriteLine("ya: ");
				//agent.Start();
				agents.ForEach((a) =>
				{
					a.Start();
				});
			} catch (Exception ex)
			{
				Debug.WriteLine("ERROR: " + ex.Message);
			}
		}

In the method DoCallBack, the first line of code I get this exception:

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)

And Stack Trace

   en Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) en e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:línea 515
   en Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides) en e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:línea 485
   en Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) en e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:línea 173
   en Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key) en e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityServiceLocator.cs:línea 64
   en Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
An StackTrace of inner exception:

   en Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor) en e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:línea 289
   en Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) en e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:línea 71
   en Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) en e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:línea 110
   en Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey) en e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlanCreatorPolicy.cs:línea 48
   en Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) en e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:línea 37
   en Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) en e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:línea 110
   en Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) en e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:línea 511

What is the problem using the log in different application domains? How I can resolve this situation?

Thanks a greeting, Mythox.

PD: automatic translation, sorry.

 

Jul 27, 2010 at 1:17 PM

Hi,

Personally, I haven't really tried yet using logging app block in a multiple application domain environment. Though, would you know if it's working fine when in a single domain?

Also, have you checked if your logging configuration are configured properly.  Could you also post your configuration used here.

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jul 27, 2010 at 2:25 PM

Hi, thanks Gino, I solved the problem, had the wrong configuration file like you told me.

Now the system works properly, the logging is carried out in all AppDomains.

Thank you very much, greetings.