473,216 Members | 2,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

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 3400
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: DraguVaso | last post by:
Hi, I want my application do different actions depending on the exception it gets. For exemple: I have an SQL-table with a unique index. In case I try to Insert a record that's alreaddy in it I...
3
by: Kelmen Wong | last post by:
Greeting, Anyone know any tool to identify whether an assembly is in Debug or Release? I can use "Dependency Walker" from VS 6. How about VS .NET? Got anything tool like that?
11
by: Neo | last post by:
Does anyone know how to get a list of the types in an Assembly without actually loading the Assembly into your app domain?
8
by: serge calderara | last post by:
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...
7
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.