473,396 Members | 1,849 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,396 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 3409
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.