Git Product home page Git Product logo

Comments (6)

Antaris avatar Antaris commented on July 30, 2024

This is likely to be a bug, will investigate today.

from razorengine.

Antaris avatar Antaris commented on July 30, 2024

Can you share some code so I can replicate the issue, currently I cannot?

from razorengine.

pmarflee avatar pmarflee commented on July 30, 2024

The issue is reproducible if you attempt to compile a template that doesn't have a model using a template service that has a BaseTemplateType that derives from TemplateBase (of T).

    public class CustomTemplateBase<T> : TemplateBase<T> { }

    [Test]
    public void Should_Compile_Template_Without_Model()
    {
        const string template = @"<tr>
            <td>
                <span id=""emailLogo"">
                    <img src=""https://book.itropics.com/bookingwizard/images/inspiringjourneys/recapimages/logo.gif""
                        alt=""inspiringjourneys_logo"" />
                </span>
            </td>
        </tr>";

        var templateService = new TemplateService(new TemplateServiceConfiguration
                                    {
                                        BaseTemplateType = typeof(CustomTemplateBase<>),
                                    });

        templateService.Compile(template, "emaillogo");
    }

This test will fail with the error "System.ArgumentException : The template type is a generic defintion, and no model type has been supplied."

I can see how the error would be caused; we're compiling a template without a model using a base template type that expects a type parameter that represents the type of the model. However I was able to do this with version 2.1 of RazorEngine.

from razorengine.

Antaris avatar Antaris commented on July 30, 2024

Ah, I think I am going to change the internal behavior to force a model type of Object when no model type is available.

from razorengine.

jeremyiverson avatar jeremyiverson commented on July 30, 2024

In the meantime, a simple workaround is to use:

templateService.Compile(template, typeof(object), "emaillogo");

from razorengine.

matthid avatar matthid commented on July 30, 2024

I think this is fixed, pleas re-open if it is not.

from razorengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.