views:

33

answers:

2

I am trying to register a type conversion in my config file as follows:

<param name="connectionString" parameterType="System.String">
    <value value="MyDbConnection" 
        type="System.Configuration.ConnectionStringSettings" 
        typeConverter="ConnectionStringSettingsTypeConverter" />
</param>

I am getting the standard can't load type error

Could not load type 'System.Configuration.ConnectionStringSettings' from assembly 'Microsoft.Practices.Unity.Configuration, ...etc

Why is it trying to load the type from the Unity assembly? What do I need to add for Unity to locate the correct assembly?

I thought because I was using the fully qualified name, it should just work.

Edit: note I am using version 1.2. The 2.0 version has an tag in the schema, but 1.2 doesn't seem to have this tag.

+1  A: 

You're not using the really fully qualified type name - you need to provide the assembly name as well. Try this:

type="System.Configuration.ConnectionStringSettings,System.Configuration"
Jon Skeet
I now get `Could not load file or assembly 'System.Configuration' or one of its dependencies. The system cannot find the file specified`. Exception Details: ` System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration' or one of its dependencies. The system cannot find the file specified.` on line `config.Containers.Default.Configure(_container)`. Any ideas?
fearofawhackplanet
I got it working now John, thanks for your help.
fearofawhackplanet
A: 

I found a clue on the question here

I changed my System.Configuration reference to CopyLocal = True. Apparently Unity isn't clever enough to look in the GAC. Well done Microsoft! :(

fearofawhackplanet
No, that's not the issue. It's how type loading by name works in .NET. If you want to load from the GAC, you need to use the Fully Qualified Assembly Name, including the culture, version number, AND public key token. If you don't have the entire thing, it won't work. That's just .NET, you'll have the same problem calling Type.GetType(name).
Chris Tavares