ASP.NET How to add assembly to web.config?

I have an assembly done in another project (projA). Now I want to import this DLL into another project (projB). How can i achieve this? This is what I tried (in projB).

1 Put the dll in the same directory as my project. (bin dir)

2 In web.config:

<assemblies> <add assembly="projA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </assemblies> 

This is the error I get:

Failed to load file or assembly 'projA, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35' or one of its dependencies. The located assembly manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

EDIT:

The fact is that in the end, the assembly link needs to be added dynamically

EDIT 2:

The name of the assembly (and namespace) is stored in the database. The physical assembly (dll) is added (by installation) to projB. Now the code in projB should read the assembly name from the database, and then add the link to the DLL that was added by the installation.

+6
web-config assemblies
source share
5 answers

Are all projA dependencies in projB? Usually I just add a link from one project to another if they are in the same solution.

Edit:

If you want to add an assembly dynamically, then perhaps a link to a service might be something to consider. Dumping in the projA DLL to bin, which really does not give all the DLLs that might be required, so there are ways to link things so objects can be understood through systems like web services using XML to give a general example.

My question about adding the assembly dynamically is where you get it from, and whether this part can be automated to be part of projB, as this is really a general solution to this problem.

Edit 2:

How can you get all the projA dependencies? Is it possible to get it so that it does not depend on a bunch of other DLLs that may or may not be on the system so that it starts. This is exactly what the error tells you that there is also a projC assembly, which is also required. Note that this addition of assemblies may continue for a long time if many dependency levels are used.

To summarize the answer: what do you need for the link to load projA into some new project? That your problem, which does not know what the dependencies look like, is quite difficult to answer directly.

+7
source share

You do not need to add anything to Web.config if the DLL assembly is in the Bin folder - you only need to do this if you reference the assembly that is in the GAC.

The error message you get basically says that the assembly cannot be found in the GAC, which is presumably because it does not exist!

+4
source share

You do not need to manually add the link to the web.config file. Right-click on your project in the Solution Explorer window in Visual Studio and select Add Link. Go to the "Overview" tab and find the DLL created in another project, select it and click "OK." If you wish, you can add project A to the same solution as project B, and then add a link to the Projects tab of the Add Link window.

+3
source share

Mistake

The located assembly manifest definition does not match the assembly reference.

assumes that the DLL was found, but does not match the version or public key. I would suggest a double check to make sure the assembly reference matches the version information, and that no rogue DLL with old version numbers is in the / bin paths or GAC

0
source share

Well, I think, to some extent, it depends on what you plan to do after loading the assembly and what you have in the assembly.

I assume that you have some kind of plugin architecture, with a known interface or base class, which you are going to call methods, say, IPlugin.

In any case, here's how to load an assembly dynamically, based on storing a link to it in any configuration section or in a DB column somewhere:

 private IPlugin LoadPlugin(string fullTypeName) { Type type = Type.GetType(fullTypeName, false, true); Object plugin = Activator.CreateInstance(type); if (plugin is IPlugin) { return (IPlugin) plugin; } // Handle the fact you've not got what you expected however you like throw new ApplicationException(error); } 

So, this will take a line such as "projA.PluginClass, projA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" load the assembly and return you an instance of the class you are interested in.

Then you will use it as follows:

 // Call to DB to get details of class and assembly string pluginClass = GetPluginDetails(); IPlugin plugin = LoadPlugin(pluginClass); // Call known method to do something on IPlugin plugin.SomeMethod(); 
0
source share

All Articles