app.config not found by ent lib

Topics: Logging Application Block
Mar 19, 2011 at 7:23 AM

I created a configuration file using the Ent lib config editor and renamed it to app.config. I also copied it, into my bin\debug folder

However when I run my console exe it throws an error. I am sure this is FAQ. but my understanding was that renaming the entlib config file to app.config and copying it with the console exe will resolve the issue.

 

Unhandled Exception: Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to g
et instance of type LogWriter, key "" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the depend
ency 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)
 ---> System.InvalidOperationException: The type LogWriter cannot be constructed. You must configure the container to su
pply this value.
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext contex
t, SelectedConstructor selectedConstructor) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategie
s\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:line 289
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) in e:\Buil
ds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstr
uctorStrategy.cs:line 71
   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityT
emp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:line 110
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTy
peBuildKey buildKey) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMeth
od\DynamicMethodBuildPlanCreatorPolicy.cs:line 48
   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityT
emp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:line 37
   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityT
emp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:line 110
   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOve
rrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 511
   --- End of inner exception stack trace ---
   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOve
rrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 515
   at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) in e:\
Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 173
   at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key) in e:\Builds\Unity\Unity
Temp\Compile\Unity\Unity\Src\UnityServiceLocator.cs:line 64
   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Ch
ris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 49
   --- End of inner exception stack trace ---
   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Ch
ris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 53
   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]() in c:\Home\Chris\Projects\Commo
nServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 90
   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer() in e:\Builds\EntLib\Latest\Source\Blocks\Logging
\Src\Logging\Logger.cs:line 408
   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(LogEntry log) in e:\Builds\EntLib\Latest\Source\Blocks\
Logging\Src\Logging\Logger.cs:line 303

Mar 21, 2011 at 3:51 AM

Hi,

You don't need to manually copy your already created config file to bin\debug folder of your project directory. You just need to have App.config added to your project then Visual Studio will copy and rename this to <exename>.exe.config at runtime.  Did you already add the App.config as an Existing Item to your project?

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 9, 2011 at 2:40 AM

Hello,

i had the same error (see below) when i tried to rename the app.config or transfer to other location.

Error:

Unhandled Exception: Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to g
et instance of type LogWriter, key "" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the depend
ency 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.

Sep 9, 2011 at 2:45 AM

Hi gelai,

By design, it will look for the configuration named app.config or web.config, so it would be better not to rename it other than the default name.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us