473,396 Members | 1,843 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.

Assembly.LoadFrom() fails

Hello,

I want to be able to load an assembly by selecting a dll from an OpenFileDialog.
This seems to work, exept when that assembly references "3rd-Party dll's".

Just this simple line:

Dim myAssembly As [Assembly] = [Assembly].LoadFile(FileName)

throws the following exception:

System.Reflection.ReflectionTypeLoadException: One or more of the types in the assembly unable to load.
at System.Reflection.Module.GetTypesInternal(StackCra wlMark& stackMark)
at System.Reflection.Assembly.GetTypes()
at Stegosoft.AssemblySniffer.Form1.ScanAssembly(Strin g FileName) in ........

Any sugestions?

TIA,
Michael
Nov 21 '05 #1
11 2660
Are these 3rd party dll's .NET assemblies ?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Michael Maes" <mi*****@merlot.com> wrote in message news:eE**************@TK2MSFTNGP11.phx.gbl...
Hello,

I want to be able to load an assembly by selecting a dll from an OpenFileDialog.
This seems to work, exept when that assembly references "3rd-Party dll's".

Just this simple line:

Dim myAssembly As [Assembly] = [Assembly].LoadFile(FileName)

throws the following exception:

System.Reflection.ReflectionTypeLoadException: One or more of the types in the assembly unable to load.
at System.Reflection.Module.GetTypesInternal(StackCra wlMark& stackMark)
at System.Reflection.Assembly.GetTypes()
at Stegosoft.AssemblySniffer.Form1.ScanAssembly(Strin g FileName) in ........

Any sugestions?

TIA,
Michael
Nov 21 '05 #2
Hi Michael,

Can you use the 3rd-party assembly by referencing them directly instead of
using them by reflection?
Also the 3rd-party assembly may need some dependent module which may cause
the problem.
You may try to use the Fuslogvw.exe tool to see if there is any fusion
error during the assembly binding.
Assembly Binding Log Viewer (Fuslogvw.exe)
http://msdn.microsoft.com/library/de...us/cptools/htm
l/cpgrfFusionLogViewerFuslogvwexe.asp
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #3
Hi Terry,

Yes, this happens when a Janus System (v2) Assembly gets involved.
The only thing I want to obtain is scan (a lot) of assemblies to draw an "Object Model".
Lutz Roeder's .NET Reflector can load the assemblies so I guess I'm using the wrong approach....

Regards,

Michael
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:uZ**************@TK2MSFTNGP12.phx.gbl...
Are these 3rd party dll's .NET assemblies ?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
Nov 21 '05 #4
Hi Peter,

I feel like "an idiot" here...
I've got the tool running, but how do I load an assembly into it?

I guess this is going to be a "blue monday" for me.

B.T.W.: Lutz Roeder's .NET Reflector can load the assemblies so I guess I'm
using the wrong approach....

Regards,

Michael
Nov 21 '05 #5
Hi Michael,

To use the tool, we may just run the Fuslogvw.exe, which will show us the
assembly binding information.
You may try to follow the steps in the link below.
Assembly Binding Log Viewer (Fuslogvw.exe)
http://msdn.microsoft.com/library/de...us/cptools/htm
l/cpgrfFusionLogViewerFuslogvwexe.asp
You may pay attention to the Other Configuration Settings section.

Also you may try to use the LoadFrom or Load method to see if that help you.
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemreflectionassemblyclassloadtopic3.asp
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemReflectionAssemblyClassLoadFromTopic.as p

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #6
Hi Peter,

Indeed the SatteliteDll's don't get loaded.
These are assemblies from which the assembly being scanned is a subclass.

EG:

Assembly A (Parent) & Assembly B (Child)
B inherits from A
If I scan B the LoadFrom-Method fails. (ReflectionTypeLoadException: One or more of the types in the assembly unable to load.)
If I scan A it works fine.

So I guess the LoadFrom-Method doesn't load the SatteliteAssemblies.

Since it can load the Parent-Assembly directly, I don't understand why it can't load it through the derived Assembly.

Any further suggestions?

Thanks,
Michael
Nov 21 '05 #7
Reflector does not use System.Reflection. Reflector uses it's own
infrastructure for reading assembly files at the binary level (look at
the Reflector.CodeModel namespace). That might explain why your file
loads in Reflector but not using Assembly.LoadFrom().
Nov 21 '05 #8
Hi Michael,

Based on my test, it seems that if the inherited class in not in the same
assembly of parent class, we can load the assembly.
Here is my test result.
[ParentClass]
Public Class PC
Public mem As Integer
Public Sub New()
mem = 1
End Sub
Public Sub Test()
Console.WriteLine(mem)
End Sub
End Class

[ChildrenClass]
Public Class ChildClass
Inherits ParentClass.PC
Public Sub New()
Me.mem = 2
End Sub
Public Sub T()
Me.Test()
End Sub
End Class

Imports System.Reflection
Module Module1
Sub Main()
Dim ass As [Assembly] =
[Assembly].LoadFrom("<path>\ChildrenClass.dll")
Dim t As Type = ass.GetType("ChildrenClass.ChildClass")
Dim o As Object = Activator.CreateInstance(t,
BindingFlags.CreateInstance, Nothing, New Object() {}, Nothing, Nothing)
t.InvokeMember("T", BindingFlags.InvokeMethod, Nothing, o, New
Object() {}, Nothing, Nothing, Nothing)
End Sub
End Module

You may try the code above to see if that help you.

As for your scnario, can you send me the a simple reproduce sample by
removing the "Online" from my email address with detailed reproduce steps.
Also have you tried my suggestion that use the load method instead, did
that work for you?

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #9
Hi Michael,

It seems that the problem is caused by the difference between loadfile and
loadfrom. For this scenario, the loadfrom will be a proper method.
Remarks
Use the LoadFile method to load and examine assemblies that have the same
identity, but are located in different paths. Do not use LoadFile to load
assemblies that you want to execute. LoadFile does not load files into the
LoadFrom context, and does not resolve dependencies using the load path, as
the LoadFrom method does. LoadFile is useful in this limited scenario
because LoadFrom cannot be used to load assemblies that have the same
identities but different paths; it will load only the first such assembly.

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemreflectionassemblyclassloadfiletopic1.a sp

If we change the loadfile to loadfrom in your reproduce sample, it will
solve the problem, you may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #10
Hi Peter,

It does seem to solve the issue.
Thanks for your time (once again).

Kind regards,

Michael
Nov 21 '05 #11
Hi Andre,

Thanks for your input.
You "unintendedly" brought my attention to some Reflector Plug-Inns, ...,
wow!

Kind regards,

Michael

BTW: The issue has been solved :-) so I'm (twice) glad!
Nov 21 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Arnaud Debaene | last post by:
Hello group. I have an app which can load "plugins" assemblies that are described in the registry (each registry entry gives the full path to the plugin ..dll file). The plugins may be anywhere...
4
by: V. Jenks | last post by:
I'm using reflection to dynamically load an assembly and even though I'm sure the assembly is present, I keep getting an error telling me the "assembly or one of its references can't be found". ...
7
by: Ollie Riches | last post by:
I am trying to dynamically load an assembly that has a reference to 'Interop.WMEncoderLib.dll' which is a PIA to the windows media player DRM components. When I run the code from a console...
1
by: lgbjr | last post by:
Hi All, I am moving some of my MDI Child forms to DLLs. The first 3 forms worked fine. But the 4th one is causing me some grief! I use the following code to load a form from a DLL: Dim...
6
by: Steve | last post by:
I'm playing with late binding and trying a very simple test to load an assembly In my "Host" application I have this code: <code> string modulePath =...
6
by: shrishjain | last post by:
Hi All, I call Assembly.LoadFrom("C:\\MyDir\\MyAssembly.dll")- it works fine. However when I call the following, it fails: ...
4
by: =?Utf-8?B?SmFu?= | last post by:
I have a .NET 2.0 application divided in two assemblies; the exe and a dll. The application generates a plugin-dll which is then loaded in a separate AppDomain (along with a second instance of my...
2
by: christopher.watford | last post by:
I'm loading a plugin assembly using Activator.CreateInstanceFrom, and inside this assembly is a settings class which gets serialized to XML. The general code flow is as follows: ObjectHandle...
4
by: James | last post by:
Hi, I have just upgraded a user machine to Vista (our first) as a test. Unfortunately a couple of our apps are failing due to Vista... 1. One app that loads an assembly from an Intranet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.