InvalidCastExeption with ObjectBuilder

Dec 12, 2006 at 8:03 AM
I'm using the ObjectBuilder with Brad Wilsons DependencyContainer. Here I see an InvalidCastException at:
private ParameterAttribute GetInjectionAttribute(ParameterInfo parameterInfo)
ParameterAttribute[] attributes = (ParameterAttribute[])parameterInfo.GetCustomAttributes
(typeof (ParameterAttribute), true);

Object of type System.Object[] can not be converted to type Microsoft.Practices.ObjectBuilder.ParameterAttribute[]

The class is build like:

class ClassOne {
public ClassTwo class2 {get; set;}
public ClassThree [] class3 {get; set;}

ClassTwo and ClassThree contain no further dependencies, just data.
Calling :
DependencyContainer container = new DependencyContainer();
ClassOne resp = container.Get<ClassOne>();

ClassTwo gets build, ClassThree fails

What is wrong with this??

The problem is with the ClassThree Array, which I would expect to be initialized as
class3 = new ClassThree0. There could probably a strategy for this - but here I failed.

Exprecting good ideas from here

Dec 14, 2006 at 6:51 PM
Yeah, something doesn't make sense here. That cast should always succeed. It's asking reflection for an array of the specific type of custom attribute.

I have no idea what the real problem is. Can you make a very small repro?
Dec 15, 2006 at 11:54 AM
Yaeh, I've got an extension to the DISample that I could send anywhere just knowing where it is.

In short:
one class ist added:
/// ++++ CODE
public class ObjectWithArray
private Object1 obj1;

public Object1 Obj1 {
get { return obj1; }
set { obj1 = value; }

private Object1[] arrObj;

public Object1[] ArrObj {
get { return arrObj; }
set { arrObj = value; }
/// ---- CODE

and one TestMethod is added:

/// ++++ CODE
public void ObjectWithArrayTest( ) {
Builder builder = new Builder();
DependencyContainer container = new DependencyContainer();

// ==>> throws InvalidCastException
ObjectWithArray obj = container.Get<ObjectWithArray>();

Assert.IsNotNull( obj );
Assert.IsNotNull( obj.Obj1 );
Assert.IsNotNull( obj.ArrObj );
/// ---- CODE