Antaris / RazorEngine

Open source templating engine based on Microsoft's Razor parsing engine
http://antaris.github.io/RazorEngine
Other
2.14k stars 578 forks source link

RazorEngine Templating TemplateCompilationException #242

Open Yonoson opened 9 years ago

Yonoson commented 9 years ago

I'm trying to send an Email template with Razor engine in a non MVC project. The view that I'm trying to parse is a HTML based one, so I would like to know what is the right way to work with.

My template layout looks like this:

@*@ModelType SaleModel*@
@imports MyNamespace.Web
<!DOCTYPE html>
    <p style="font-weight:bold;text-align:center"  >
        <span>ID</span>
        <span  style="color:purple" >@Model.SaleID</span>
        <span text="   " />
        <span style="color:purple">@Model.SaleDate</span>
        <span style="color:purple">@Model.Status</span>             
    </p>
</body>
</html>

when i run

Dim tem = File.ReadAllText("Reports\Sale.vbhtml")
    Dim lsl = dcx.Sales.Find(SaleID)
    Dim bdy = Razor.Parse(tem, lsl)

i get an error

RazorEngine.Templating.TemplateCompilationException was unhandled by user code
  HResult=-2146233088
  Message=Errors while compiling a Template.

Please try the following to solve the situation:
  * If the problem is about missing references either try to load the missing references manually (in the compiling appdomain!) or
    Specify your references manually by providing your own IReferenceResolver implementation.

Currently all references have to be available as files!
  * If you get 'class' does not contain a definition for 'member': 
        try another modelType (for example 'null' or 'typeof(DynamicObject)' to make the model dynamic).

NOTE: You CANNOT use typeof(dynamic)!
    Or try to use static instead of anonymous/dynamic types.
More details about the error:

 - error: (23, 7) The name 'imports' does not exist in the current context

     - error: (46, 22) The name 'Html' does not exist in the current context

     - error: (46, 49) The type or namespace name 'CurConfig' does not exist in the namespace 'MyNamespace' (are you missing an assembly reference?)
Temporary files of the compilation can be found in (please delete the folder): 
C:\Users\UserName\AppData\Local\Temp\RazorEngine_or2vg2ii.eop

the error seems pretty detailed but, i have no idea HOW to add which assemblies and to where., please advise

matthid commented 9 years ago

VB support is not that good, but you can try to look into the temp folder and look into the generated source code files to figure out what's wrong in your case.

Yonoson commented 9 years ago

hi in %temp% i only see some vbc.... files. (such as vbc1B362114903420D9CA73333CE7AC99F.TMP) it does not seem to be txt/human readable any way i can get the log data? all the best

matthid commented 9 years ago

There is a folder path within the error message, which should point you to the folder containing the source files... You also need to set Debug to true in the RazorEngine configuration for the source files to be written.

stevenova commented 9 years ago

I'm getting the same error if I have a valid css style for page as @page,

campersau commented 8 years ago

I know this is old, but have you set the following?

config.Language = RazorEngine.Language.VisualBasic

I get the same error message if I don't set this config option. The default language is CSharp.

Yonoson commented 8 years ago

oh thanks! it wouldve been helpful back then... nowadays we just use straight html for building reports but thanks anyways, just in case... all the best!

On Sun, Jul 17, 2016 at 3:57 PM, campersau notifications@github.com wrote:

I know this is old, but have you set the following?

config.Language = RazorEngine.Language.VisualBasic

I get the same error message if I don't set this config option. The default language is CSharp.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Antaris/RazorEngine/issues/242#issuecomment-233180787, or mute the thread https://github.com/notifications/unsubscribe-auth/AKsZDRhvddiceP-OIGl0ftImw_gaGkFlks5qWibBgaJpZM4DmWOy .

Sincerely,

Yisroel M. Olewski

CEO

Machshevet.com

+972 (52) 764-9971

Websites *·* CRM · ERP · Telephony · Inventory · Content Management