Click here to Skip to main content
16,004,901 members
Home / Discussions / C#
   

C#

 
AnswerRe: Checking DB existance Pin
Colin Angus Mackay26-Mar-06 10:49
Colin Angus Mackay26-Mar-06 10:49 
QuestionDeploying and Loading an assembly Pin
Subby Dev26-Mar-06 8:00
Subby Dev26-Mar-06 8:00 
QuestionFlateStyle.System Button Pin
Gamil Mohamad26-Mar-06 6:17
Gamil Mohamad26-Mar-06 6:17 
AnswerRe: FlateStyle.System Button Pin
AB777126-Mar-06 17:09
AB777126-Mar-06 17:09 
GeneralRe: FlateStyle.System Button Pin
Gamil Mohamad26-Mar-06 20:13
Gamil Mohamad26-Mar-06 20:13 
Questionlooking for program that chake similry code Pin
The_general1026-Mar-06 5:40
The_general1026-Mar-06 5:40 
QuestionHow to carry out MoneyCell with the VS2005 and GDI+? Pin
Chinese_ynzy26-Mar-06 5:24
Chinese_ynzy26-Mar-06 5:24 
QuestionInterface Type-casting problem Pin
hhrafn26-Mar-06 4:18
hhrafn26-Mar-06 4:18 
Hi,

I'm trying to typecast a class that I load from a dll. This class is using a certain interface and I'd like to type-cast it into the same interface (see code).

I should also point out that the main class and the class that I'm trying to load into it are in two seperate projects (and namespaces).

But my problem is that when I run this I get the error:
"Unable to cast object 'Class1' to type 'IPlugin'." Confused | :confused:

<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
<br />
class Class1 : IPlugin<br />
{<br />
    public Class1() { }<br />
<br />
    public String getInfo()<br />
    {<br />
        return "weeee";<br />
    }<br />
<br />
}<br />
<br />
public interface IPlugin<br />
{<br />
   String getInfo();<br />
}<br />
<br />
<br />
namespace DLL_LoadTest<br />
{<br />
    class Program<br />
    {<br />
        static void Main(string[] args)<br />
        {<br />
            Assembly assembly = Assembly.LoadFrom(@"C:\Test\ClassLibrary1\bin\Debug\ClassLibrary1.dll");<br />
                <br />
            IPlugin plugin = null;<br />
            plugin = (IPlugin)assembly.CreateInstance("Class1");<br />
        }<br />
    }<br />
}<br />


please help!

thanks,
HHG

-- modified at 10:21 Sunday 26th March, 2006
GeneralRe: Interface Type-casting problem Pin
Guffa26-Mar-06 4:27
Guffa26-Mar-06 4:27 
GeneralRe: Interface Type-casting problem Pin
hhrafn26-Mar-06 5:56
hhrafn26-Mar-06 5:56 
Questionerror handling in C# Pin
Mridang Agarwalla26-Mar-06 4:13
Mridang Agarwalla26-Mar-06 4:13 
AnswerRe: error handling in C# Pin
Guffa26-Mar-06 4:22
Guffa26-Mar-06 4:22 
GeneralRe: error handling in C# Pin
Mridang Agarwalla26-Mar-06 4:35
Mridang Agarwalla26-Mar-06 4:35 
QuestionWhy does this string not work? Pin
KaKa'26-Mar-06 3:55
KaKa'26-Mar-06 3:55 
AnswerRe: Why does this string not work? Pin
Guffa26-Mar-06 4:23
Guffa26-Mar-06 4:23 
GeneralRe: Why does this string not work? Pin
KaKa'26-Mar-06 13:31
KaKa'26-Mar-06 13:31 
GeneralRe: Why does this string not work? Pin
Christian Graus26-Mar-06 13:45
protectorChristian Graus26-Mar-06 13:45 
AnswerRe: Why does this string not work? Pin
Guffa27-Mar-06 0:11
Guffa27-Mar-06 0:11 
QuestionRunning Sql Script From C#? Pin
majidbhutta26-Mar-06 3:43
majidbhutta26-Mar-06 3:43 
AnswerRe: Running Sql Script From C#? Pin
Colin Angus Mackay26-Mar-06 3:53
Colin Angus Mackay26-Mar-06 3:53 
QuestionAn attempt was made to load a program with an incorrect format Pin
Colin Angus Mackay26-Mar-06 2:05
Colin Angus Mackay26-Mar-06 2:05 
AnswerRe: An attempt was made to load a program with an incorrect format [SOLVED] Pin
Colin Angus Mackay27-Mar-06 9:17
Colin Angus Mackay27-Mar-06 9:17 
QuestionGrid computing Pin
Mridang Agarwalla26-Mar-06 0:00
Mridang Agarwalla26-Mar-06 0:00 
AnswerRe: Grid computing Pin
Guffa26-Mar-06 1:17
Guffa26-Mar-06 1:17 
QuestionAnother small listview problem Pin
Mridang Agarwalla25-Mar-06 23:50
Mridang Agarwalla25-Mar-06 23:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.