Windows Vista Beta | WinVistaBeta.com - Message | AddIn Problem

November 20, 2008  
Subject: AddIn Problem
Group: microsoft.public.vstudio.general
Date: 8/10/2008 2:39:48 PM
From: Jack Jackson [Email Address Protection]

I have written a VS 2008 AddIn. Everything works fine except for one
thing.

The AddIn looks at the current Design View window, gets a reference
the control being designed and runs its Controls collection.

Some of the child controls are my own classes that inherit from
various .NET controls, and they all implement one or more of my
Interfaces.

My AddIn is unable to cast these controls to any of the Interfaces
that they implement - it gets an InvalidCastException.

As a test I created one of these classes in the AddIn, and I am able
to cast that object to the interfaces.

In the debugger I can't see any difference between the two objects,
one that is on the designer and the other that was created in the
AddIn. If I call Type.GetInterfaces on both the object from the
designer and the one I create in the AddIn, both list the same
interfaces.

Does anyone have any idea why I can't cast these objects to their
interfaces?


Back
Subject: Re: AddIn Problem
Group: microsoft.public.vstudio.general
Date: 8/10/2008 5:19:08 PM
From: Jack Jackson [Email Address Protection]

On Sun, 10 Aug 2008 14:39:48 -0700, Jack Jackson
<jjackson@cinnovations.net> wrote:

>I have written a VS 2008 AddIn. Everything works fine except for one
>thing.
>
>The AddIn looks at the current Design View window, gets a reference
>the control being designed and runs its Controls collection.
>
>Some of the child controls are my own classes that inherit from
>various .NET controls, and they all implement one or more of my
>Interfaces.
>
>My AddIn is unable to cast these controls to any of the Interfaces
>that they implement - it gets an InvalidCastException.
>
>As a test I created one of these classes in the AddIn, and I am able
>to cast that object to the interfaces.
>
>In the debugger I can't see any difference between the two objects,
>one that is on the designer and the other that was created in the
>AddIn. If I call Type.GetInterfaces on both the object from the
>designer and the one I create in the AddIn, both list the same
>interfaces.
>
>Does anyone have any idea why I can't cast these objects to their
>interfaces?

I got it to work using Reflection to do all of the accesses.

My guess is that the IDE is doing some magic here, and the objects
instantiated on the design surface aren't the real objects even though
the debugger claims they are.

Does anyone know what is going on here?


Back