Comments (11)
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.
I am using this application in .Net 7 application and version of library is RazorBlade" Version="0.6.0"
from razorblade.
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.
Project Config:
vscode IDE Error:
Visual studio Version 17.8.6 IDE Error
from razorblade.
Well, I don't have this issue ¯\_(ツ)_/¯
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.
@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.
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.
@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.
from razorblade.
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.
Ok, I understand the problem, and it's very simple. It occurs because of @inherits RazorBlade.HtmlTemplate
:
- RazorBlade's
HtmlTemplate
class inherits fromRazorTemplate
, which defines aprotected internal virtual Task ExecuteAsync()
method that the generated source overrides. - ASP.NET's base class is
RazorPageBase
, which defines this method aspublic 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.
Thanks @ltrzesniewski . I think below third party libraries are creating problem. the moment I moved the template to a different project the errors disappeared.
from razorblade.
Related Issues (11)
- `CancellationToken` in templates HOT 3
- Make the generator self-contained (no runtime dependency) HOT 9
- Can't use template with a model when RazorBladeEmbeddedLibrary is true HOT 4
- DiagnosticId is not available in netstandard2.0 HOT 2
- Layout support HOT 4
- Cannot use RazorBlade in a roslyn SourceGenerator, because it requires C# 10, and source generators need to target netstandard2.0 which only has c# 7.3 HOT 2
- Tag helpers don't work HOT 5
- Forward base class constructors by default HOT 16
- When trying the example with a model, I get a template generated which do not accept a model arg in the ctor ? HOT 1
- Streaming HTML HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from razorblade.