Blog Stats
  • Posts - 157
  • Articles - 0
  • Comments - 67
  • Trackbacks - 19

 

Enterprise Library: Exception has been thrown by the target of an invocation

A co-worker encountered the following exception when trying to use a library that uses the Microsoft Enterprise Library:

System.Reflection.TargetInvocationException was unhandled by user code
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeMethodHandle._InvokeConstructor(Object[] args, SignatureStruct& signature, IntPtr declaringType)
at System.RuntimeMethodHandle.InvokeConstructor(Object[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ExplicitInstrumentationAttacher.BindInstrumentation()
...

This is caused when using the built-in instrumentation features of the Enterprise Library by enabling instrumentation in the configuration file before installing the instrumentation.

There are at least two possible solutions:

1. Disable instrumentation

One possible solution is to disable the usage of instrumentation. This can be done by adding the following lines to the configuration file:

<configuration>
	<configSections>
		<section name="instrumentationConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.Configuration.InstrumentationConfigurationSection, Microsoft.Practices.EnterpriseLibrary.Common"/>
	</configSections> 
	<instrumentationConfiguration performanceCountersEnabled="false" /> 
</configuration> 

2. Install services for the application blocks

Another solution would be to install the services for the Enterprise Library application blocks instrumentation by running the batch file that you will find in Start -> All Programs -> Microsoft pattern & practices -> Enterprise Libary - January 2006 -> Install Instrumentation


Cross-posted from The .NET Aficionado

Feedback

# re: Enterprise Library: Exception has been thrown by the target of an invocation

Gravatar Nice. I was getting the same error whenever i started windows service. After reading the above workaround, i was able to run the service with no errors.
Thanks. 6/8/2007 1:57 PM | Vijay

# re: Enterprise Library: Exception has been thrown by the target of an invocation

Gravatar it didn't solve my problem, I looked at the innerexception, a variable had a DBNullValue that caused the exception 5/14/2009 6:32 AM | jbosch

Post a comment





 

 

 

Copyright © Gabriel Lozano-Morán