Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7067139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:09:55+00:00 2026-05-28T05:09:55+00:00

When calling the Parse method in the Razor ViewEngine, compilation errors are thrown as

  • 0

When calling the Parse method in the Razor ViewEngine, compilation errors are thrown as TemplateComplilationException which contains a list of errors. Those errors refer to temporary filenames, but the files are deleted before you can access them.

static void Main(string[] args)  
{
    var service = TemplateServiceFactory.CreateTemplateService(Language.CSharp, true);
    string result = "";
    try
    {
       result = service.Parse("Hello @DateTime.NowXX ");
    }
    catch (TemplateCompilationException ex)
    {
      foreach (var error in ex.Errors)
         if (!string.IsNullOrEmpty(error.FileName))
             Console.WriteLine( File.ReadAllText( error.FileName ));
    }  //                                         ^^^^ File does not exist!

    Console.WriteLine( result );       
    Console.ReadKey();
    }

(a little background)
I’m using the Razor engine “stand-alone” without MVC. When I call the Parse I want to get as much detailed information as possible to display to the user.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:09:55+00:00Added an answer on May 28, 2026 at 5:09 am

    RazorEngine’s TemplateCompilationException is a class that wraps a CompilerErrorCollection that contain CompilerError objects, so the most details you could possibly get from the TemplateCompilationException CompilerError objects are their respective properties, which appears to be enough to debug with. Consider and try this example

    try
    {
        Razor.Parse("My erroneous @DateTime.Now.foo()");
    }
    catch(TemplateCompilationException ex)
    {
        foreach(var error in ex.Errors)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Compile Error Num: \t" + error.ErrorNumber);
            sb.AppendLine("Error Text:\n\t" + error.ErrorText);
            Console.WriteLine(sb.ToString());
        }
        Console.WriteLine("Erroneous Template:\n\t" + ex.Template);
    }
    

    When I run my example this is what I get, which tells you the error(s) that was encountered and you can dump the template data to reference for your users.

    Compile Error Num:   CS1061
    Error Text:
      'System.DateTime' does not contain a definition for 'foo' and no 
      extension method     'foo' accepting a first argument of type 
      'System.DateTime' could be found (are you missing a using directive 
      or an assembly reference?)
    
    Erroneous Template:
        My erroneous @DateTime.Now.foo()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse objects to XML in Delphi, so I read about calling
Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
When calling a remote service (e.g. over RMI) to load a list of entities
Is possible to clone an instance calling a method on it with chaining? This
I have the following method that is supposed to parse information from an XML
I have a static method like this public static string DoSomethingToString(string UntrustedString) { //parse
I am calling a server side api which returns me the DB rows in
My Android app is calling .NET web method and it returns a single string.
In my application, which uses Spring and Hibernate, I parse a CSV file and
I am calling a restful service via the WebClient method to return some XML.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.