Attempting to load the application through reflection and get the error "Failed to load file or assembly ... The system cannot find the file specified."
4 answers
You can:
- Create a new one
AppDomain
to load the assembly (and set the base directoryAppDomain
to the directory containing all assemblies). - Attach a handler for
AppDomain.AssemblyResolve
to help the CLR find assembly dependencies. - You may be able to add the directory in question to the probing path list. However, it will need to be located somewhere in your application directory. See probe for more information .
+3
source to share
You can try using something like this
string myDll = string.Empty;
string location = Assembly.GetExecutingAssembly().Location;
if (location != null)
{
myDll = string.Format(@"{0}\my.assembly.name.dll", location.Substring(0, location.LastIndexOf(@"\")));
}
This should get the physical directory where the assemblies are running. It could be in Windows.NET temporary directories. However, since the files are at the same level, they must exist next to each other.
0
source to share
If you are using assembly.loadfrom you can provide the path to the assembly file.
The load-from context allows an assembly to be loaded from a path not probed, and still allows dependencies on that path and loaded because the path information is supported by the context.
0
source to share