ConfigurationErrorsException with DateTimeConverter

Apr 13, 2010 at 11:41 PM
Edited Apr 13, 2010 at 11:42 PM

In VS 2010, configured for .NET 4 (not client--haven't tried client; but in case it's relavent).  In the unity config section I have a couple aliases as follows:

<typeAlias alias="String" type="System.String" />
<typeAlias alias="DateTimeConverter" type="System.ComponentModel.DateTimeConverter" />

Loading the config works fine for the String alias, but a ConfigurationErrorsExeception occurs for the DateTimeConverter detailing that it can't load DateTimeConverter from Unity.Configuration.  Changing to "System.ComponentModel.DateTimeConverter, System" results in the same exception but now "cannot load file or assembly 'System' or one of its dependencies".  It would only work if I use "System.ComponentModel.DateTimeConverter, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" for the type.

I just wanted to make sure this isn't specifically an issue with Unity.

Apr 14, 2010 at 2:49 AM

When you define an alias, you must use an assembly qualified name. It's kind of a fluke that String worked (by the way, in Unity 2.0 "string" is a predefined alias now, so you don't have to declare it yourself). So you need to specify the assembly. And, for assemblies like System which are in the Global Assembly Cache (GAC), you must use a fully qualified assembly name with the version, public key token, etc., otherwise the CLR can't find the type.

This behavior is what Type.GetType(string) does, not something specific to Unity.


Apr 14, 2010 at 8:15 PM
Okay, thanks. The 1.2 documentation seems to routinely use "string" without defining an alias for it. Somewhat of a moot point now, I suppose.