4

I'm using Nancy 0.14.1.0 with a Razor view. Things are going fine as long as I work with the internal webserver in VS 2010. Now I did deploy the stuff to my webserver running IIS 6. The route is

       Get["/api/v1/admin/clients"] = parameters => {
            return View["Admin/view", new DataAccessLayer(Context).admin_get_clients()];
        };

which returns a List of clients (doesn't matter here).

The directory structure on the server is

bin
Content
Shared
   |--- _Layout.cshtml
Views
   |--- Admin
         |--- view.cshtml

The exception I catch is

Nancy.ViewEngines.ViewNotFoundException: Unable to locate view 'Admin/view' Currently available view engine extensions: sshtml,html,htm Locations inspected: ,,,,views/api/Admin/view,api/Admin/view,views/Admin/view,Admin/view Root path: C:\Inetpub\Websites\Test\api\ 

What concerns me a bit is the "available view engine extensions" entry: I'm missing cshtml here... although I guess my web.config contains the right entry:

<compilation debug="true" targetFramework="4.0">
  <buildProviders>
    <add extension=".cshtml" type="Nancy.ViewEngines.Razor.BuildProviders.NancyCSharpRazorBuildProvider, Nancy.ViewEngines.Razor.BuildProviders" />
    <add extension=".vbhtml" type="Nancy.ViewEngines.Razor.BuildProviders.NancyVisualBasicRazorBuildProvider, Nancy.ViewEngines.Razor.BuildProviders" />
  </buildProviders>


</compilation>

The Nancy Module behind works fine: I have added the route

        Get["/api/v1/admin/clients/{id}"] = parameters => {
            return "Hello";
        };

and get the "Hello"...

Any hints?

Prasanth
  • 3,029
  • 31
  • 44
decades
  • 827
  • 17
  • 25

4 Answers4

2

You haven't deployed the Nancy razor package, or it can't load it for some reason (dependency missing maybe), that's why it does't list the file types.

Steven Robbins
  • 26,441
  • 7
  • 76
  • 90
  • deployed the Nancy razor package? How? For me, I have already installed `Nancy.Viewengines.Razor.1.4.1` from nuget. – zwcloud Sep 25 '18 at 12:03
1

Close, but the Nancy razor packag wasn't missing. The Nancy razor package was deployed. The only thing missing was System.Razor.dll. I deployed that too and done :)

decades
  • 827
  • 17
  • 25
  • 1
    Hence "or it can't load it for some reason (dependency missing maybe)" ;-) – Steven Robbins Jan 16 '13 at 15:23
  • do you mean System**.Web**.Razor.dll ? – superjos Mar 21 '13 at 11:40
  • 2
    Not OP, but I believe it's `System.Web.Razor.dll`. Looking in my `bin\Release` directory there was a file called `Nacy.ViewEngines.Razor.xml`. I saw a reference to the `System.Web.Razor` namespace in the file. Adding the reference, set `Copy Local` to true, and my problem, same as OP's, was resolved. – DJH Feb 18 '15 at 12:16
  • I had different System.Web.Razor versions in the app project and test project. Upgrading the one in the test project, to match the one from app project, fixed the problem. – ConstantinM Jan 26 '19 at 06:16
0

I find this issue still happening with the Nancy template projects. You need to remove and re-add the Nancy nuget references. Enabling package restore doesn't seem to be enough.

nathanchere
  • 8,008
  • 15
  • 65
  • 86
0

I ran into this problem self-hosting Nancy from a console application which referenced a separate DLL "web" project. The razor DLLs weren't being copied to the output folder even though the console project referenced the web project, and the web project references the appropriate razor libraries.

Since the razor DLLs are loaded dynamically, they were not copied to console's output folder. More discussion on the underlying issue here: Is "Copy Local" transitive for project references?

Community
  • 1
  • 1
Frank Schwieterman
  • 24,142
  • 15
  • 92
  • 130