Getting a “ComponentActivatorException” using Castle Windsor from a .net 4.0 application using a .net 2.0 component

StackOverflow https://stackoverflow.com/questions/2276033

Question

I have an application which is being developed in VS2010, and makes use of the Castle-Windsor IoC, through a configuration file.

One of the components I am registering, also developed in VS2010, references a .net 2.0 component (LeadTools), so recompiling the 2.0 project isn't an option. When the wrapping component's registration is done, a "ComponentActivatorException" is raised, which wraps a "System.TypeInitializationException", which in turn wraps a "System.IO.FileLoadException" with a message of "Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information."

I have added the runtime declaration to the application's configuration file, as so:

<!-- useLegacyV2RuntimeActivationPolicy is needed for LEADTools-->
<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  <supportedRuntime version="v2.0.50727" />
</startup>

This works fine if the wrapping component isn't registered in Windsor, however, it does appear to disregard the directives otherwise.

Thanks!

Was it helpful?

Solution 2

The problem was due to using "define"s and "if"s within the configuration file, per the MicroKernel documentation. Removing all of those elements from the App.Config file allowed the components to be instantiated, whether or not they were registered in the Windsor container.

OTHER TIPS

I assume you're using registration via XML?

What happens if you register the component in code?

Can you try to reproduce the issue without error?

call Type.GetType("assembly qualified name of the type from .net 2.0 assembly");

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top