LoadAssembly dynamically


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.

asked on Stack Overflow Jul 26, 2011 by AlexCode • edited Mar 13, 2018 by Cœur

5 Answers


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.

answered on Stack Overflow Jul 26, 2011 by Jason Evans • edited Sep 27, 2011 by Tim Cooper

You need to use the "long form of the assembly name" not the file path to the code: see this link

answered on Stack Overflow Jul 26, 2011 by Schroedingers Cat • edited Jul 26, 2011 by Schroedingers Cat

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)...

answered on Stack Overflow Jul 26, 2011 by Yahia

This is probably related to permissions, generally an website is not going to have access (particularly execute access) to files outside it's root directory.

answered on Stack Overflow Jul 26, 2011 by CodingGorilla

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 app.

See here for more info: How to call a Managed DLL File in C#?

answered on Stack Overflow Jul 26, 2011 by George Duckett • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0