RazorEngine 3.7.0 works with unit test but not from web api
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
The unit test is working and the webproject opens a browser with "HTTP Error 404.0 - Not Found" for me.
can you try to use the latest https://www.nuget.org/packages/RazorEngine/4.2.0-beta3 ?
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:
- Set the startup project to TemplateManagement.Core.Api.
- From the list of web servers in VS 2015, select "Web"
- 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.
- 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.")