Thansks Jeroen;

Prior to posting this question I tried to use SetCustomAttributes where it
hung for me also.

Never thought of trying it out on Whidbey. Interesting.

Peter Partch

----- Original Message -----
From: "Jeroen Frijters" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, February 05, 2004 2:10 AM
Subject: Re: [ADVANCED-DOTNET] Reflection.Emit, MarshalAsAttribute and
dealing with SizeParamIndex


I wrote:
> I tried to use SetCustomAttribute to emit a
> MarshalAsAttribute, but that hangs (!)
>
> I looked at the Rotor code and SetCustomAttribute actually has support
> for pseudo-custom attributes, so in theory it should work,
> but it looks like there is a bug somewhere in the runtime.

I don't know if this is any use to you, but I just tried it on Whidbey,
and there it does work.

Here is the code I used:

ConstructorInfo ci = typeof(MarshalAsAttribute).GetConstructor(new
Type[] { typeof(UnmanagedType) });
CustomAttributeBuilder cb = new CustomAttributeBuilder(ci, new object[]
{ UnmanagedType.LPArray }, new PropertyInfo[0], new object[0], new
FieldInfo[] { typeof(MarshalAsAttribute).GetField("SizeParamIndex") },
new object[] { (short)0 });
paraBld.SetCustomAttribute(cb);

This yields:

.method public abstract virtual instance void
        SetArray([in] int32 count,
                 [in] int32[]  marshal([ + 0]) 'array') cil managed

So the good news is that they fixed the bug, the bad news is that you
have to wait a while before the fix becomes available :-(

Regards,
Jeroen

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to