473,786 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assembly.LoadFr om() 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(FileN ame)

throws the following exception:

System.Reflecti on.ReflectionTy peLoadException : One or more of the types in the assembly unable to load.
at System.Reflecti on.Module.GetTy pesInternal(Sta ckCrawlMark& stackMark)
at System.Reflecti on.Assembly.Get Types()
at Stegosoft.Assem blySniffer.Form 1.ScanAssembly( String FileName) in ........

Any sugestions?

TIA,
Michael
Nov 21 '05 #1
11 2713
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******** ******@TK2MSFTN GP11.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(FileN ame)

throws the following exception:

System.Reflecti on.ReflectionTy peLoadException : One or more of the types in the assembly unable to load.
at System.Reflecti on.Module.GetTy pesInternal(Sta ckCrawlMark& stackMark)
at System.Reflecti on.Assembly.Get Types()
at Stegosoft.Assem blySniffer.Form 1.ScanAssembly( String 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/cpgrfFusionLogV iewerFuslogvwex e.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******** ******@TK2MSFTN GP12.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/cpgrfFusionLogV iewerFuslogvwex e.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/
frlrfsystemrefl ectionassemblyc lassloadtopic3. asp
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemRefl ectionAssemblyC lassLoadFromTop ic.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 #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. (ReflectionType LoadException: 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 SatteliteAssemb lies.

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.Reflecti on. Reflector uses it's own
infrastructure for reading assembly files at the binary level (look at
the Reflector.CodeM odel namespace). That might explain why your file
loads in Reflector but not using Assembly.LoadFr om().
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.WriteLi ne(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.Reflecti on
Module Module1
Sub Main()
Dim ass As [Assembly] =
[Assembly].LoadFrom("<pat h>\ChildrenClas s.dll")
Dim t As Type = ass.GetType("Ch ildrenClass.Chi ldClass")
Dim o As Object = Activator.Creat eInstance(t,
BindingFlags.Cr eateInstance, Nothing, New Object() {}, Nothing, Nothing)
t.InvokeMember( "T", BindingFlags.In vokeMethod, 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/
frlrfsystemrefl ectionassemblyc lassloadfiletop ic1.asp

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

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

Similar topics

4
2884
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 on the disk. Each plugin defines a class which implements an interface known to the app. The main app loads the plugin with Assembly.LoadFrom and then uses Assembly.GetTypes() and Type.FindInterface to find the concrete types in the plugin that...
4
2598
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". I do in fact have a reference to the assembly in question in the project and I even tried declaring it with "using" at the top of the class file. Here's the method that fails:
7
3044
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 application it works perfectly fine, but when the assembly containing the reference is load from a windows service an exception is thrown with the following message: "File or assembly name Interop.WMEncoderLib, or one of its dependencies, was not...
1
2907
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 asmAssemblyContainingForm As = .LoadFrom("neiconv.dll") Dim TypeToLoad As Type = asmAssemblyContainingForm.GetType("neiconv.Frm_ND")
6
44489
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 = @"C:\PMDRepository\Tools\ManfBusProcMgr\Modules\TestModule\bin\Debug\TestModule"; Assembly a = Assembly.Load(modulePath); </code>
6
1839
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: Assembly.LoadFrom("C:\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\ ...\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\ MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\...
4
4475
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 application dll). It's been working for months and now the it's not working from my application exe anymore but still working from NUnit when testing the dll. What could have changed in my exe? Some configuration thing in my VS2005 project?
2
5100
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 pluginHandle = Activator.CreateInstanceFrom(assemblyName, type); object plugin = pluginHandle.Unwrap(); ....
4
1400
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 website now fails with FileNotFound on a call to Assembly.LoadFrom(url). This still works fine on all XP SP2 systems in the company. 2. Maybe related... Our Intranet hosts a couple of csharp user controls in
0
9492
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9960
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.