Search:
Namespaces
Discussions
.NET v1.1
Feedback
reflecting custom attributes...
Messages
Related Types
This message was discovered on
ASPFriends.com 'ngfx-reflection' list
.
Robert Chartier
-- Copied from [aspngcs] to [ngfx-reflection] by Ryan Trudelle-Schwarz <
Click here to reveal e-mail address
> --
This is a bit confusing, but IMHO its a bug.
I have a set of classes which i want to add attributes to them.
So i create my attribute class, and derive from Attribute, then add the
needed attributes to my classes. Nothing new. It compiles and works fine.
Next i try to reflect these attributes. So i get the type, and then attempt
to pull out the CustomAttributes:
object[] att1 = type.GetCustomAttributes(false);
try {
Santra.MyCustomAttrib valatt;
valatt = (Santra.MyCustomAttrib)att1[0]; /* 1 */
return valatt.AttribValue;
} catch(Exception e) {
return false;
}
(Ive hard coded most of the logic to simplify things.)
The line above marked with /* 1 */ is where the problem comes in. I step
the debugger to that line, and use the debugger's QUICK WATCH to check out
the cast
(Santra.MyCustomAttrib)att1[0]
and it handles the cast properly. Its type is "Santra.MyCustomAttrib" No
problems with the debugger.
Next I hit the step button, and attempt to actually cast that class back in
to the variable. This is when it throws an exception..."Specified Cast is
not Valid"
how can the Quick Watch cast it properly (as it should be doing), but not
the actual stepping over code? Ive tried this on a few different machines
to make sure my install isnt the issue. Same issue on both machines.
Thanks for any help.
Robert Chartier
Author and Developer
604-975-5590
Click here to reveal e-mail address
http://www.aspalliance.com/nothingmn/
Reply to this message...
Russ McClelland
Have you tried specifying the namespace for the type? I have run into
some cases where I needed to specify the full type in order for a cast
to work.
-----Original Message-----
From: Robert Chartier [mailto:
Click here to reveal e-mail address
]=20
Sent: Sunday, May 26, 2002 2:05 PM
To: ngfx-reflection
Subject: [ngfx-reflection] reflecting custom attributes...
-- Copied from [aspngcs] to [ngfx-reflection] by Ryan Trudelle-Schwarz
<
Click here to reveal e-mail address
> --
This is a bit confusing, but IMHO its a bug.
I have a set of classes which i want to add attributes to them. So i
create my attribute class, and derive from Attribute, then add the=20
needed attributes to my classes. Nothing new. It compiles and works
fine.
Next i try to reflect these attributes. So i get the type, and then
attempt=20
to pull out the CustomAttributes:
object[] att1 =3D type.GetCustomAttributes(false);
try {
Santra.MyCustomAttrib valatt;
valatt =3D (Santra.MyCustomAttrib)att1[0]; /* 1 */
return valatt.AttribValue;
} catch(Exception e) {
return false;
}
(Ive hard coded most of the logic to simplify things.)
The line above marked with /* 1 */ is where the problem comes in. I
step=20
the debugger to that line, and use the debugger's QUICK WATCH to check
out=20
the cast
(Santra.MyCustomAttrib)att1[0]
and it handles the cast properly. Its type is "Santra.MyCustomAttrib"
No=20
problems with the debugger.
Next I hit the step button, and attempt to actually cast that class back
in=20
to the variable. This is when it throws an exception..."Specified Cast
is=20
not Valid"
how can the Quick Watch cast it properly (as it should be doing), but
not=20
the actual stepping over code? Ive tried this on a few different
machines=20
to make sure my install isnt the issue. Same issue on both machines.
Thanks for any help.
Robert Chartier
Author and Developer
604-975-5590
Click here to reveal e-mail address
http://www.aspalliance.com/nothingmn/
| [ngfx-reflection] member
Click here to reveal e-mail address
=3D YOUR ID=20
|
http://www.aspfriends.com/aspfriends/ngfx-reflection.asp
=3D JOIN/QUIT
Reply to this message...
Robert Chartier
Yes, ive fully specified everything. And that still wouldnt explain why
the Quick Watch tools casts it right, but stepping into the code throws an
error. Everything is correct, but it still doest not work.
/rob
At 11:03 AM 05/27/2002 -0500, you wrote:
[Original message clipped]
Robert Chartier
Author and Developer
604-975-5590
Click here to reveal e-mail address
http://www.aspalliance.com/nothingmn/
Reply to this message...
Robert Chartier
one more note to add
if i DONT use reflection, and get the type like:
Type type=typeof(Santra.MyClass);
where MyClass is using the custom attributes, it works just fine
but still no luck with reflection & custom attributes (other than it
working only with the Quick Watch in the debugger)....it just doesnt make
any sense.
/rob
At 11:03 AM 05/27/2002 -0500, you wrote:
[Original message clipped]
Robert Chartier
Author and Developer
604-975-5590
Click here to reveal e-mail address
http://www.aspalliance.com/nothingmn/
Reply to this message...
Russ McClelland
I agree, I just know when I was going after enums using reflection, I
had to specify the full namespace, class, and enum name to get values
using reflection whereas I did not using the debugger.
-----Original Message-----
From: Robert Chartier [mailto:
Click here to reveal e-mail address
]=20
Sent: Monday, May 27, 2002 1:46 PM
To: ngfx-reflection
Subject: [ngfx-reflection] RE: reflecting custom attributes...
Yes, ive fully specified everything. And that still wouldnt explain why
the Quick Watch tools casts it right, but stepping into the code throws
an=20
error. Everything is correct, but it still doest not work.
/rob
At 11:03 AM 05/27/2002 -0500, you wrote:
[Original message clipped]
Robert Chartier
Author and Developer
604-975-5590
Click here to reveal e-mail address
http://www.aspalliance.com/nothingmn/
| [ngfx-reflection] member
Click here to reveal e-mail address
=3D YOUR ID=20
|
http://www.aspfriends.com/aspfriends/ngfx-reflection.asp
=3D JOIN/QUIT
Reply to this message...
Robert Chartier
when i reflect an assembly that i load off of disk (assembly.load(byte[]))
and then get the Type from there, then attributes, it doesnt work...no
matter what i try.
but when i reflect by loading the type directly Type type = typeof(foo);,
and then attempt for the attributes it works fine...no matter at the class
level or the member level.
im assuming that it should work either way because being restricted to the
second option only would be limiting the capabilities of dynamic reflection
of assemblies.
/rob
At 07:59 PM 05/27/2002 -0500, you wrote:
[Original message clipped]
Robert Chartier
Author and Developer
604-975-5590
Click here to reveal e-mail address
http://www.aspalliance.com/nothingmn/
Reply to this message...
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com