Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top