8

We are experiencing a very strange situation with Razor Mediator (v 1.3.3.0) development in Tridion 2011 SP1 with Media Manager Connector on Windows 2008 R2. The first time that you open a Razor TBB in Template Builder and run it, everything executes properly and the TBB completes (or throws an error due to a bug, as the case may be). Subsequent executions with an updated content component also run fine. However, make the simplest change to the Razor Template (add a @Debug statement, even just add a single white space), save the TBB and execute it in Template Builder, and the following error is thrown:

TemplateCompileException: CS1703: An assembly with the same identity 'Tridion.ExternalContentLibrary.V1, Version=1.0.0.1328, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b' has already been imported. Try removing one of the duplicate references. 
Line 0 Column 0: //------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.18063
//

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)
  at Tridion.Extensions.Mediators.Razor.RazorHandler.Compile(DateTime revisionDate)
  at Tridion.Extensions.Mediators.Razor.RazorHandler.GetRazorTemplate(DateTime revisionDate, String templateID)
  at Tridion.Extensions.Mediators.Razor.RazorHandler.CompileAndExecute(DateTime revisionDate, Engine engine, Package package)
  at Tridion.Extensions.Mediators.Razor.RazorMediator.Transform(Engine engine, Template template, Package package)
  at Tridion.ContentManager.Templating.Engine.ExecuteTemplate(Template template, Package package)
  at Tridion.ContentManager.Templating.Engine.InvokeTemplate(Package package, TemplateInvocation templateInvocation, Template template)
  at Tridion.ContentManager.Templating.Compound.CompoundTemplateMediator.Transform(Engine engine, Template templateToTransform, Package package)
  at Tridion.ContentManager.Templating.Engine.ExecuteTemplate(Template template, Package package)
  at Tridion.ContentManager.Templating.Engine.InvokeTemplate(Package package, TemplateInvocation templateInvocation, Template template)
  at Tridion.ContentManager.Templating.Engine.TransformItem(Template template, IdentifiableObject itemToRender)
  at Tridion.ContentManager.Templating.Debugging.DebuggingEngine.Run()
  at Tridion.ContentManager.Templating.Debugging.DebugSession.Run()

Any subsequent executions of the TBB will result in the same error, no matter what you change in the TBB. But, if you leave things alone in Template Builder for somewhere between 30-60 minutes (we don't know exactly how long), you will be able to run the TBB again. Make another change, however, and the process repeats. In fact, once it starts, it gets "worse" if you keep trying to change your TBB. After a few saves of your TBB, you start getting the same error when saving. Again, waiting 30-60 minutes seems to clear things up.

This also happens on a per user basis, even with the same TBB. I can make a change to the TBB and experience the error. I can then check in the TBB, and another developer can run it in Template Builder. If he makes a change to the TBB, then he will receive the error. We both have to wait until things clear up to execute the TBB again.

Dreamweaver templates work fine with Media Manager Connector. Razor templates would throw the usual The type or namespace name could not be found (are you missing a using directive or an assembly reference?) errors until the assemblies are added to the Razor config in Tridion.ContentManager.config, like so:

<razor.mediator extractBinaries="true" adminUser="NT AUTHORITY\SYSTEM">
  <namespaces>
    <add namespace="Tridion.ExternalContentLibrary" />
    <add namespace="Tridion.ExternalContentLibrary.V1" />
  </namespaces>
  <assemblies>
    <add assembly="D:\app\Tridion\bin\client\Tridion.ExternalContentLibrary.V1.dll" />
    <add assembly="D:\app\Tridion\bin\client\Tridion.ExternalContentLibrary.dll" />
  </assemblies>
  <imports/>
  <importSettings includeConfigWhereUsed="false" includeImportWhereUsed="false" replaceRelativePaths="false"/>
</razor.mediator>

Once the above was added, we could use razor templates to get assets from the Tridion.ExternalContentLibrary api, albeit with the issue as described.

There isn't much out there on the Internet with people using Razor and Media Manager Connector, but I have found one blog where the two are apparently used together successfully. That post doesn't mean they weren't experiencing this issue, but no mention was made of it so I would assume things are running as expected.

Our guess is that we have a configuration issue with either Razor or Media Manager Connector, or that the current version of Razor is bugged. Anybody have this working who can help us out?

1
  • Welcome to Tridion Stack Exchange and Thanks for very nicely putting the question. Commented Aug 22, 2014 at 15:28

1 Answer 1

8

Alex Klock's website CodedWeapon where we had gotten the original instructions on how to load an external dll for use in Razor shows 2 ways to reference the assembly. The solution to our problem lies in the second method, namely referencing the dll from the GAC:

<razor.mediator extractBinaries="true" adminUser="NT AUTHORITY\SYSTEM">
  <namespaces>
    <add namespace="Tridion.ExternalContentLibrary" />
    <add namespace="Tridion.ExternalContentLibrary.V1" />
    <!-- <add namespace="Test.Sample" />-->
  </namespaces>
  <assemblies>
    <add assembly="Tridion.ExternalContentLibrary.V1, Version=1.0.0.1328, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b" />
    <add assembly="Tridion.ExternalContentLibrary, Version=1.0.0.1328, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b" />
  </assemblies>
  <imports/>
  <importSettings includeConfigWhereUsed="false" includeImportWhereUsed="false" replaceRelativePaths="false"/>
</razor.mediator>

As shown in my original question, we had referenced the dll from its' installation location within Tridion. After adding the 2 dlls to the GAC via...

"c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil" /i Tridion.ExternalContentLibrary.V1.dll /f
"c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil" /i Tridion.ExternalContentLibrary.dll /f

...and updating Tridion.ContentManager.config to reference the GAC entry, the issues within Razor/Template Builder disappeared. Hope this helps somebody!

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.