P
pop-server
There appears to be a bug in CustomAttributeTypedArgument.ResolveType
I encounter it when I do reflection on custom attribute data where the
custom attribute constructor type is in a different assembly than
a CustomAttributeEncodedArgument that encodes a type from a different
assembly than mscorlib.
I would appreciate any workarounds that you can suggest.
You can reproduce the problem with this sample:
namespace TestCustomAttributes
{
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Reflection;
using System.Windows.Forms;
namespace TestCustomAttributeReflection
{
internal class ButtonDesigner
{
}
[System.ComponentModel.Designer(typeof(TestCustomAttributeReflection.ButtonDesigner))]
internal class Button : System.Windows.Forms.Button
{
}
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Type theButtonType = typeof(TestCustomAttributeReflection.Button);
foreach (CustomAttributeData theCustomAttributeData in
CustomAttributeData.GetCustomAttributes(theButtonType))
{
System.Collections.Generic.IList<CustomAttributeTypedArgument>
theConstructorArguments = theCustomAttributeData.ConstructorArguments;
}
}
}
}
}
The relevant code in CustomAttributeTypedArgument.ResolveType looks
something like:
Type type1 = Type.GetType(typeName);
if ((type1 == null) || (type1.Assembly !=
typeof(object).Assembly))
{
try
{
type1 =
typeof(object).Assembly.GetType(typeName);
}
catch (Exception)
{
}
}
This line finds the type
type1 = Type.GetType(typeName);
The || condition in the next line causes the type1 variable to be reassigned
to null in the case where type1.Assembly is not mscorlib
if ((type1 == null) || (type1.Assembly !=
typeof(object).Assembly))
{
try
{
type1 =
typeof(object).Assembly.GetType(typeName);
Jonathan Pierce
President
Jungle Creatures, Inc.
http://www.junglecreatures.com/
I encounter it when I do reflection on custom attribute data where the
custom attribute constructor type is in a different assembly than
a CustomAttributeEncodedArgument that encodes a type from a different
assembly than mscorlib.
I would appreciate any workarounds that you can suggest.
You can reproduce the problem with this sample:
namespace TestCustomAttributes
{
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Reflection;
using System.Windows.Forms;
namespace TestCustomAttributeReflection
{
internal class ButtonDesigner
{
}
[System.ComponentModel.Designer(typeof(TestCustomAttributeReflection.ButtonDesigner))]
internal class Button : System.Windows.Forms.Button
{
}
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Type theButtonType = typeof(TestCustomAttributeReflection.Button);
foreach (CustomAttributeData theCustomAttributeData in
CustomAttributeData.GetCustomAttributes(theButtonType))
{
System.Collections.Generic.IList<CustomAttributeTypedArgument>
theConstructorArguments = theCustomAttributeData.ConstructorArguments;
}
}
}
}
}
The relevant code in CustomAttributeTypedArgument.ResolveType looks
something like:
Type type1 = Type.GetType(typeName);
if ((type1 == null) || (type1.Assembly !=
typeof(object).Assembly))
{
try
{
type1 =
typeof(object).Assembly.GetType(typeName);
}
catch (Exception)
{
}
}
This line finds the type
type1 = Type.GetType(typeName);
The || condition in the next line causes the type1 variable to be reassigned
to null in the case where type1.Assembly is not mscorlib
if ((type1 == null) || (type1.Assembly !=
typeof(object).Assembly))
{
try
{
type1 =
typeof(object).Assembly.GetType(typeName);
Jonathan Pierce
President
Jungle Creatures, Inc.
http://www.junglecreatures.com/