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
Tridion.Extensions.Mediators.Razor.Templating.Compiler.Compile(IEnumerable`1
entries, IEnumerable`1 assemblyReferences) at
Tridion.Extensions.Mediators.Razor.Templating.RazorTemplateGenerator.CompileTemp
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">
@TestRazor()
@foreach (var article in Fields.ArticlesAndRTFs) {
if (article.Schema.Title == "Content Article") {
@RenderComponentPresentation(article.ID, "tcm:xyz")
}
}
</div>
Where tcm:xyz is a layout which looks like this:
<article></article>
(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
Tridion.ContentManager.Data.AdoNet.Oracle.OracleDatabaseUtilities.GetConnection(
) 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
Tridion.ContentManager.Security.AuthorizationManager.LoadAccessToken(String
userName, IEnumerable`1 mappedGroupUris, IEnumerable`1 claimSets) at
Tridion.ContentManager.Security.AuthorizationManager.LoadAccessToken(String
userName, String impersonationUserName) at
Tridion.ContentManager.Session..ctor(String userName) at
Tridion.Extensions.Mediators.Razor.RazorHandler.get_Session() at
Tridion.Extensions.Mediators.Razor.RazorHandler.GetImportTemplateContent(String
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.