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 9286621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:27:44+00:00 2026-06-18T19:27:44+00:00

I am getting Cannot access a closed Stream when unit testing a Nancy web

  • 0

I am getting “Cannot access a closed Stream” when unit testing a Nancy web app.

My module is as follow:

public class MainModule : NancyModule
{
    public MainModule()
    {
        Get["/{Name}"] = p =>
            {
                var command = this.Bind<MainCommand>();
                return Response.AsJson(command.ExecuteGetMessage());
            };
    }
}

And my test is:

    [Test]
    public void Should_return_welcome_message()
    {
        // When
        var bootstrapper = new DefaultNancyBootstrapper();
        var browser = new Browser(bootstrapper);

        BrowserResponse browserResponse = browser.Get("/", with =>
            {
                with.HttpRequest();
            });

        Console.WriteLine(browserResponse.StatusCode);
        Console.WriteLine(browserResponse.Body.ToString());

        // Then
        Assert.AreEqual(HttpStatusCode.OK,browserResponse.StatusCode);
    }

UPDATE: I am getting StatusCode = NotFound and the exception happens when trying to access browserResponse.Body.

I had a look at the Nancy forum and also here at StackOverflow.
I tried this solution: Nancy test doesn't find route in other assembly

but still not working.

When I run the test in debug mode I see that my module is been called but I still cant check the returned value.

What should I do in order to get it working?

Thanks

Ademar

  • 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-18T19:27:45+00:00Added an answer on June 18, 2026 at 7:27 pm

    You are getting a NotFound response because the route you have defined is different from the route you have called.

    You are calling / in your test, but the module has a route of /{Name}.

    The exception is because there is no body with a NotFound response.

    Update your test to something like:

    var bootstrapper = new ConfigurableBootstrapper(c=>c.Module<MainModule>());
    var browser = new Browser(bootstrapper);
    BrowserResponse browserResponse = browser.Get("/ademar", with =>
            {
                with.HttpRequest();
            });
    

    * Updated to include source from the comment *

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

Sidebar

Related Questions

I am getting a pretty common, The process cannot access the file because it
I am getting this error: The process cannot access the file (...) because it
I'm getting this error The process cannot access the file 'C:\test\Person.xml' because it is
I keep getting the following error: Cannot access a disposed object. Object name: 'AdoTransaction'.
I am getting this error: TypeError: Error #1009: Cannot access a property or method
I'm getting this error: TypeError: Error #1009: Cannot access a property or method of
I've been getting... User exception thrown: TypeError: Error #1009: Cannot access a property or
I am getting following exception file :: Result000691.dat java.io.FileNotFoundException: D:\bio-rad\Result000691.dat (The process cannot access
I'm getting ObjectDisposedException was unhandled with message Cannot access a disposed object. This happens
I am getting a Cannot Find Symbol error for rowData, and columnLabels. Is the

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.