ASP.NET How to add assembly in web.config? - asp.net

I have a assembly made in another project (projA). Now I want to import this dll in another project (projB). How can I achieve this? This is what I've tried (in projB).
1 Put dll in same dir as my project. (the 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:
Could not load file or assembly 'projA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
EDIT:
The point is that eventually the assembly reference must me added dynamically
EDIT 2:
The name of the assembly (and namespace) are stored in the database. The physical assembly (dll) is added (by installation) in projB. Now the code in projB must read the assembly name from the database and then add a reference to the dll which is added by installation.

Are all of projA's dependencies in projB? Usually I'd just add a reference from one project to another if they are in the same solution.
Edit:
If you want to add an assembly dynamically then maybe a service reference maybe something to consider. By dumping in projA's DLL into the bin that doesn't really give all the DLLs that it may require, thus there are ways to tie things together so that objects can be understood across systems, like web services using XML to give a common example.
My question back about adding an assembly dynamically is where would you get it from and can that part be automated to be part of projB as that is really the general solution to this kind of problem.
Edit 2:
How could you get all of projA's dependencies? Is it possible to get it so that it doesn't depend on a bunch of other DLLs that may or may not be on the system that this is to run. That is what the error is telling you, that there exists some assembly projC that is also required. Note that this adding of assemblies can continue for a long time if there are many levels of dependencies used.
Summarizing the answer: What would you need to reference in order to load projA into some new project? That's your problem which without knowing what the dependencies look like is rather hard to answer directly.

You do not need to add anything in Web.config if the assembly DLL is in the Bin folder - you only need to do this if you are referencing an assembly that is in the GAC.
The error message you are getting is basically saying that the assembly can't be found in the GAC, which is presumably because it isn't there!

You don't need to manually add the reference in the web.config file. Right click on your project in the Solution Explorer window in Visual Studio and select 'Add Reference'. Go to the Browse tab and find the DLL you created in the other project, select it and click OK. Optionally, you can add the project A to the same solution as project B and then add the reference through the Projects tab of the Add Reference window.

The error
The located assembly's manifest
definition does not match the assembly
reference.
suggests that a DLL was found but did not match the version, or public key.
I would suggest double checking to ensure that the assembly reference matches the version information and that no rogue DLL's with old version numbers are located in the /bin paths or the GAC

Well, I guess to some extent it depends on what you are planning on doing once you've loaded the assembly, and what you've got in the assembly.
I'll assume you've got some sort of plugin architecture, with a known interface or base class that you're going to be calling methods on, lets say IPlugin.
Anyway, here's how to load an assembly dynamically, based on storing a reference to it in either a config section or 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 string 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're interested in.
You would then use it like this:
// 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();

Related

Referenced assembly, formerly unsigned, now signed, cannot be loaded by application

After signing and recompiling a referenced assembly (MyAssembly.dll), my web application fails with "The located assembly's manifest definition with name MyReferencedAssembly does not match the assembly reference".
This is what I expected, since the PublicKeyToken has changed from null to a new key.
It seems you should be able to use an assemblyBinding section in the web.config file to make the application use the new signed assembly.
Problem is, there doesn't seem to be a way to identify the assembly the app will be looking for (the old, unsigned assembly) in the assemblyIdentity element.
Since the old publicKeyToken value was null, I've tried leaving it out, tried setting it to an empty string, null in quotes and none of them seem to work.
I've tried changing the version number so I can use binding Redirect from the old to the new version, and also tried setting a specific codeBase for the assembly.
All of this fails so I have to believe the assembly loading process just doesn't like loading a signed assembly when an unsigned one was referenced/expected.
How do I perform this mapping?
Recompiling the entire code base referencing the signed assemblies is not an option.
Thanks for any suggestions.

Unable to Initialize TDSE object. Could not load file or assembly 'Tridion.ContentManager.Publishing while accessing the Tridion UI

While opening the Tridion UI I am getting this error:
Unable to Initialize TDSE object. Could not load file or assembly 'Tridion.ContentManager.Publishing, Version=6.1.0.996, Culture=neutral, PublicKeyToken=360aac4d3354074b' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515) The type initializer for 'Tridion.ContentManager.TypeRegistry' threw an exception.
Most probably you have some extension or something like this that you have copied from the network and your DLL get locked. You need to find this DLL and click Unblock from the context menu. You will most probably have to do it for all other copied dlls as well. It should look like this:
http://www.izenda.com/Site/KB/Uploads/Images/unblock.PNG
In case you have no idea where to look - use procmon
I would also double check Tridion.ContentManager.Publishing dll is in the GAC.
A quick way to see this is to look in c:\windows\assembly and match the version of the DLL as well. You could re-drag and drop the DLL there to make sure all is well.

How to update dll in asp.net

I update my freetextbox version into 3.3.0.22838. I don't know how to update it. i just copy paste my new version in bin.
And I get this error:
Could not load file or assembly 'FreeTextBox, Version=3.1.5.21298, Culture=neutral, PublicKeyToken=5962a4e684a48b87' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Line 1: <%# page language="C#" masterpagefile="~/Template/BackendTemplate.master" autoeventwireup="true" validaterequest="false" inherits="Backend_Modules_BookManagement, App_Web_wplihlju" title="Untitled Page" %>
Much thanks!
Double check your solution's reference to the assembly. Right-click > Properties > Specific Version should be set to False. That or drop the reference to the old one and add a reference to the new one. Either way you'll need to recompile. The first suggestion will solve it for all future versions however.
hallo it says on error that you used different version of control on build you should put version Version=3.1.5.21298 instead of version 3.3.0.22838...
or you should build your project with version 3.3.0.22838 and deploy all your project....
As you see in the error message FreeTextBox has a public key token and also a version number. when you add a dll as a reference to your application, it binds your application to this publick token key and version number.
so you need to remove your FreeTextBox dll from your application references and add reference to new version to correct your problem.
just open your solution, go to references of your application, remove the FreeTextBox reference. then right click on references and select add reference and then select your new FreeTextBox dll. after rebuild, every thing will go fine.
The loader cannot find the assembly that was referenced; see that you put your assembly in the application folder or GAC it.

Assembly loading error in my ASP.NET app, and the assembly isn't even referenced anymore

I had some code that referenced the Noesis.Javascript assembly (http://javascriptdotnet.codeplex.com) and had renamed the Noesis.Javascript.dll to Noesis.Javascript.0.4.dll. I referenced this file through Visual Studio, and when I launched my web app in the ASP.NET development server, I got this error:
Could not load file or assembly
'Noesis.Javascript.0.4' or one of its
dependencies. The located assembly's
manifest definition does not match the
assembly reference. (Exception from
HRESULT: 0x80131040)
I then tried to remove this reference and re-reference the older version of the library. I got the same error. I then tried to remove this reference entirely and comment out all code that used this library. I still get the same error. I have tried to explicitly close out the ASP.NET development server from its icon in the system tray, but this still occurs. I can find no reference of this assembly anywhere in my project now, yet the error persists. What might be happening? Is there some cache that I'm not finding? How can I resolve this error?
Go into the registry and set [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Refresh the page and the error output will show you which assembly has a dependency on Noesis.Javascript.0.4.
Check if "Noesis.Javascript.0.4" appears anywhere in your web.config file and remove it if it does. It might be in the <assemblies> part.
remove the reference and add it again. Please note that the two dll version must be same. Do not add any later version, if its get registered into your web.config, otherwise you need to remove from there too.
In my case, I added a wrong DLL. Instead of adding 64bit, I added 32bit.
Thanks,

Could not load file or assembly for c1webreport1 tool in compnentone studio

I'm using Licensed componentone product in my ASP.NET application and spcefically i use C1WebReport1 control from the product.while upgrading C1WebReport1 control from version 2.5.20072.239 to 2.6.20093.53207,i get the error message as
"Could not load file or assembly 'C1.Web.C1WebReport.2, Version=2.6.20093.53207, Culture=neutral, PublicKeyToken=594a0605db190bb9' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
can any one help me to bring complete solution?
Thanks in advance.
Regards
Omprakash
It looks like the new (version 2.6.20093.53207) dll might not be in your bin folder. You can view the version of the dll by right-clicking, selecting properties and viewing the summary tab. Make sure you have the right version included in your project. If you have an old dll.refresh file I would delete it and also go into design view on the form that uses WebReport to regenerate the licensing files.
By the way, ComponentOne just released a brand new ReportViewer for ASP.NET you might want to try out too. If you have a license for 2009v3 you probably will qualify for the free upgrade!

Resources