PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
DLL does not load Dynamically
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
DLL does not load Dynamically
![]() |
DLL does not load Dynamically |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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"); ? |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#5 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#6 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#7 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#8 |
|
Guest
Posts: n/a
|
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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

