As long as you don't have IAction defined in two separate assemblies
or namespaces you should be fine.

The problem could be that you are actually loading the executing
assembly (or at least IAction) twice by using LoadFrom. Can't confirm
that because I don't have a copy of the dll you used, but it's a
hunch. You can check what you have loaded using GetLoadedAssemblies.

If everything is one assembly, you don't need to load from the file,
use the GetExecutingAssembly call instead. The only reason you would
want to load the assembly from a file is if you needed to dynamically
load a class.





On 8/17/05, Falls, Travis D (HTSC, CASD) <[EMAIL PROTECTED]> wrote:
> Hey Dean,
> Thanks for looking at that for me.  I have a quick question about your
> response...
> "Make sure both assemblies refer to the same definition of IAction" and "my
> bet is that you have IAction defined in two places"... I don't think I have
> this defined in both namespaces.  I have three files... the one with the
> main in it which is in its own namespace and the action and action interface
> in another interface... I reference this DLL in VS.net in the project with
> the EXE.  How can I check to see if this is defined in two different
> locations?  Thanks again.
> 
> 
> Travis D. Falls | Consultant   RAFT.Net   IT | 860.547.4070 |
> [EMAIL PROTECTED]
> 
> 
> -----Original Message-----
> From: AspNetAnyQuestionIsOk@yahoogroups.com
> [mailto:[EMAIL PROTECTED] Behalf Of Dean Fiala
> Sent: Wednesday, August 17, 2005 2:18 PM
> To: AspNetAnyQuestionIsOk@yahoogroups.com
> Subject: Re: [AspNetAnyQuestionIsOk] Reflection Issue
> 
> 
> Travis,
> I was able to get this to work.  Instead of loading the assembly from
> a file, I just loaded the executing assembly.  Your code basically
> works, so my bet is that you have IAction defined in two places (one
> in each assembly) and therefore you get the invalid cast exception.
> Make sure both assemblies refer to the same defintion of IAction.
> Might be helpful to put in a third assembly.
> 
> private static void Main(string[] args)
>                 {
>                         Assembly refAsyAction
> =Assembly.GetExecutingAssembly();
>                         Type type =
> 
> refAsyAction.GetType(@"com.TheHartford.HTSC.RAFT.Reflection.Actions.ftp");
>                         IAction myFTP =
> 
> (IAction)refAsyAction.CreateInstance(type.FullName);
>                         myFTP.start();
>                 }
> 
> On 8/17/05, Falls, Travis D (HTSC, CASD) <[EMAIL PROTECTED]>
> wrote:
> > I have written an attempt at reflection as I described which is listed
> below
> > (C#).  I am getting an error on the line IAction myFTP = .... the error is
> > listed directly below.  does anyone know how I can accomplish this?:
> >
> > An unhandled exception of type 'System.InvalidCastException' occurred in
> > ReflectionExample.exe
> > Additional information: Specified cast is not valid.
> >
> >
> > using System;
> > using System.Reflection;
> > using com.TheHartford.HTSC.RAFT.Reflection.Actions;
> >
> > namespace com.TheHartford.HTSC.RAFT.Reflection {
> >         internal class ReflectionExample {
> >
> >                 public ReflectionExample() {
> >                         init();
> >                 }
> >
> >
> >                 private void init() {}
> >
> >
> >                 [STAThread]
> >
> >                 private static void Main(string[] args) {
> >                         Assembly refAsyAction =
> > Assembly.LoadFrom(@"C:\TEMP\Actions.dll");
> >                         Type type =
> > refAsyAction.GetType(@"com.TheHartford.HTSC.RAFT.Reflection.Actions.ftp");
> >                         IAction myFTP =
> > (IAction)refAsyAction.CreateInstance(type.FullName);
> >                         myFTP.start();
> >                 }
> >
> >         }
> > }
> >
> >
> >
> > namespace com.TheHartford.HTSC.RAFT.Reflection.Actions
> > {
> >
> >         public interface IAction
> >         {
> >                 string start();
> >         }
> >
> >
> >         public class ftp : IAction
> >         {
> >                 public ftp() {}
> >
> >                 public string start()
> >                 {
> >                         return "Is Working; FTP Start";
> >                 }
> >         }
> > }
> >
> >
> > *************************************************************************
> > PRIVILEGED AND CONFIDENTIAL: This communication, including attachments, is
> > for the exclusive use of addressee and may contain proprietary,
> > confidential and/or privileged information.  If you are not the intended
> > recipient, any use, copying, disclosure, dissemination or distribution is
> > strictly prohibited.  If you are not the intended recipient, please notify
> > the sender immediately by return e-mail, delete this communication and
> > destroy all copies.
> > *************************************************************************
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> 
> 
> --
> Dean Fiala
> Very Practical Software, Inc
> http://www.vpsw.com
> 
> 
> 
> 
> Yahoo! Groups Links
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Yahoo! Groups Links
> 
> 
> 
> 
> 
> 
> 
> 


-- 
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com


------------------------ Yahoo! Groups Sponsor --------------------~--> 
<font face=arial size=-1><a 
href="http://us.ard.yahoo.com/SIG=12hbl9jsp/M=362131.6882499.7825260.1510227/D=groups/S=1705006764:TM/Y=YAHOO/EXP=1124312768/A=2889191/R=0/SIG=10r90krvo/*http://www.thebeehive.org
">Get Bzzzy! (real tools to help you find a job) Welcome to the Sweet Life 
- brought to you by One Economy</a>.</font>
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to