PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET DLL does not load Dynamically

Reply

DLL does not load Dynamically

 
Thread Tools Rate Thread
Old 27-04-2006, 08:20 PM   #1
RSS
Guest
 
Posts: n/a
Default DLL does not load Dynamically


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
Old 27-04-2006, 08:29 PM   #2
AMDRIT
Guest
 
Posts: n/a
Default Re: DLL does not load Dynamically

Try ".\\" + _assemblyPath;
"RSS" <q> wrote in message news:%235F%23DdiaGHA.1812@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.

  Reply With Quote
Old 27-04-2006, 08:36 PM   #3
Bruce Wood
Guest
 
Posts: n/a
Default Re: DLL does not load Dynamically

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
Old 27-04-2006, 08:37 PM   #4
Willy Denoyette [MVP]
Guest
 
Posts: n/a
Default Re: DLL does not load Dynamically

Please post the exact exception message.

Willy.

"RSS" <q> wrote in message news:%235F%23DdiaGHA.1812@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.

  Reply With Quote
Old 27-04-2006, 09:25 PM   #5
RSS
Guest
 
Posts: n/a
Default Re: DLL does not load Dynamically

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]" <willy.denoyette@telenet.be> wrote in message news:OH2swmiaGHA.4772@TK2MSFTNGP05.phx.gbl...
Please post the exact exception message.

Willy.

"RSS" <q> wrote in message news:%235F%23DdiaGHA.1812@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.

  Reply With Quote
Old 28-04-2006, 11:55 AM   #6
.neter
Guest
 
Posts: n/a
Default Re: DLL does not load Dynamically

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
Old 28-04-2006, 06:00 PM   #7
RSS
Guest
 
Posts: n/a
Default Re: DLL does not load Dynamically

Yes it is a windows service


".neter" <gwrafal@poczta.onet.pl> wrote in message
news:e2sois$s38$1@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.



  Reply With Quote
Old 11-05-2006, 03:56 PM   #8
adi
Guest
 
Posts: n/a
Default Re: DLL does not load Dynamically

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off