ASP.NET · Errors and Exceptions
„Could not load file or assembly System.Web.Extensions“ při načítání controlů metodou LoadControl
Na zajímavý problém jsem narazil při implementaci použití CMS a našeho prezentačního frameworku. Obojí je kompilováno pro .NET 2.0, používáme je s .NET Frameworkem 3.5.
CMS načítá *.ascx standardní metodou:
[sourcecode language='csharp' padlinenumbers='true' light='true']
Page.LoadControl("~/Test.ascx");
[/sourcecode]
Bohužel se objevil problém s načítáním assembly, které jsou ve web.configu redirectovány na nové verze:
[sourcecode language='bash' light='true'] Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Systém nemůže nalézt uvedený soubor. [/sourcecode]
[sourcecode language='xml' light='true']
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
[/sourcecode]
Příčina a řešení problému byla taková, že jsem v konfiguračním souboru musel odstranit namespace (atribut xmlns) z elementu configuration.
[sourcecode language='xml' light='true'] <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> [/sourcecode]