Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RazorEngineCompilationException for Strongly typed model. #113

Closed
Kirmiir opened this issue Jul 23, 2022 · 1 comment
Closed

RazorEngineCompilationException for Strongly typed model. #113

Kirmiir opened this issue Jul 23, 2022 · 1 comment

Comments

@Kirmiir
Copy link

Kirmiir commented Jul 23, 2022

Following the example for Strongly typed model usage, I get the following error when I try to complie simple template:

Unable to compile template: (28,69): error CS1031: Type expected
(28,69): error CS1003: Syntax error, ',' expected
(28,70): error CS1003: Syntax error, ',' expected
(28,45): error CS0308: The non-generic type 'RazorEngineTemplateBase' cannot be used with type arguments
(31,67): error CS0115: 'Template.ExecuteAsync()': no suitable method found to override
(33,13): error CS0103: The name 'WriteLiteral' does not exist in the current context
tl1k43uj.51l(5,2): error CS0103: The name 'Write' does not exist in the current context
tl1k43uj.51l(5,8): error CS0103: The name 'Model' does not exist in the current context

After looked on the issue it seems like the problem is related to lack of namespace in my code.
After adding namespace into the code all works as expected.
The problem here is if there is no namespace the result of the following metod RazorEngineCompilationOptionsBuilder.RenderTypeName is ".ModelName".

The inital thought was to add something looks like:

if (string.IsNullOrEmpty(type.Namespace))
{
    result = type.Name;
}

At the same time there is one case with the similar result. If the Model is inner class the class name will be incorrect.

I haven't found issues or details about it in documentation.

Could someone please advise are these known issues and is there info about in document?
Just thought that maybe it worth to add if there is no info.

In both cases there is simple workaround.

Just in case the code example can be found here: Exampe
method Example1 for issue with namespace
method Example2 for issue with inner class

@adoconnection
Copy link
Owner

Hi @Kirmiir thanks for detailed info, it helped a lot!
version 2022.8.1 is out 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants