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

  • Home
  • SEARCH
  • 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 8446697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:59:30+00:00 2026-06-10T09:59:30+00:00

In a previous question Does Nancy.Testing support nested Razor views? I outlined the difficulties

  • 0

In a previous question Does Nancy.Testing support nested Razor views? I outlined the difficulties I was having with Nancy unit tests failing when presented with nested razor layouts.

After investigation I can now refine that information. The problem is not related to nesting it is simply this: If you include a @using statement in a razor layout or view, then Nancy will fail to find that referenced namespace if accessed from a unit-test.

For example:

Master Layout

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Test</title>    
    </head>
    <body>
        @RenderBody()        
    </body>
</html>

View

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
@{
    Layout = "Master.cshtml";
}
hello World 

As you would expect, this works fine. However if we now add a bit of server side processing to the master layout, and so create the need for a @using statement, then unit tests fail (the code runs fine normally, only the unit tests fail) with:

Error Compiling Template: (15, 11) The type or namespace name ‘uMentor’ could not be found.

Master Layout with server-side code

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
@using uMentor.Extensions
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>@Model.Title</title>   
    </head>
    <body>
        @{
            var user = Html.GetCurrentUser();
        }
        @RenderBody()        
    </body>
</html>

I have ensured that my web.config (both the web-site project and the unit-test project) have the correct razor assemblies and namespaces mentioned:

Web.config

<configSections>
  <section name="razor" type="Nancy.ViewEngines.Razor.RazorConfigurationSection, Nancy.ViewEngines.Razor" />
</configSections>
<razor disableAutoIncludeModelNamespace="false">
  <assemblies>
    <add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <add assembly="Nancy" />
    <add assembly="uMentor" />
  </assemblies>
  <namespaces>
    <add namespace="Nancy" />
    <add namespace="uMentor" />
    <add namespace="uMentor.Domain" />
    <add namespace="uMentor.Extensions" />
  </namespaces>
</razor>

Stripping everything back, I can build the simplest ‘hello world’ view -> layout with nothing in it, no code. The unit test passes (the response body has the correct html in it). I then put in a redundant @using statement at the top of the view or the layout and the test fails (the response body contains the error message above).

Master Layout with @using only – Fails

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
@using uMentor.Extensions
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Test</title>   
    </head>
    <body>
        @RenderBody()        
    </body>
</html>

Therefore, the evidence suggests that placing a @using statement into a razor view or layout causes a razor compilation error that silently fails, returning the error message in the response body. Only if your test happens to check the body content will you find out there has been a problem.

Thank you for any help.

  • 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-06-10T09:59:31+00:00Added an answer on June 10, 2026 at 9:59 am

    My first guess is to move the config from the web.config to the app.config.
    This worked for me, though I don’t know why.

    Also I love Nancy, it’s brilliant, but the documentation sucks really. Because of this when I am developing Nancy apps, I hook it’s source code into the project (only the relevant parts of course) and than when I face any problems I go into Nancy’s source code and find the problem myself. The code is well written it’s easy to read.

    Cheers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question was inspired by a previous question posted on SO, Does the order
Possible Duplicate: What does ||= mean? In this previous question, I asked about an
This question is based on a previous question: How does C# compilation get around
Following on from a previous question , I am having trouble combining the Lazy<T>
This is brought on by a previous question . Apparently ImageList doesn't support animated
This is a generalization of my previous question about pluralize filter: Does lift have
So this question follows on from my previous question Under what conditions does a
From Previous Question I got some idea about having composite primary key in n-m
Going back to my previous question on OCSP, does anybody know of reliable OCSP
This is conjunction with my previous question https://stackoverflow.com/questions/8428911/jcs-disk-cache-data-retrieval Does JCS read from disk even

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.