2

SDL Tridion Support recommended that I post this question out here (they don't seem to have any good guesses at this point). Today I went to go update a Template Building Block (TBB) that largely has gone unchanged/untouched for a couple years now and has worked without issue. Now, when trying to make a simple change to the TBB file in question, I get this error:

Unable to save item
TemplateCompileException: CS0234: The type or namespace name 'Script' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) 
Line 15 Column 22: namespace Tridion.Extensions.Mediators.Razor.Templating {
 using System;
(80040356) Unable to save item
TemplateCompileException: CS0234: The type or namespace name 'Script' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) 
Line 15 Column 22: namespace Tridion.Extensions.Mediators.Razor.Templating {
    using System;


TemplateCompileException: CS0234: The type or namespace name 'Script' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) 
Line 15 Column 22: namespace Tridion.Extensions.Mediators.Razor.Templating {
    using System;
    using Tridion.Extensions.Mediators.Razor.Models;
    using Tridion.ContentManager.Publishing;
 *     using System.Web.Script.Serialization;
    public class Rzr31eda8513e3e4d0ba7e7aba065d78a1eTemplate : Tridion.Extensions.Mediators.Razor.TridionRazorTemplate {
#line hidden

Stack Trace: 
   at Tridion.Extensions.Mediators.Razor.Templating.Compiler.Compile(IEnumerable`1 entries, IEnumerable`1 assemblyReferences)
   at Tridion.Extensions.Mediators.Razor.Templating.RazorTemplateGenerator.CompileTemplates(IEnumerable`1 assemblyReferences)
   at Tridion.Extensions.Mediators.Razor.RazorHandler.Compile(DateTime revisionDate)

The error references this specific namespace declaration:

@using System.Web.Script.Serialization

And that declaration is used in this small block of code:

@{
    dynamic obj = new JavaScriptSerializer().Deserialize<object>(TridionHelper.Package.GetByName("Navigation").GetAsString());
    dynamic root = obj["Root"];
}

In my search for solutions along the way, I've seen other situations require them adding this to their Tridion.ContentManager.config or their web.config file this line in the config:

<add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

The curious thing is that this line isn't in our .config file AND that the config file has also not been touched in a very long time, either. SOMETHING has changed along the way and nobody on my team has a clue what would have changed and why. We're unsure if our Windows Server group has patched the servers in a way that changed something with .NET or if some patch we've been provided by SDL has changed Razor Mediator or some other change that affects namespaces.

Why would I be getting this error message (about Script not being in the System.Web namespace) and what do I do to resolve this? Do we have to modify the Tridion.ContentManager.config file or some other configuration in order for the Extensions namespace to be recognized?

Thank you in advance for any assistance or knowledge you're able to share!

2 Answers 2

1

As you have already discovered, the System.Web.Script.Serialization classes are in a different assembly. If this is not added as a configuration option, it's possible that is that it is "baked in" to the same assembly as your template using ILMERGE.

Assuming that the references in your .NET project include the assembly, it will compile OK, but then not work in the context of Tridion. Some people do the assembly merging as a post-build step, but even if this is working correctly and you upload the unmerged version, you'll get this problem.

I'd check for a post-build step, and look in the output directory for a merged assembly. If it's there, just upload that instead of the original.

Even if it's not already set up like this, it might still be a viable approach to solve your problem.

1
  • This whole subject is admittedly out of my "wheelhouse" and I'm not sure how to respond, but I'm pretty sure that nothing has changed in our project files — no recent deployments have been pushed out, and as far as our system architect can tell, the project still seems to show those classes as being in place. I've forwarded this solution off to him for his input.
    – michael t
    Commented Aug 5, 2019 at 13:48
0

After a lot of back and forth with SDL, we decided to try modifying our Tridion.ContentManager.config file to include the addition below:

  <razor.mediator extractBinaries="true" adminUser="ead\esa_sdlmtuser_qa">
     ...
    <assemblies>
        <add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </assemblies>
     ...
  </razor.mediator>

After restarting the SDL Web Content Manager Service Host service (and its dependencies), the template worked and were able to save it without issue. It's unclear to me, though, WHY this works largely because the configuration file didn't have that add assembly line before and had worked in the past.

Also as a plot twist, our DEV environment had this same issue but started working WITHOUT this addition to the configuration file. I don't know why and we're all stumped on our end.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.