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.
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.
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>.
Related
My application is running fine on local, after i publish to azure web apps it gives me the error
Could not load file or assembly 'Microsoft.Practices.ObjectBuilder2, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
how do I fix this? I do not even have the objectBuilder2, if its something I have to reference where do I get it?Please help
Microsoft.Practices.ObjectBuilder2 is part of Enterprise Library. See here
Do you use this library? If not, try to remove references to it. If you use it, then add appropriate .dll to your installation.
For me Microsoft.Practices.Unity references was broken. I've just removed and added it again and worked. Maybe any refereces to Microsoft.Practices.* that would be broken can show this error.
Place Microsoft.Practices.ObjectBuilder2.dll in bin folder of your web application, this will work.
How can I load an assembly using its full display name from a location outside the application's bin path?
Usually one can load an assembly from a custom location with
Assembly.LoadFrom(path);
This works, but it seems that for loading a strong-named assembly I need to specify its full display name such as in
Assembly myDll =
Assembly.Load("myDll, Version=1.0.0.1, Culture=neutral, PublicKeyToken=9b35aa32c18d4fb1");
But the problem here is that this only references assemblies that are in my probing path of my application.
So what if I have an assembly dir1/asm.dll and one assembly dir2/asm.dll and both have a strong name.
How can I load them during runtime?
During Runtime, you can specify additional directories to probe when loading an assembly via the following methods:
AppDomain.CurrentDomain.ClearPrivatePath();
AppDomain.CurrentDomain.AppendPrivatePath();
When the subdirectory names are already known during installation, you can also specify these additional directories in the app.config file in the privatePath attribute of the <probing> element.
Make also sure the file name is correct. When you have
AppDomain.CurrentDomain.AppendPrivatePath("Subdir");
Assembly myDll = Assembly.Load("myDll, Version=1.0.0.1, Culture=neutral, PublicKeyToken=9b35aa32c18d4fb1");
then .net will look for a file named "mydll.dll" in the directory "Subdir" beneath the directory of the executable.
you can load any assembly from its location via loadfile (example here)
if you want to take multiple versions of an assembly consider handling the AppDomain.CurrentDomain.AssemblyResolve (example here)
the examples are from a small open source project, which will load dlls from a seperate a "packages" folder (allowing for packages to have their own copy of a dependency, using the isolated loader)
In my ASP.NET application I am getting an error sometimes. When I refresh the page error will be gone. The error is,
Could not load file or assembly 'FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
I am thinking that some of my app assemblies reference this assembly. Is it possible to get all refrences recursively. I mean, I will get all reference assemblies of my application, all reference assemblies of my application's reference assemblies and so on.
Use this tool to find the DEpendencies
"NDepend"
http://www.ndepend.com
You can use a free AssemblyInfo tool to see the assembly dependency graph.
You can investigate your assemblies for references using a tool like .NET Reflector
I am trying to use Ajax control toolkit in asp.net website. I copied the dll from one of my previous sample project. It has the following details
Assembly Version – 3.5.40412.0
File Version - 3.5.40412.2
Internal Name: Ajax Control Toolkit
Language : Neutral
Product Version - 3.5.40412.2
When I add reference to this assembly, it appears as “AjaxControlToolkit-3.5.40412.2” in the reference list. When I run the solution, I get a FileLoadException:
Could not load file or assembly 'AjaxControlToolkit-3.5.40412.2' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I think the problem is with the difference in Assembly version and File version. Is it so? How can we overcome it?
Edit the web.config file to remove the reference, which is not required for normal operation:
1 - Open the web.config file in the root of your site
2 - Find the following line and comment it out():xxxxx-is your assembly name.
<add assembly="xxxxx", Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
3 - Save and close the web.config file and try again
Ref Link : http://manual.aspdotnetstorefront.com/p-1118-could-not-load-file-or-assembly-microsoftwebservices3-version3000-cultureneutral-publickeytoken31bf3856ad364e35.aspx
I have searched google for this and could not find the solution to the problem.
My Website references DAL (custom dll) which references Enterprise Library Data Access Components.
I have added the Enterprise Library from the NuGet Package Manager and when I try to build the Website this compilation error pops up:
Error 44 Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference
I have tried setting the Copy Local = True in the DAL for the Enterprise Library dlls and the dlls are transferred to the Bin directory of the website along with DAL dll, but still the error pops up.
Can anyone guide me on this....
The problem is that the DLL that you are using and the one that is referenced in your project are different. I'm not sure what the difference in the manifest is, but it could be version and/or public key.
You have a couple of things to try:
Open the properties for the DLL reference in your project and set Version Specific to false.
Remove the reference, delete the DLL from the bin folder, and re-add the reference.
You could also have a different/incorrect version in your GAC. In order to make sure that you are always using a specific, known version create an assemblies folder relative to your project directory, copy the dll to that directory, and add a reference to the DLL in the assemblies directory rather than one in GAC or elsewhere on your machine. This will ensure that only the specific version that you have targeted for the application will be used rather than any version that is updated on your machine at a later time.
NuGet CommonServiceLocator
Install-Package CommonServiceLocator
This dll is likely to be in the GAC on developer machines as part of some windows application installation (my best guesses are Visual Studio or SSMS).
That’s why we are likely to get warnings or errors on the build machine which we try our best to keep the GAC as clean as the production server’s.
To download the file manually, you can go to https://servicelocation.codeplex.com/
To fix the build warnings and errors, you simply need to run a NuGet command to install the CommonServiceLocation package. The package contains only this one dll file. Microsoft has released only 1 version (1.0.0.0) of this file since 2008. The file is fully compatible with all .NET versions and all Unity versions.
I was able to resolve this issue by removing from ALL the Logging references in the app.config file::
, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null
ie:
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,
Microsoft.Practices.EnterpriseLibrary.Logging,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=null"
requirePermission="true" />
Becomes:
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,
Microsoft.Practices.EnterpriseLibrary.Logging"
requirePermission="true" />
This is not ideal, but it does work...
The Enterprise Library Configuration Tool, sets the values back, so you need to watch for that. I know there is a way to tell the config file to accept these mis-matched settings -- but I I am not sure how.
Setting the PublicKeyToken values for each of the EnterpriseLibrary references in Web.Config fixed it for me.
Remove the reference, delete the DLL from the bin folder and VS, and re-add the reference.