473,320 Members | 1,933 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,320 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 3405
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}"...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.