abp icon indicating copy to clipboard operation
abp copied to clipboard

Templating Module Exception

Open aklscv opened this issue 6 years ago • 7 comments

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?

aklscv avatar May 12 '20 04:05 aklscv

What are the steps to reproduce the problem?

maliming avatar May 12 '20 05:05 maliming

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.

aklscv avatar May 12 '20 05:05 aklscv

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 avatar May 12 '20 12:05 hikalkan

@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.

aklscv avatar May 12 '20 15:05 aklscv

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.

hikalkan avatar May 13 '20 02:05 hikalkan

Thanks for the fast action on this issue

aklscv avatar May 13 '20 02:05 aklscv

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.

hikalkan avatar May 13 '20 02:05 hikalkan