I'm trying to load an assembly at runtime. For that I'm using the following line:
file is a FileInfo object, so file.FullName returns the full path to the file on the filesystem, e.g.: c:\mywebsite\dlls\myassembly.dll
When I try to execute the line above I get the following error:
Could not load file or assembly 'c:\mywebsite\dlls\myassembly.dll' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
I'm sure this isn't a dependency problem, and I don't know what's an "invalid codebase"
Note that if I put the assembly directly on the BIN folder of the site everything works correctly, I just can't make load dynamically.
To supplement Schroedingers Cat's answer, you might want to look at Assembly.LoadFile if you only have the file path. But you might get security issues when running from ASP.NET which may require configuring permissions on the file system, to allow your website to access the file.
You need to use the "long form of the assembly name" not the file path to the code: see this link
This is a security/permissions issue - you can't load assemblies from outside bin without the proper permissions (depending on the account used to run)...
This is probably related to permissions, generally an asp.net website is not going to have access (particularly execute access) to files outside it's root directory.
That method expects the assembly name. What you want is Assembly.LoadFrom, although you will have to be carefull with permissions as you're calling this from an asp.net app.
See here for more info: How to call a Managed DLL File in C#?
User contributions licensed under CC BY-SA 3.0