How to reference assembly from web.config?

Budda picture Budda · Jan 13, 2011 · Viewed 9.6k times · Source

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!

Answer

Ariel picture Ariel · Jan 13, 2011

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().)