Whidbey Bug? CustomAttributeTypedArgument.ResolveType

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/
 
P

pop-server

Thanks Willy,

I posted a bug report in the appropriate place.

Jonathan

Willy Denoyette said:
This is not a Whidbey NG, please post to -
microsoft.private.whidbey.framework_sdk.
and/or report an issue to: http://lab.msdn.microsoft.com/productfeedback/

Willy.

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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top