简体   繁体   中英

How to reference assembly from web.config?

I need to add reference to 'System.XML.dll' assembly into web.config (in order to try solution for problem, mentioned here: Problem with Extension method: IXmlLineInfo ).

I've tried to add the following line into "assemblies" section:

<add assembly="System.Xml, Version=2.0.5.0, Culture=neutral,
     PublicKeyToken=7cec85d7bea7798e"/>

That caused an error:

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load file or assembly 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

To be honest, I not sure if version/Culture/PublicKeyToken are specified correctly.

I have few different versions of System.XML.dll:

  • C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETFramework\\v3.5\\Profile\\Client\\System.XML.dll
  • C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETFramework\\v4.0\\Profile\\Client\\System.XML.dll
  • C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETFramework\\v4.0\\System.XML.dll
  • C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\Silverlight\\v3.0\\System.Xml.dll
  • C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\Silverlight\\v4.0\\System.Xml.dll

Also I have some assemblies in GAC in Framework, Framework x64, etc...

Question1:

Which assembly do I need?

Question2: (obsolete)

How to determine exact assembly version and publicKeyToken?

PS Funny things, when I posted question I've found that there is a 'publickkeytoken' tag already and it contains answer for Question2 :)

Thanks a lot!

Try 'gacutil /l', and make sure you put in your web.config the one you really want to reference, depending on the target .NET release (eg, 3.5, 4.0, etc). (In code terms, make sure you can load the assembly through Assembly.Load().)

If you are using Visual Studio, then you can do it by Right clicking your Project-> Add Reference->Under .NET tab you will find that assembly.

How to add assembly reference via VS .

Depending on the type of project ie WebSite or WebApplication VS will either add an entry to web.config or add the dll to your bin folder.

Now which one you need(2.0/3.5/4.0) depends on your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM