Abp: Templating Module Exception

Created on 12 May 2020  路  7Comments  路  Source: abpframework/abp

I am trying to use the templating system that came out with the latest version ABP 2.7 and I am facing the following exception:

System.Threading.SynchronizationLockException: The upgradeable lock is being released without being held.
   at System.Threading.ReaderWriterLockSlim.ExitUpgradeableReadLock()
   at Volo.Abp.TextTemplating.VirtualFiles.LocalizedTemplateContentReaderFactory.CreateAsync(TemplateDefinition templateDefinition)
   at Volo.Abp.TextTemplating.VirtualFiles.VirtualFileTemplateContentContributor.GetOrNullAsync(TemplateContentContributorContext context)
   at Volo.Abp.TextTemplating.TemplateContentProvider.GetContentOrNullAsync(ITemplateContentContributor[] contributors, TemplateContentContributorContext context)
   at Volo.Abp.TextTemplating.TemplateContentProvider.GetContentOrNullAsync(TemplateDefinition templateDefinition, String cultureName, Boolean tryDefaults, Boolean useCurrentCultureIfCultureNameIsNull)
   at Volo.Abp.TextTemplating.TemplateRenderer.RenderSingleTemplateAsync(TemplateDefinition templateDefinition, Dictionary`2 globalContext, Object model)
   at Volo.Abp.TextTemplating.TemplateRenderer.RenderInternalAsync(String templateName, Dictionary`2 globalContext, Object model)
   at Volo.Abp.TextTemplating.TemplateRenderer.RenderAsync(String templateName, Object model, String cultureName, Dictionary`2 globalContext)

Since there is no documentation yet, I was trying to figured out by using the tests in the test project. Things that I did:

  • Setup MyOwnTemplateDefinitionProvider inheriting from TemplateDefinitionProvider and override the Define method to define my template.
  • Added typeof(AbpTextTemplatingModule) to my module.
  • Inject ITemplateRenderer on my AppService and call RenderAsync passing the template name and the model as an anonymous object.

Anything I am missing?

abp-framework bug effort-0.5 high

Most helpful comment

It seems ReaderWriterLockSlim doesn't support async/await scenario :( I didn't know that. So, it can randomly throw exceptions in this case.

@maliming I will take care about it.

All 7 comments

What are the steps to reproduce the problem?

I pretty much did what I describe above; However, it was with an existing project after upgrading to ABP 2.7. I will see if I can reproduce with a brand new project.

I added control for it: https://github.com/abpframework/abp/commit/48ac4d2bb7010af56323746cee02dcd59d5156e8

However, I don't think there was a bug. If you share your full code we can see it.

@hikalkan @maliming Here's the source made with a brand new ABP 2.7 version: https://github.com/aklscv/abplockheld

Just call the testMethod endpoint and you will see the error. The config was done on the Domain.Shared project.

I am not sure there is bug either maybe I am just not using it correctly.

It seems ReaderWriterLockSlim doesn't support async/await scenario :( I didn't know that. So, it can randomly throw exceptions in this case.

@maliming I will take care about it.

Thanks for the fast action on this issue

Thank you @aklscv for reporting and re-producing it. I will not release a hotfix since this feature is not even documented yet and you can workaround it until the 2.8 release.

Workaround

Copy the LocalizedTemplateContentReaderFactory file into your application (no additional step, that's all). It will override the one in the framework and solve the issue.

Once you update to ABP framework 2.8, you can safely delete this class from your application.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ugurozturk picture ugurozturk  路  3Comments

zsanhong picture zsanhong  路  3Comments

ChangYinShung picture ChangYinShung  路  3Comments

hikalkan picture hikalkan  路  3Comments

hikalkan picture hikalkan  路  3Comments