how to Identify a type in an assembly ????

  • Thread starter serge calderara
  • Start date
S

serge calderara

Dear all,

I need to be sure that a loaded assembly is implementing a
particular interface.

How can I do that as long as my assembly is loaded and I
have the assemlby object available in current domain as
follow:

Dim ass As System.Reflection.Assembly
Dim loadass As System.Reflection.Assembly
loadass = ass.LoadFrom(sFile)

thanks for your help
regards

calderara serge
maillefer s.a
 
M

Mattias Sjögren

I need to be sure that a loaded assembly is implementing a
particular interface.

Assemblies don't implement interfaces, types do.

Dim ass As System.Reflection.Assembly
Dim loadass As System.Reflection.Assembly
loadass = ass.LoadFrom(sFile)

You don't need to declare a variable (ass) to call Shared methods such
as Load. You can simply do

loadass = System.Reflection.Assembly.LoadFrom(sFile)

You can get all types in the assembly with Assembly.GetTypes(), and
check each if it implements a certain interface with
Type.IsAssignableFrom().



Mattias
 
C

calderara serge

I have try what you suggest like :

loadass = System.Reflection.Assembly.LoadFrom(sFile)
then geting the types by :

dim obj() as type
obj=loadass.getTypes()

then I get an error saying that all types cannot be loaded ?

whats that ?

thanks for your information
serge
 
C

calderara serge

Hello,

I have tried to retrieve all interface defines in an assembly as follow
:

objType = ass.GetType()
t = objType.GetInterfaces

The assembly is one that I have created and when using GetInterfaces
methode I retrive interface of the assembly but only the system
reflexion runtime interface. It cannot retrives my own interface that I
include in assembly by implements keywords.

how to retrive my own interface ?

thnaks for your help
regards
serge
 
P

Phil Wilson

As has been pointed out previously, assemblies don't implement interfaces. Your
assembly might have dozens of classes in it, and some of those might implement
your interface, so I suspect what you want to do is enumerate the Types in the
assembly that are classes, and then see if those classes implement your
interface.
 
S

serge calderara

Hello,

I have tried as you mentionned to get the type with
ass.GetTypes. It was for working fin for a while and since
today without having change any thing in my code I get an
error when executing the ass.GetTypes saying :

"One or more of the types in the assembly unable to load."

What does it means and why it hapens now ?
any iadeas?

thnaks for your help
regards
serge
 
M

Mattias Sjögren

"One or more of the types in the assembly unable to load."

What does it means and why it hapens now ?
any iadeas?

Serge,

If you catch the exception and take a close look at it (Message,
InnerException and other properties), does it tell you any more about
which type it fails to load?



Mattias
 
C

calderara serge

Hello

Thnaks for your answer, I found out what was the problem

regards
serge
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top