I am building a console application that uses a MSH style CmdParser (
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

-- 
When I wrote this, only God and I understood what I was doing.  Now, God
only knows - Karl Weierstrass
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to