PRB: Assembly.LoadFrom Does Not Load Dependent Assemblies That Are Located in the Same Directory (327435)
The information in this article applies to:
- Microsoft Visual Studio .NET (2002), Professional Edition
This article was previously published under Q327435 SYMPTOMSYou can call the Assembly.LoadFrom() method on an assembly that invokes a method from a dependent
assembly. If the method is located in the same directory, you may see one of the following exceptions: Unhandled
Exception: System.Reflection.TargetInvocationException: Exception has been
thrown by the target of an invocation. System.IO.FileNotFoundException: File or
assembly name assembly, or one of its dependencies, was not found This occurs when the assembly that you load is in a directory of
the same name as the assembly, and the calling application is in a different
directory. CAUSE When you dynamically load an assembly with Assembly.LoadFrom() from a directory with the same name as the assembly (for example,
MyAssembly.dll is located in the directory that is named MyAssembly), the
assembly is loaded in the Load context instead of the LoadFrom context. The
dependent assemblies are not loaded. RESOLUTION Rename the directory where the assembly is loaded from and
where its dependents are located. A directory with a different name causes the
assembly to load in the LoadFrom context. The dependents of the assembly are
loaded also.
For example, instead of locating MyAssembly.dll and its
dependent assembly (DepAssembly.dll) in the directory that is named MyAssembly,
put them in a directory that is named MyAssemblyDir. STATUS This
behavior is by design.REFERENCES For more information about Assembly.LoadFrom(), visit the following Microsoft Web site: For more information about the .NET runtime and how it locates
assemblies, visit the following Microsoft Web site:
| Modification Type: | Minor | Last Reviewed: | 3/3/2004 |
|---|
| Keywords: | kbprb KB327435 |
|---|
|