How to reference assembly from web.config?

随声附和 提交于 2019-12-02 02:52:24

问题


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?

P.S. 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!


回答1:


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




回答2:


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 (e.g., 3.5, 4.0, etc). (In code terms, make sure you can load the assembly through Assembly.Load().)



来源:https://stackoverflow.com/questions/4682536/how-to-reference-assembly-from-web-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!