473,793 Members | 2,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DLL does not load Dynamically

RSS
Hi everyone,
I have an app that uses some DLL's that are shared across couple applications. There are reasons existing that prevent me from putting them in to the GAC.

Each of these app's at some point in time loads a DLL dynamically in this fashion:

System.Reflecti on.Assembly assembly = null;

assembly = System.Reflecti on.Assembly.Loa dFrom(_assembly Path);

return assembly.Create Instance(_typeN ame, false, System.Reflecti on.BindingFlags .Default, null, args, null, null);

_assemblyPath - DB driven that has a value for path. Now, if I have a path like this "C:\Mypath\My.d ll" everything works fine. If I only have "My.dll" i get an error message saying the My.dll or one of its dependencies cannot be found. The exe and My.dll reside in the same folder and by default it should load when _assemblyPath = My.dll.

Any idea why its not working.

thanks a lot in advance.

Apr 27 '06 #1
7 1730
Try ".\\" + _assemblyPath;
"RSS" <q> wrote in message news:%2******** **********@TK2M SFTNGP04.phx.gb l...
Hi everyone,
I have an app that uses some DLL's that are shared across couple applications. There are reasons existing that prevent me from putting them in to the GAC.

Each of these app's at some point in time loads a DLL dynamically in this fashion:

System.Reflecti on.Assembly assembly = null;

assembly = System.Reflecti on.Assembly.Loa dFrom(_assembly Path);

return assembly.Create Instance(_typeN ame, false, System.Reflecti on.BindingFlags .Default, null, args, null, null);

_assemblyPath - DB driven that has a value for path. Now, if I have a path like this "C:\Mypath\My.d ll" everything works fine. If I only have "My.dll" i get an error message saying the My.dll or one of its dependencies cannot be found. The exe and My.dll reside in the same folder and by default it should load when _assemblyPath = My.dll.

Any idea why its not working.

thanks a lot in advance.

Apr 27 '06 #2
Just a stab in the dark... when you start the application, what is the
"Start in" current directory?

If you're running from a CMD command line, do you switch directories to
C:\Mypath and then run the app, or run it from wherever the current
directory is?

If you're running it from a desktop shortcut, what is your "Start in"
path set to?

I would assume that Assembly.LoadFr om would attempt to load from the
current directory if no path is specified, which may not be the same as
the directory where the executing assembly resides.

If you always want the latter behaviour, have you tried getting the
location of the running assembly using

string exePath = Assembly.GetExe cutingAssembly( ).Location;

and then building the DLL name like this:

string dllPath = Path.Combine(Pa th.Combine(Path .GetPathRoot(ex ePath),
Path.GetDirecto ryName(exePath) ), "My.dll");

?

Apr 27 '06 #3
Please post the exact exception message.

Willy.

"RSS" <q> wrote in message news:%2******** **********@TK2M SFTNGP04.phx.gb l...
Hi everyone,
I have an app that uses some DLL's that are shared across couple applications. There are reasons existing that prevent me from putting them in to the GAC.

Each of these app's at some point in time loads a DLL dynamically in this fashion:

System.Reflecti on.Assembly assembly = null;

assembly = System.Reflecti on.Assembly.Loa dFrom(_assembly Path);

return assembly.Create Instance(_typeN ame, false, System.Reflecti on.BindingFlags .Default, null, args, null, null);

_assemblyPath - DB driven that has a value for path. Now, if I have a path like this "C:\Mypath\My.d ll" everything works fine. If I only have "My.dll" i get an error message saying the My.dll or one of its dependencies cannot be found. The exe and My.dll reside in the same folder and by default it should load when _assemblyPath = My.dll.

Any idea why its not working.

thanks a lot in advance.

Apr 27 '06 #4
RSS
An unexpected exception was handled while processing job requests.

System.IO.FileN otFoundExceptio n: File or assembly name My.Core.dll, or one of its dependencies, was not found.

File name: "My.Core.dl l"

at System.Reflecti on.Assembly.nLo ad(AssemblyName fileName, String codeBase, Boolean isStringized, Evidence assemblySecurit y, Boolean throwOnFileNotF ound, Assembly locationHint, StackCrawlMark& stackMark)

at System.Reflecti on.Assembly.Int ernalLoad(Assem blyName assemblyRef, Boolean stringized, Evidence assemblySecurit y, StackCrawlMark& stackMark)

at System.Reflecti on.Assembly.Loa dFrom(String assemblyFile, Evidence securityEvidenc e, Byte[] hashValue, AssemblyHashAlg orithm hashAlgorithm)

at System.Activato r.CreateInstanc eFrom(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttri butes, Evidence securityInfo)

at My.Core.Typing. TypeDef.Instanc e(IDataReader dr)

at My.Core.Typing. Type.CacheType( String typeName)

at My.Core.Typing. Type.GetById(St ring typeName, Int32 typeId)

at My.Core.Activit ies.ActivityTyp e.GetById(Int32 id)

at My.Core.Activit ies.Activity.Li st(IDbConnectio n connection)

at My.Scheduling.S chedulingServer .Version2Proces sing()

at My.Scheduling.S chedulingServer .ProcessingLoop (Object stateInfo)

=== Pre-bind state information ===

LOG: Where-ref bind. Location = C:\WINDOWS\syst em32\My.Core.dl l

LOG: Appbase = c:\program files\Mine\sche duleingsetup\

LOG: Initial PrivatePath = NULL

Calling assembly : (Unknown).

===

LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).

LOG: Attempting download of new URL file:///C:/WINDOWS/system32/My.Core.dll.

"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message news:OH******** ******@TK2MSFTN GP05.phx.gbl...
Please post the exact exception message.

Willy.

"RSS" <q> wrote in message news:%2******** **********@TK2M SFTNGP04.phx.gb l...
Hi everyone,
I have an app that uses some DLL's that are shared across couple applications. There are reasons existing that prevent me from putting them in to the GAC.

Each of these app's at some point in time loads a DLL dynamically in this fashion:

System.Reflecti on.Assembly assembly = null;

assembly = System.Reflecti on.Assembly.Loa dFrom(_assembly Path);

return assembly.Create Instance(_typeN ame, false, System.Reflecti on.BindingFlags .Default, null, args, null, null);

_assemblyPath - DB driven that has a value for path. Now, if I have a path like this "C:\Mypath\My.d ll" everything works fine. If I only have "My.dll" i get an error message saying the My.dll or one of its dependencies cannot be found. The exe and My.dll reside in the same folder and by default it should load when _assemblyPath = My.dll.

Any idea why its not working.

thanks a lot in advance.

Apr 27 '06 #5
RSS wrote:
An unexpected exception was handled while processing job requests.

(...)

It is looking for the file in C:\windows\syst em32. Is your program a
windows service?
You might try the trick with Assembly.GetExe cutingAssembly( ).Location
posted above.
Apr 28 '06 #6
RSS
Yes it is a windows service
".neter" <gw*****@poczta .onet.pl> wrote in message
news:e2******** **@news.onet.pl ...
RSS wrote:
An unexpected exception was handled while processing job requests.

(...)

It is looking for the file in C:\windows\syst em32. Is your program a
windows service?
You might try the trick with Assembly.GetExe cutingAssembly( ).Location
posted above.

Apr 28 '06 #7
adi
hi,

the "best" solution (only my opinion)

1) keep the interfaces of your libs compatible => signatures of public
props+methods
(the best is only 1 version of your lib in gac + publisher policy)

2) deploy your libs in the GAC, but only with publisher policies!
this will redirect your "old" clients to the new versions of your libs

loading manualy your libs may not be good for the code maintenance of
your libs ...

adrian

May 11 '06 #8

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

Similar topics

1
2758
by: Ron Vecchi | last post by:
I am using the FlashShockWave COM object. in the form design mode I specified the Flash Movie .SWF local path. and it loads correctly. My problem is that if I make changes to the swf file it never is changed in the EXE. It seem to be embedded. I have to remove the object and then add a new object for the changes to take effect.
1
3992
by: TIM T | last post by:
I want to load a user control from a dll dynamically to my main form. I have been reading about using reflection. I got this to work with the methods from my other classes in the dll but I am not sure how to load a user control onto my main form. If somebody could explains this to me or know if any examples any help would be appreciated. Thanks Tim
3
1678
by: Boni | last post by:
Dear Sirs, If I dynamically load assembly into the memory by Load(byte) how long do I have to preserve the array valid? Can it be destructed just after the load call? Thanks in advance, Boni
1
2803
by: Marcel Balcarek | last post by:
I create a user control dynamically: Dim newCriteriaControl As CriteriaTextBoxUserControl = CType(Me._page.LoadControl("CriteriaTextBoxUserControl.ascx"), CriteriaTextBoxUserControl) myContainer.Add(newCriteriaControl) and the user control's load event executes on initial executon of the page. On a POST of the same page, the control is added as above, but the load event is not firing, nor is prerender.
1
1746
by: Nancy Sui | last post by:
I am trying to dynamically load a dll which specifies different rules for evalution with the following code. DataRow dr = ds.Tables.Rows; string fileName = Convert.ToString(dr); assemblyInstance = Assembly.Load( fileName ); typeInstance = assemblyInstance.GetType( "MSF.Storefront.Rules." + dr.ToString() , true, false); Object parameter = new Object; if (seg == null) parameter = cs;
1
1022
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a variable (targetId) in to the usercontrol (IntergySite.aspx) by calling its setter method. Currently, I am using if-then-else and hardcoded the User Control Object to do casting and call the setter method. Question: Is there any way I could load,...
6
2058
by: hitendra15 | last post by:
Hi I have created web user control which has Repeater control and Linkbutton in ItemTemplate of repeater control, following is the code for this control On first load it runs fine but when page gets post back it gives following error Failed to load viewstate. The control tree into which viewstate is
9
7042
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related to VB, plus the address bar would show something like this: www.somethinghere?id=3 and if you change number 3 from the address bar to (for example) 34 or 71 you would get different page with the same formatting like I.e: www.somethinghere?id=34...
1
1968
by: chandu | last post by:
hello , i want to load and execute an existing dll in a applicaiton dynamically with out giving references etc... need to create separate appdomain or in same appdomain can i load and execute the assembly dynamically.......... please give me some idea..
2
4406
by: Nick | last post by:
I have two navigation user controls and based on a query string will load one or the other. On the page that will load the user control I cannot do the following Dim uc As FlashNavigation (The name of the code behind class) I also can't do CType(uc, FlashNavigation) I get Type 'FlashNavigation' is not defined. How can I dynamically load a user control then access it's properties and or methods?
0
9671
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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
10433
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
10212
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
10000
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
7538
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
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
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...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.