Giter Club home page Giter Club logo

Comments (11)

ltrzesniewski avatar ltrzesniewski commented on June 21, 2024 1

Good! 🙂

I added a warning when you try to use RazorBlade in an ASP.NET project. That should make the issue less confusing in the next release.

from razorblade.

babula38 avatar babula38 commented on June 21, 2024

I am using this application in .Net 7 application and version of library is RazorBlade" Version="0.6.0"

from razorblade.

ltrzesniewski avatar ltrzesniewski commented on June 21, 2024

I cannot reproduce this. I assume you're not using ReSharper? Are all of your tools up to date?

Can you please provide a simple repro project?

from razorblade.

babula38 avatar babula38 commented on June 21, 2024

Project Config:

image

vscode IDE Error:

image

Visual studio Version 17.8.6 IDE Error

image

from razorblade.

ltrzesniewski avatar ltrzesniewski commented on June 21, 2024

Well, I don't have this issue ¯\_(ツ)_/¯

image

Can you update your VS version? v1.9.6 is currently the latest.

Also, the class name doesn't seem right. RazorBlade would generate a PurchaseOrderDocumentView class, not one named Utility_Templates_PurchaseOrderDocumentView. Do you use ASP.NET in your project? If so, you should use ASP.NET directly to render your template. RazorBlade is not compatible with ASP.NET.

from razorblade.

babula38 avatar babula38 commented on June 21, 2024

@ltrzesniewski I am currently using Aspnet core webapi. It is part of Infrastructure layer.

So you suggest not using this library in it?

from razorblade.

ltrzesniewski avatar ltrzesniewski commented on June 21, 2024

I suppose you have AddRazorPages()/MapRazorPages() in your app? In that case I'd use ASP.NET's Razor instead of RazorBlade: you'll get more features and a single implementation. Otherwise, both libraries will try to process all the .cshtml files, and incompatibilities may arise.

The whole point of RazorBlade is to provide Razor templates when you're not using ASP.NET.

I should probably emit a warning when you try to use RazorBlade along with ASP.NET, because of the confusing behavior you get in that case.

from razorblade.

babula38 avatar babula38 commented on June 21, 2024

@ltrzesniewski, It's surprising that we're not utilizing AddRazorPages()/MapRazorPages(). This API is designed to serve only JSON. However, we have requirements for generating HTML documents as strings using Razor for certain document generation purposes.

Interestingly, the generated class name is different from what is shown in the IDE error.

image

from razorblade.

ltrzesniewski avatar ltrzesniewski commented on June 21, 2024

Hmm, that's what RazorBlade generates, but I suppose the IDE shows you errors which would happen if ASP.NET were the underlying engine. I'll try to reproduce the problem in an ASP.NET app in order to understand it better.

If you'd like to use RazorBlade, maybe you could try to isolate your Razor templates in a separate project which does not reference ASP.NET at all. Hopefully, the IDE won't get confused in that case 🤞. Since the generated templates are internal, you'll have to add a wrapper in order to call them, or maybe just an InternalsVisibleTo attribute if you just want to quickly test the IDE behavior.

from razorblade.

ltrzesniewski avatar ltrzesniewski commented on June 21, 2024

Ok, I understand the problem, and it's very simple. It occurs because of @inherits RazorBlade.HtmlTemplate:

  • RazorBlade's HtmlTemplate class inherits from RazorTemplate, which defines a protected internal virtual Task ExecuteAsync() method that the generated source overrides.
  • ASP.NET's base class is RazorPageBase, which defines this method as public abstract Task ExecuteAsync()

RazorBlade expects a protected method to override, while ASP.NET expects a public one. If you run ASP.NET's source generator on a template which uses RazorBlade.HtmlTemplate, you'll get the "cannot change access modifiers" error that you see. That comes from Microsoft.CodeAnalysis.Razor.Compiler/Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator, not from RazorBlade itself.

I don't want to make the ExecuteAsync method public in RazorBlade, since it's not suited to be called directly by the user. The RazorBlade library provides wrapper methods such as RenderAsync which set up the necessary context.

I also tested what happens when you move your RazorBlade template into a separate "Class Library" project, and sure enough, the error disappears since the Razor source generator is no longer invoked.

from razorblade.

babula38 avatar babula38 commented on June 21, 2024

Thanks @ltrzesniewski . I think below third party libraries are creating problem. the moment I moved the template to a different project the errors disappeared.

image

from razorblade.

Related Issues (11)

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.