tags:

views:

1395

answers:

4

My ASP.NET application loads an assembly and creates a class instance from an object within it. The assembly itself has a reference to a dll called "Aspose.Cells.dll" which it can access without any problems and is located on the same path as the assembly file itself. However, when I make a method call to one of its methods I get this error:

Could not load file or assembly 'Aspose.Cells, Version=4.1.2.0, Culture=neutral, PublicKeyToken=9a40d5a4b59e5256' or one of its dependencies.

I figure that I need to make my ASP.NET application reference this DLL as well but everything I've tried so far has failed. The assembly DLL which is loaded is not located within the root of the web application and I'm hoping that it doesn't have to be.

I can load the assembly like this:

Assembly asm = Assembly.LoadFile(@"D:\Dev\EasyFlow\Plugins\ImportExportLibrary\bin\Debug\Aspose.Cells.dll");

But I can not use it like this:

AppDomain newDomain = AppDomain.CreateDomain("testAspose");
Assembly asm = newDomain.Load(System.IO.File.ReadAllBytes(@"D:\Dev\EasyFlow\Plugins\ImportExportLibrary\bin\Debug\Aspose.Cells.dll"));

Is there a better way to do it?

Update:

Thanks for your replies.

I forgot to mention that I cannot copy the assemblies to the bin folder or the GAC because I want it to work as a plugin system where assemblies can be replaced easily by changing the path to assemblies in a configuration file and not having to manually copy files into the main project.

However, the AssemblyResolve event seems interesting and I will give it a try later.

A: 

You can copy the dependent assembly into the Bin folder or install it in the GAC.

Paul Alexander
A: 

I'm thinking you can add assembly references to the web.config, in the <compilation> section, like so:

<compilation debug="true">
  <assemblies>
     <add assembly="Aspose.Cells, Version=4.1.2.0, Culture=neutral,  PublicKeyToken=9a40d5a4b59e5256"/>
  </assemblies>
</compilation>

I am not altogether certain this will work, and it may require a corresponding entry to web.config in a <configSections> node under <configuration>.

Cyberherbalist
+1  A: 

There are a few ways to do this. One way is described in the Microsoft Knowledge Base article "How to load an assembly at runtime that is located in a folder that is not the bin folder of the application". It provides a pretty good step-by-step method of how to do this.

HVS
A: 

I think when you change/replace the component file e.g Aspose.Cells.dll for your project but don't update the assembly reference, this error might occur sometimes. In VS.NET, you need to Remove the older assembly reference first and then try Add Reference to your new Aspose.Cells.dll file located at your desired path to check if it works fine.

qamarhash2