473,385 Members | 1,730 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,385 software developers and data experts.

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.Reflection.Assembly assembly = null;

assembly = System.Reflection.Assembly.LoadFrom(_assemblyPath) ;

return assembly.CreateInstance(_typeName, false, System.Reflection.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.dll" 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 1746
Try ".\\" + _assemblyPath;
"RSS" <q> wrote in message news:%2******************@TK2MSFTNGP04.phx.gbl...
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.Reflection.Assembly assembly = null;

assembly = System.Reflection.Assembly.LoadFrom(_assemblyPath) ;

return assembly.CreateInstance(_typeName, false, System.Reflection.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.dll" 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.LoadFrom 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.GetExecutingAssembly().Location;

and then building the DLL name like this:

string dllPath = Path.Combine(Path.Combine(Path.GetPathRoot(exePath ),
Path.GetDirectoryName(exePath)), "My.dll");

?

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

Willy.

"RSS" <q> wrote in message news:%2******************@TK2MSFTNGP04.phx.gbl...
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.Reflection.Assembly assembly = null;

assembly = System.Reflection.Assembly.LoadFrom(_assemblyPath) ;

return assembly.CreateInstance(_typeName, false, System.Reflection.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.dll" 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.FileNotFoundException: File or assembly name My.Core.dll, or one of its dependencies, was not found.

File name: "My.Core.dll"

at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Boolean isStringized, Evidence assemblySecurity, Boolean throwOnFileNotFound, Assembly locationHint, StackCrawlMark& stackMark)

at System.Reflection.Assembly.InternalLoad(AssemblyNa me assemblyRef, Boolean stringized, Evidence assemblySecurity, StackCrawlMark& stackMark)

at System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)

at System.Activator.CreateInstanceFrom(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)

at My.Core.Typing.TypeDef.Instance(IDataReader dr)

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

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

at My.Core.Activities.ActivityType.GetById(Int32 id)

at My.Core.Activities.Activity.List(IDbConnection connection)

at My.Scheduling.SchedulingServer.Version2Processing( )

at My.Scheduling.SchedulingServer.ProcessingLoop(Obje ct stateInfo)

=== Pre-bind state information ===

LOG: Where-ref bind. Location = C:\WINDOWS\system32\My.Core.dll

LOG: Appbase = c:\program files\Mine\scheduleingsetup\

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**************@TK2MSFTNGP05.phx.gbl...
Please post the exact exception message.

Willy.

"RSS" <q> wrote in message news:%2******************@TK2MSFTNGP04.phx.gbl...
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.Reflection.Assembly assembly = null;

assembly = System.Reflection.Assembly.LoadFrom(_assemblyPath) ;

return assembly.CreateInstance(_typeName, false, System.Reflection.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.dll" 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\system32. Is your program a
windows service?
You might try the trick with Assembly.GetExecutingAssembly().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\system32. Is your program a
windows service?
You might try the trick with Assembly.GetExecutingAssembly().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
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...
1
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...
3
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
by: Marcel Balcarek | last post by:
I create a user control dynamically: Dim newCriteriaControl As CriteriaTextBoxUserControl = CType(Me._page.LoadControl("CriteriaTextBoxUserControl.ascx"), CriteriaTextBoxUserControl) ...
1
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...
1
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...
6
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...
9
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...
1
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.