# Reflection bug?

**URL:** <https://www.ruby-forum.com/t/reflection-bug/181334>\
**Category:** IronRuby\
**Created:** [January 10, 2010, 12:25am UTC](https://www.ruby-forum.com/t/reflection-bug/181334 "2010-01-10T00:25:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrew\_Wilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@andrew\_Wilson](https://www.ruby-forum.com/u/andrew_Wilson)\
**Post date:** [January 10, 2010, 12:25am UTC](https://www.ruby-forum.com/t/reflection-bug/181334/1 "2010-01-10T00:25:17Z")

</div>

I am building a console application that uses a MSH style CmdParser (  
[Shows | Microsoft Learn](http://channel9.msdn.com/playground/Sandbox/52952/)) to read input  
parameters  
and reflect match them up against a data class defining their meaning.

In the attempt to use RSpec & IronRuby to test my .net application, the  
code  
blows up on a call to the below method:

private static Parameter[] GetPublicReadWriteCmdMembers(object instance)  
{  
if ( instance == null )  
throw new ArgumentNullException(“instance”);

```
        ArrayList al = new ArrayList();
        Type type = instance.GetType();
        ArrayList members = new ArrayList();
        members.AddRange(type.GetProperties());
        members.AddRange(type.GetFields());

        if ( members.Count == 0 )
            throw new ArgumentException("No public members in 

```

type.");

```
        foreach(MemberInfo mi in members)
        {
            // Only add members that have ParameterBaseAttribute(s).
            if ( ! mi.IsDefined(typeof(ParameterBaseAttribute), 

```

true) )  
continue;

```
            switch(mi.MemberType)
            {
                case MemberTypes.Property:
                    PropertyInfo pi = (PropertyInfo)mi;
                    if ( ! (pi.PropertyType.IsPublic && pi.CanRead 

```

&&  
pi.CanWrite) )  
throw new ArgumentException(“All CMD members  
must be public readable and writeable.”);

```
                    // Loop here on members if parameterAttributes.
                    object[] pArray =

```

pi.GetCustomAttributes(typeof(ParameterAttribute), true);  
if ( pArray != null && pArray.Length \> 0 )  
{  
foreach(ParameterAttribute pa in pArray)  
{  
Parameter p =  
Parameter.CreateParameter(instance, mi, pa);  
al.Add(p);  
}  
}  
else  
{  
// Use default ParameterAttribute.  
ParameterAttribute pa = new  
ParameterAttribute();  
Parameter p =  
Parameter.CreateParameter(instance, mi, pa);  
al.Add(p);  
}  
break;  
case MemberTypes.Field:  
FieldInfo fi = (FieldInfo)mi;  
if ( ! fi.FieldType.IsPublic )  
throw new ArgumentException(“All Cmd members  
must be public”);

```
                    object[] pArray2 =

```

fi.GetCustomAttributes(typeof(ParameterAttribute), true);  
if ( pArray2 != null && pArray2.Length \> 0 )  
{  
foreach(ParameterAttribute pa in pArray2)  
{  
Parameter p =  
Parameter.CreateParameter(instance, mi, pa);  
al.Add(p);  
}  
}  
else  
{  
// Use default ParameterAttribute.  
ParameterAttribute pa = new  
ParameterAttribute();  
Parameter p =  
Parameter.CreateParameter(instance, mi, pa);  
al.Add(p);  
}

```
                    break;
                default:
                    break;
            }
        }
        return (Parameter[])al.ToArray(typeof(Parameter));
    }

```

Specifically, the exception thrown is on the call: if ( !  
mi.IsDefined(typeof(ParameterBaseAttribute), true) ) which is using  
reflection to figure out if the input parameter is defined in my data  
class  
(as best I can tell).

The exception is:

Could not load file or assembly ‘CmdParser, Version=1.5.0.0,  
Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The  
system  
cannot find the file specified.

So. I am stuck at a bit of an impasse. I tried requiring the CmdParser  
assembly in the way it claims above and it indeed blows up. However, if  
I  
call require.the dll itself and do some testing in IR I can repeat the  
exception during the reflection call.

Any ideas for how I might get through this?

-Andrew

---

<div class="post-metadata">

**Author:** ![andrew\_Wilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@andrew\_Wilson](https://www.ruby-forum.com/u/andrew_Wilson)\
**Post date:** [January 11, 2010, 10:43am UTC](https://www.ruby-forum.com/t/reflection-bug/181334/2 "2010-01-11T10:43:27Z")

</div>

## you can try copying your cmdparser.dll to the bin folder where ir.exe lives. That might work because I assume you’ve got it in the bin of your application already. Don’t shoot me if it doesn’t. I had to do this when I wanted to use particular control sets in WPF but that was a long time ago (\>1yr) so things might be different now.

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([IronRuby in Action - Ivan Porto Carrero and Adam Burmister | Manning](http://manning.com/carrero))
