-
Notifications
You must be signed in to change notification settings - Fork 92
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
@Model is null when using RazorEngineTemplateBase #28
Comments
Another update on this, It seems my "weakly typed" version of this function is able to render my template just fine.
I'm guessing the null issue is related to using the generic |
Its because of Thats design issue, I need to think a little. |
as a quick solution I would simplify cache dictionary:
|
This is a design expression issue I've long struggled with in C#. C# 9 will supposedly be implementing covariant overrides. That would solve this issue, but is a ways out |
Maybe not so far out. Looks like they plan to release C# 9 with .NET 5, which is already to release candidates |
Cool, however this breaking change for public abstract class RazorEngineTemplateBase<T> : RazorEngineTemplateBase
{
public override T Model { get; set; }
}
public abstract class RazorEngineTemplateBase : IRazorEngineTemplate
{
public virtual dynamic Model { get; set; }
} |
That appears to be the design they're going for. https://github.com/dotnet/csharplang/blob/master/proposals/csharp-9.0/covariant-returns.md#motivation I wasn't clear that this library would need to change from new to override. |
good news anyway :) |
I've run into an issue when attempting to strongly type a template.
My template has
@inherits RazorEngineCore.RazorEngineTemplateBase<MyModelType>
at the top, and this makes intellisense work nicely.The template compiles just fine, but when I run it, I always get "Object not sent to instance of an object" when I reference any property on my model. I know my model is not null. It works fine when render it without using
RazorEngineTemplateBase
.Running a template with
@(Model == null)
works, but always renders "True".My generic render function:
Any help on this would be greatly appreciated. Thanks.
The text was updated successfully, but these errors were encountered: