468,161 Members | 2,092 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,161 developers. It's quick & easy.

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

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
Jul 21 '05 #1
8 3194
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #3
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #4
GetTypes() returns an array of type objects, not a single one, so that might
be causing some problems.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://weblogs.asp.net/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"calderara serge" <se*************@maillefer.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 21 '05 #5
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.
--
Phil Wilson [MVP Windows Installer]
----
"calderara serge" <se*************@maillefer.net> wrote in message
news:ex**************@tk2msftngp13.phx.gbl...
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 21 '05 #6
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
-----Original Message-----
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 suchas Load. You can simply do

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

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

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.comPlease reply only to the newsgroup.
.

Jul 21 '05 #7
"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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #8

Hello

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

regards
serge
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by DraguVaso | last post: by
8 posts views Thread by serge calderara | last post: by
reply views Thread by kamranasdasdas | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.