[Mono-list] Trouble accessing interface methods via as operator
Tue, 13 Apr 2004 06:16:52 -0400
On Tue, 2004-04-13 at 04:02, Michal Moskal wrote:
> On Tue, Apr 13, 2004 at 03:39:54AM -0400, Joe Scaduto wrote:
> > Hello,
> > I am trying to use the 'as' operator to access interface methods. I am
> > using reflection to create an instance of the class which implements the
> > interface. I am able to obtain the object but the 'as' operator always
> > returns null for me even though the class does implement the interface.
> > I am not sure what is going. Any help would be greatly appreciated.
> > code snippet:
> > System.Object obj = Activator.CreateInstance(type);
> > IServices current = obj as IServices;
> > if (current == null)
> > Console.WriteLine("obj does not implement IServices");
> Are you sure it is *the same* IServices that is implemented and that you
> use on right hand side of 'as' ? Where does the type come from? And
> where does the IServices come from? IServices seen by 'type' and 'as'
> can be different even when they share the name.
The type comes from a dll (Schedule.dll) which I compiled with the
namespace which IServices is defined (Umbrella.CIB.Service). The file
where I reflect on the Schedule.dll, where the above code snippet is
from, I have 'using Umbrella.CIB.Service' which is the same namespace I
used for compiling the Schedule.dll I thought then IServices as seen by
'type' and as seen by 'as' would be the same. Am I incorrect in this
Thanks in advance,