views:

215

answers:

2

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!

A: 

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");

Krzysztof Koźmic
Unfortunately, registering the component through code yields the same results, with a slightly shorter stack trace (no Windsor exceptions). Trying Type.GetType() also raises a "System.IO.FileLoadException", when done through the same application. It's almost as though the activation policy isn't being taken into consideration for some reason.
Hugo
This suggests it's not really a Windsor issue - rather, perhaps a bug in the policy, which does not get taken into account when using reflection to load a library? (just guessing)
Krzysztof Koźmic
A: 

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.

Hugo
cool. Glad you were able to solve the issue. Could you create a reproduction of the issue, and post it to Castle group, so that we can see if there's anything that can be done to fix this?
Krzysztof Koźmic