We have a page region in XPM and it works fine with adding/removing components until you add the 6th+ component to it. After doing so the following error is produced:

TemplateCompileException: CS0103: The name 'TestRazor' does not exist in the
current context Line 33 Column 7: public override void Execute() { 
WriteLiteral("\r\n<div class=\"clearfix\">\r\n\r\n "); * Write(TestRazor()); 
WriteLiteral("\r\n\r\n"); foreach (var article in Fields.ArticlesAndRTFs) { 
Stack Trace: at 
entries, IEnumerable`1 assemblyReferences) at 
lates(IEnumerable`1 assemblyReferences) at 
Tridion.Extensions.Mediators.Razor.RazorHandler.Compile(DateTime revisionDate)

This happens after adding the additional component presentation to the page through XPM or when attempting to "update preview" after adding the additional component presentation. If I then republish the page and then "update preview", the update works as expected with no issues no matter how many component presentations I have added.

This does not happen for all component presentations, only for component presentations which render nested component presentations. And this does not occur when rendering the page using any other method (Preview, publish, template builder etc...). All of our layouts include razor helper functions and the other layouts do not have this issue.

The component presentation added to the page has this layout:

<div class="clearfix">


  @foreach (var article in Fields.ArticlesAndRTFs) {
    if (article.Schema.Title == "Content Article") {
        @RenderComponentPresentation(article.ID, "tcm:xyz")


Where tcm:xyz is a layout which looks like this:


(The layouts here are just test versions to attempt to get to the root of the issue, they are the layouts being used right now to duplicate the issue but are not the final version of these templates.)

Additionally here is the Windows Event Viewer Log:

RazorHandler: Error import of '/webdav/021 Global Design/Building 
Blocks/System/Templates/Template Building Blocks/Razor Functions.cshtml'. 
System.Reflection.TargetInvocationException: Exception has been thrown by the 
target of an invocation. ---> Oracle.DataAccess.Client.OracleException: Unable 
to enlist in a distributed transaction at 
Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, 
OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object 
src, String procedure, Boolean bCheck, Int32 isRecoverable) at 
Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, 
OracleConnection conn, IntPtr opsErrCtx, Object src) at 
Oracle.DataAccess.Client.OracleConnection.Open() at 
) at Tridion.ContentManager.Data.AdoNet.Oracle.OracleDataSession..ctor() --- End 
of inner exception stack trace --- at 
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, 
Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, 
Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean 
publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) 
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean 
skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at 
System.Activator.CreateInstance(Type type, Boolean nonPublic) at 
System.Activator.CreateInstance(Type type) at 
Tridion.ContentManager.Data.DataSessionFactory.CreateDataSession() at 
Tridion.ContentManager.Data.DataSessionFactory.CreateDataSession(UserData user) 
at Tridion.ContentManager.Session.GetDataSession() at 
userName, IEnumerable`1 mappedGroupUris, IEnumerable`1 claimSets) at 
userName, String impersonationUserName) at 
Tridion.ContentManager.Session..ctor(String userName) at 
Tridion.Extensions.Mediators.Razor.RazorHandler.get_Session() at 
path) Component: Templating Errorcode: 0 User: NT AUTHORITY\NETWORK SERVICE 

What could cause this issue? Are there any steps that could resolve it?

Edit: If the lines "@TestRazor()" Or

@foreach (var article in Fields.ArticlesAndRTFs) {
    if (article.Schema.Title == "Content Article") {
@RenderComponentPresentation(article.ID, Package[Package.TemplateName + "Template"])

Are removed, from the template above the functionality works as expected.

Edit: The razor function is declared within an @functions block in a TBB and it is:

public string TestRazor()
  return "success";

The file is imported globally from the Tridion.ContentManager.config file by specifying the Webdav path of this TBB.

  • Spoke with the creator of the Razor Mediator and he determined that it is most likely an issue with the mediator itself and the way it reads the global Razor Functions file. One workaround is to duplicate some code and add the new functions inline under a different name to the offending templates. It should be fixed in a future version of the Razor Mediator. Aug 15, 2016 at 13:22

1 Answer 1


The final solution which solved this issue permanently was to change the razor mediator helper functions TBB into a .txt file. Loading the TBB multiple times in the same template was causing the issue in XPM due to the way in which the Razor Mediator reads the file. Changing the helper functions over to a .txt file and importing that instead, fixed the issues entirely. -I've been told that future versions of the Razor Mediator will address this issue.

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.