PC Review


Reply
Thread Tools Rate Thread

DLL does not load Dynamically

 
 
RSS
Guest
Posts: n/a
 
      27th Apr 2006
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.

 
Reply With Quote
 
 
 
 
AMDRIT
Guest
Posts: n/a
 
      27th Apr 2006
Try ".\\" + _assemblyPath;
"RSS" <q> wrote in message news:%235F%(E-Mail Removed)...
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.

 
Reply With Quote
 
Bruce Wood
Guest
Posts: n/a
 
      27th Apr 2006
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");

?

 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      27th Apr 2006
Please post the exact exception message.

Willy.

"RSS" <q> wrote in message news:%235F%(E-Mail Removed)...
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.

 
Reply With Quote
 
RSS
Guest
Posts: n/a
 
      27th Apr 2006
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(AssemblyName 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(Object 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]" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
Please post the exact exception message.

Willy.

"RSS" <q> wrote in message news:%235F%(E-Mail Removed)...
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.

 
Reply With Quote
 
.neter
Guest
Posts: n/a
 
      28th Apr 2006
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.
 
Reply With Quote
 
RSS
Guest
Posts: n/a
 
      28th Apr 2006
Yes it is a windows service


".neter" <(E-Mail Removed)> wrote in message
news:e2sois$s38$(E-Mail Removed)...
> 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.



 
Reply With Quote
 
adi
Guest
Posts: n/a
 
      11th May 2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to dynamically load dll ? chandu Microsoft C# .NET 1 27th Sep 2006 09:17 AM
DLL does not load Dynamically RSS Microsoft Dot NET Framework 7 11th May 2006 03:56 PM
Dynamically load add-ins =?Utf-8?B?SGVhdGg=?= Microsoft Dot NET 1 13th Apr 2005 07:18 AM
Load User Control Dynamically, Cast object dynamically =?Utf-8?B?UmV6YSBOYWJp?= Microsoft ASP .NET 1 5th Mar 2005 01:04 AM
Load User Control Dynamically, Cast object dynamically =?Utf-8?B?UmV6YSBOYWJp?= Microsoft ASP .NET 1 4th Mar 2005 08:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:52 PM.