473,545 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comparing same interface type returns false, Why?

Hi all,

Using Windows CP Pro
VS .net 2005

I'm creating an app that allows user to extend its functionality by
installing plug in modules, these modules support an interface I have
created called IPlugInInterfac e. The problem is when I come to load them
I check each dll to see if supports this interface, they all return
false even though when I inspect them during debugging they look the
same, I use the following function:

public ArrayList SearchPath(stri ng dir, AppDomain domain)
{
ArrayList ar = new ArrayList();

foreach (string File in System.IO.Direc tory.GetFiles(d ir, "*.dll"))
{
try
{
Type ct = typeof(TestName space.PlugIn.IP lugInInterface) ;
System.Reflecti on.Assembly asm =
System.Reflecti on.Assembly.Loa dFrom(File);

foreach (Type t in asm.GetTypes())
{
foreach (Type iface in t.GetInterfaces ())
{
//*************** *************** *
// see text below
//*************** *************** *
if (ct.IsAssignabl eFrom(iface))
{
ar.Add(t);
break;
}
}
}
}
catch (Exception ex)
{
}
}
return ar;
}
//*************** ***

this is where the problem occurs, if I inspect both ct and iface both
seem to be of the same type, ie namespace and name etc but the call to
IsAssignableFro m always returns false.

Any ideas

TIA

Joe
Nov 17 '05 #1
5 3166
Hi, Joe.

The plug in classes would have to implement the exact same interface, not
only the namespace qualified interface name, but also the same assembly and
version. Check AssemblyQualifi edName property of both types, they have to be
the same for IsAssignableFro m to return true.

--
Ming Chen
http://engdump.blogspot.com/
"Joe Black" <Jo******@newsg roup.nospam> wrote in message
news:eX******** ******@TK2MSFTN GP14.phx.gbl...
Hi all,

Using Windows CP Pro
VS .net 2005

I'm creating an app that allows user to extend its functionality by
installing plug in modules, these modules support an interface I have
created called IPlugInInterfac e. The problem is when I come to load them I
check each dll to see if supports this interface, they all return false
even though when I inspect them during debugging they look the same, I use
the following function:

public ArrayList SearchPath(stri ng dir, AppDomain domain)
{
ArrayList ar = new ArrayList();

foreach (string File in System.IO.Direc tory.GetFiles(d ir, "*.dll"))
{
try
{
Type ct = typeof(TestName space.PlugIn.IP lugInInterface) ;
System.Reflecti on.Assembly asm =
System.Reflecti on.Assembly.Loa dFrom(File);

foreach (Type t in asm.GetTypes())
{
foreach (Type iface in t.GetInterfaces ())
{
//*************** *************** *
// see text below
//*************** *************** *
if (ct.IsAssignabl eFrom(iface))
{
ar.Add(t);
break;
}
}
}
}
catch (Exception ex)
{
}
}
return ar;
}
//*************** ***

this is where the problem occurs, if I inspect both ct and iface both seem
to be of the same type, ie namespace and name etc but the call to
IsAssignableFro m always returns false.

Any ideas

TIA

Joe

Nov 17 '05 #2
Ming Chen wrote:
Hi, Joe.

The plug in classes would have to implement the exact same interface, not
only the namespace qualified interface name, but also the same assembly and
version. Check AssemblyQualifi edName property of both types, they have to be
the same for IsAssignableFro m to return true.


Hi Ming,

I have the interface declared within an external DLL file as follows

public interface IPlugInInterfac e
{
#region Variable declaration

int PlugInType { get;}
string PlugInName { get;}
string PlugInDescripti on { get;}
string PlugInShortDesc ription { get;}
int PlugInMajorVers ion { get;}
int PlugInMinorVers ion { get;}
char PlugInRevision { get;}
string PlugInGuid { get;}
string PlugInReleaseDa te { get;}
string PlugInAuthor { get;}
string PlugInAuthorInf ormation { get;}
bool RequiresRegistr ation { get;}

#endregion

#region Member function declaration

void PerformAction(I PlugInContext context);
void ShowForm(System .Windows.Forms. Control parent);

#endregion
}

I then declare my class:

public class MyPlugin:IPlugI nInterface
{
//code goes here
}

Does this not mean I am using the exact same interface, or am I missing
something?

Your help is appreciated.

Joe
Nov 17 '05 #3
You have to declare the interface in a single assembly for all PlugIns and
having all other assemblies reference to this one. .NET class/interface have
their own internal type identifier hence they are not simply matched base on
memory layout. Types declared in different dlls are different types even if
their definitions are exactly the same.

For example, you can create a dll (PluginInterfac e.dll) which contains
nothing but the definition of the interface, then create individual PlugIn
classes by adding reference to this dll.

--
Ming Chen
http://engdump.blogspot.com/
"Joe Black" <Jo******@newsg roup.nospam> wrote in message
news:OA******** *****@TK2MSFTNG P15.phx.gbl...
Ming Chen wrote:
Hi, Joe.

The plug in classes would have to implement the exact same interface,
not only the namespace qualified interface name, but also the same
assembly and version. Check AssemblyQualifi edName property of both types,
they have to be the same for IsAssignableFro m to return true.


Hi Ming,

I have the interface declared within an external DLL file as follows

public interface IPlugInInterfac e
{
#region Variable declaration

int PlugInType { get;}
string PlugInName { get;}
string PlugInDescripti on { get;}
string PlugInShortDesc ription { get;}
int PlugInMajorVers ion { get;}
int PlugInMinorVers ion { get;}
char PlugInRevision { get;}
string PlugInGuid { get;}
string PlugInReleaseDa te { get;}
string PlugInAuthor { get;}
string PlugInAuthorInf ormation { get;}
bool RequiresRegistr ation { get;}

#endregion

#region Member function declaration

void PerformAction(I PlugInContext context);
void ShowForm(System .Windows.Forms. Control parent);

#endregion
}

I then declare my class:

public class MyPlugin:IPlugI nInterface
{
//code goes here
}

Does this not mean I am using the exact same interface, or am I missing
something?

Your help is appreciated.

Joe

Nov 17 '05 #4
Ming Chen wrote:
You have to declare the interface in a single assembly for all PlugIns and
having all other assemblies reference to this one. .NET class/interface have
their own internal type identifier hence they are not simply matched base on
memory layout. Types declared in different dlls are different types even if
their definitions are exactly the same.

For example, you can create a dll (PluginInterfac e.dll) which contains
nothing but the definition of the interface, then create individual PlugIn
classes by adding reference to this dll.


Thanks Ming,

I found that I had a copy of the dll that implemented the
IPlugInInterfac e in the same directory that the dll with the actual plug
in was in, this seemed to cause the appdomain to look at that copy of
the IPlugInInterfac e, hence the failure of the function call.

Many thanks for your help

Joe
Nov 17 '05 #5
hi, plz try the following (it always works 4 me)

Type _type = somePlugIn.GetT ype();

foreach (Type iface in _type.GetInterf aces()) {
if (iface == typeof(IPlugInI nterface)) {
//do some magic
}
}

regards
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
8639
by: Kill Bill | last post by:
type(i) == "<type 'float'>" this always returns false. How come? type(i)returns <type 'float'> if i is a float so why isn't == working?
0
1419
by: Farek | last post by:
(If Im posting in the wrong place concerning COM+ and .NET plz redirect me.) Hello all, Im writing a COM+ in VB.NET that is suppose to be able to set/get an address(String value). I've made a seperate project that contains all interfaces Im using in my entire project. But whenever I try to include the Interface in the COM+ class the...
3
1487
by: Simon Harvey | last post by:
Hi all, I hope someone can help me with the following: I have a number of usercontrols that I've made which provides certain audit functions for any data inserted into it. Each audit control is a descendant of BaseAuditControl. Descedants include AuditableTextControl and AuditableBoolControl. The problem I'm having is determining which...
19
2626
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor = Color.Empty then..... or if mycolor is Color.Empty then .......
19
3810
by: Ole Nielsby | last post by:
How does the GetHashCode() of an array object behave? Does it combine the GetHashCode() of its elements, or does it create a sync block for the object? I want to use readonly arrays as dictionary keys, based on their content, not their identity. Is this feasible using the arrays directly, or do I need to wrap them in a struct that...
0
2201
by: Ken | last post by:
Hi I have a little application that does datavalidation. It supports dynamically loaded plugins (you drop a dll with a class implementing IValidator<Tin the same dir as the main application). All classes that implement this interface are shown in a drop down in a DataGridViewComboBoxColumn named Validator. By choosing the class to...
8
1983
by: Lamefif | last post by:
// C3DRect supports IDraw and IShapeEdit. class C3DRect : public IDraw, public IShapeEdit { public: C3DRect(); virtual ~C3DRect(); // IDraw virtual void Draw(); // IShapeEdit virtual void Fill (FILLTYPE fType);
4
1727
by: jmDesktop | last post by:
In the code below from MSDN How do the PeopleEnum methods ever get called? foreach (Person p in peopleList) Console.WriteLine(p.firstName + " " + p.lastName); What is going on behind the scenes in the foreach? Also, I could not find where the interface signatures were for the
0
195
by: =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post by:
D'Arcy J.M. Cain wrote: I can give you the technical answer after reading the sources of the decimal module: you can only compare to Decimal what can be converted to Decimal. And that is int, long and another Decimal. Everything else will return False when comparing. Yes, but only if comparison from type(A) to type(C) is supported at...
0
7464
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7396
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7413
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5323
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3440
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.