I have an MVC login page, and I'm trying to use some .DLLs which I've already created for other purposes. These .DLLs are really plugins and they are located in a /CorePlugins
folder in my webpage and loaded dynamically at run time via PreApplicationStartMethod. Here is how I'm loading these .DLLs:
var corePluginAssemblyFiles = CorePluginsFolder.GetFiles("*.dll", SearchOption.AllDirectories);
foreach (var assemblyFile in corePluginAssemblyFiles)
{
var assembly = Assembly.LoadFile(assemblyFile.FullName);
System.Web.Compilation.BuildManager.AddReferencedAssembly(assembly);
}
Now, among these plugins, I'm actually able to reference back and forth any which way I want and everything works fine. But, when trying to use one from my login page LoginController (which is in the /bin folder and not the /CorePlugins folder) it says that it cannot find the .Dll in question:
Could not load file or assembly 'Core.API.UserMgmt, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The network path was not found. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Core.API.UserMgmt, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The network path was not found.
Source File: C:\svn\HomeCenter_DEV\HomeCenter\HomeCenter.Core\Controllers\LoginController.cs Line: 202
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Core.API.UserMgmt, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = Core.API.UserMgmt, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified)
LOG: Appbase = file:///C:/svn/HomeCenter_DEV/HomeCenter/HomeCenter.Core/
LOG: Initial PrivatePath = NULL
Calling assembly: HomeCenter.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\svn\HomeCenter_DEV\HomeCenter\HomeCenter.Core\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: The same bind was seen before, and was failed with hr = 0x80070035.
So just for giggles I placed a copy of the .DLL in the /bin folder as well, and low and behold it said it can't load the assembly because its already loaded. So now I'm thinking what the hell. So using some test code I printed out the loaded assemblies from System.Web.Compilation.BuildManager.GetReferencedAssemblies() and from AppDomain.CurrentDomain.GetAssemblies() and I do in fact see the .DLL I'm trying to use Core.API.UserMgmt, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
. So whats going on here? Why can't it find the DLL that has clearly already been loaded. If I place the .dll in the /bin folder and remove it out of the /CorePlugins
folder, it works, but then everything else that I have set up breaks. I need the .dll to be in the /CorePlugins
folder.
I can't quite remember which post I found that lead me to solving this, but essentially adding a probing
element to assemblyBinding
section in my Web.Config
is what solved this for me.
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="folder\subFolder1;folder\subFolder2;folder\subFolder3" />
<!-- Other stuff -->
</assemblyBinding>
I had to add the root folder of every DLL I wanted to include because I couldn't figure out how to get it to recursively traverse the directory.
User contributions licensed under CC BY-SA 3.0