RazorEngine icon indicating copy to clipboard operation
RazorEngine copied to clipboard

RazorEngine 3.7.0 works with unit test but not from web api

Open girish-a opened this issue 11 years ago • 3 comments

I have a class library(Package) in which I have some RazorEngine 3.7.0 code which parses a template.

When I invoke the Parse() method on the library from a unit test, it works, but when I call it from a web API, I get the error "Could not load file or assembly 'System.Web.Razor, Version=3.0.0.0."

Not sure why this is happening.

I have uploaded the code sample to this repo: https://github.com/girish-a/try

girish-a avatar Aug 17 '15 13:08 girish-a

The unit test is working and the webproject opens a browser with "HTTP Error 404.0 - Not Found" for me.

matthid avatar Aug 21 '15 15:08 matthid

can you try to use the latest https://www.nuget.org/packages/RazorEngine/4.2.0-beta3 ?

matthid avatar Aug 22 '15 08:08 matthid

Installing 4.2.0-beta3 did it! It works now from the API as well. Thanks!!!

But if you need to repro the issue in 3.7.0, please do the following:

  1. Set the startup project to TemplateManagement.Core.Api.
  2. From the list of web servers in VS 2015, select "Web"
  3. Press F5 - As you said, a browser instance with Http 404 appears. But along with that, you should see a console for the web server which says "Started". The configured command in project.json is Microsoft.AspNet.Hosting, so you will see the console window.
  4. From a testing tool (I use Postman - you can get it from Chrome Extensions), send an Http POST request to http://localhost:5000/api/razor/ (You can add a breakpoint to the Post method of the RazorController class).

You should be able to see the error mentioned above ("Could not load file or assembly 'System.Web.Razor, Version=3.0.0.0.")

girish-a avatar Aug 24 '15 10:08 girish-a