Problem using custom rule in xml configuration file

Topics: Developer Forum
Aug 9, 2007 at 1:08 PM
Edited Aug 9, 2007 at 1:26 PM
I tried to use a custom rule in xml configuration file, but when I set typeName attribute of rule element with the "MyCompany.MyProduct.MyNamespace.MyRuleConfigReader, MyCompany.MyProduct.MyNamespace" value, I received the error "TypeLoadException" in TryGetType method.
In GetRule method internalTypeName is set to "ValidationFramework.Configuration.MyCompany.MyProduct.MyNamespace.MyRuleConfigReader, MyCompany.MyProduct.MyNamespace,ValidationFramework".
The first try to load a type finds the assembly "ValidationFramework" (not the mine) but don't finds the type and a TypeLoadException is thrown even if throwOnError is false.

I suggest this workaround:

internal static bool TryGetType(string typeName, out Type type)
// from:
// " ...
// The throwOnError parameter only affects what happens when the type is not found.
// It does not affect any other exceptions that might be thrown.
// In particular, if the type is found but cannot be loaded, a TypeLoadException can be thrown even if throwOnError is false
type = Type.GetType(typeName, false);
catch (Exception)
type = null;
if (type == null)
return false;
return true;

I used the ValidationFramework-25443.


Aug 10, 2007 at 11:16 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Aug 11, 2007 at 1:24 AM
Fixed now.
Thanks for finding this one.
I also added a test for that case so it should not show up again.
Let me know if u have any problems.