Entlib and Plugin Frameworks using Tracer

Topics: Logging Application Block
Apr 3, 2007 at 5:04 PM
Hi,

I've run into a error when i try to use the Tracer object, on the following command i get a Invalid Cast Exception - Unable to cast object of type 'Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings' to type 'Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings'.

The command it fails on is :

Using (New Tracer("Trace"))

I'm wondering if it's to do with the fact that i'm trying to use the entlib both in a application host and a pluging framework. I've been guessing about what i should do with regard to the relative app.config files for both the host application and the plugin.

Does anyone have a view using entlib in this way ? I've tried making sure the the entlib .dll's and the app.config for the plugin are in a place that can be seen by the application during runtime but with no luck.

Any ideas or suggestions ?

Many Thanks

John

I think this maybe due to me using a
Apr 3, 2007 at 5:31 PM
Hi John -

I suspect the issue here is that you are using different versions of the logging block in your host and plug-in applications. This could be due to incompatibilities in the code, or just different assembly version numbers or public keys. If you're sure both are compiled against the same version, also check your configuration file to make sure it's specifying the currect version and public key token.

Tom
Apr 5, 2007 at 7:52 PM
Hi Tom,

Thanks for the reponse, i'll check it tonight - i would make sense and i've upgraded this app from 2.0 to 3.0 so maybe i've missed something.

On the plugins though, do you think that it's acceptable to carry an app.config with each plugin as well as the one controlling the host application.

Given this design what would you do ?

Thanks

John
Oct 2, 2007 at 6:27 PM
I had the same problem. However I did not have 2.0 but instead just 3.1 of the logging app block
I am using the .NET framework 2.0

Does anyone know how to fix this problem?
Oct 3, 2007 at 1:26 PM
Hi,

What is the exact problem you're facing? Do you have a plugin architecture?

Please post a stack trace of your exception.

Fernando
Apr 17, 2008 at 9:06 AM
Did anyone ever solve this problem?

I have the exact same issue.

I have also upgraded my application from 1.1 to 2.0.

Could it be that there is versioning information (as in, .NET versioning information) saved somewhere that is causing this issue?
Apr 17, 2008 at 4:16 PM
Hello,

As far as I see there can be two possible reasons of that. The first one is which have already mentioned above related to the different versions of an assembly. I've run into the related problem one day because in my custom assembly I referenced EntLib dll at compile-time but it loads the other dll using Reflection according to the app.config settings. Just make sure that you have valid app.config with assemblies from 3.1 package (there are hardcoded version numbers and public tokens in app.config).

The second possible reason could be if you have EntLib libraries registered in GAC. I know nothing about Plugin framework implementation mentioned above but just be noticed that maybe somehow one of EntLib assemblies was called directly from local app folder but the object it's casting to is created using GAC's version of EntLib. Or vise versa. So if you have EntLib registered in GAC just don't use local copies.
Sep 4, 2008 at 4:20 PM
Hi,
don't compile the code use those dlls. if you are doing like that, you need to make sure that, you refrecne all compiled dlls of application blocks.

safe is: just refer the dlls from the installed location: usually it is: Drive:\Program Files\Microsoft Enterprise Library 3.1 - May 2007\Bin

Venkat