ASP.net LoadAssembly dynamically

1

I'm trying to load an assembly at runtime. For that I'm using the following line:

System.Reflection.Assembly.Load(file.FullName);

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.

c#
asp.net
reflection
asked on Stack Overflow Jul 26, 2011 by AlexCode • edited Mar 13, 2018 by Cœur

5 Answers

3

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
1

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
1

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
0

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.

answered on Stack Overflow Jul 26, 2011 by CodingGorilla
0

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