NullRef in 1.0.21 #188

Closed
opened 2025-12-29 08:23:37 +01:00 by adam · 6 comments
Owner

Originally created by @zidad on GitHub (Jul 8, 2019).

Originally assigned to: @StefH on GitHub.

Upgrading my tests to WireMock 1.0.21 starting giving me a NullReferenceException, I haven't figured out why exactly:

"ClassName":"System.NullReferenceException","Message":"Object reference not set to an instance of an object.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at WireMock.ResponseBuilders.Response.ProvideResponseAsync(RequestMessage requestMessage, IFluentMockServerSettings settings) in /ResponseBuilders/Response.cs:line 419
at WireMock.Mapping.ResponseToAsync(RequestMessage requestMessage) in /Mapping.cs:line 83
at WireMock.Owin.WireMockMiddleware.InvokeInternal(HttpContext ctx) in /Owin/WireMockMiddleware.cs:line 121","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2147467261,"Source":"WireMock.Net","WatsonBuckets":null}

Originally created by @zidad on GitHub (Jul 8, 2019). Originally assigned to: @StefH on GitHub. Upgrading my tests to WireMock 1.0.21 starting giving me a NullReferenceException, I haven't figured out why exactly: "ClassName":"System.NullReferenceException","Message":"Object reference not set to an instance of an object.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at WireMock.ResponseBuilders.Response.ProvideResponseAsync(RequestMessage requestMessage, IFluentMockServerSettings settings) in /ResponseBuilders/Response.cs:line 419 at WireMock.Mapping.ResponseToAsync(RequestMessage requestMessage) in /Mapping.cs:line 83 at WireMock.Owin.WireMockMiddleware.InvokeInternal(HttpContext ctx) in /Owin/WireMockMiddleware.cs:line 121","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2147467261,"Source":"WireMock.Net","WatsonBuckets":null}
adam added the bug label 2025-12-29 08:23:37 +01:00
adam closed this issue 2025-12-29 08:23:37 +01:00
Author
Owner

@zidad commented on GitHub (Jul 8, 2019):

Looks like it could be related to this commit, probably the settings or filesystemhandler is null:

93682c9bbf (diff-9c7a467190fbb513b80085bfc57d18faR421)

Downgrading to WireMock 1.0.20 for now solves the problem.

@zidad commented on GitHub (Jul 8, 2019): Looks like it could be related to this commit, probably the settings or filesystemhandler is null: https://github.com/WireMock-Net/WireMock.Net/commit/93682c9bbffa9a1e18dac6fa06c31d396eafb9bd#diff-9c7a467190fbb513b80085bfc57d18faR421 Downgrading to WireMock 1.0.20 for now solves the problem.
Author
Owner

@StefH commented on GitHub (Jul 8, 2019):

Can you please provide your unit test example code?

@StefH commented on GitHub (Jul 8, 2019): Can you please provide your unit test example code?
Author
Owner

@zidad commented on GitHub (Jul 8, 2019):

Something as simple as this fails with me with 1.0.21:

   public class FluentMockServerTest
    {
        private readonly ITestOutputHelper _output;

        public FluentMockServerTest(ITestOutputHelper output)
        {
            _output = output;
        }

        [Fact]
        public async Task ReproduceIssue()
        {

            using (var server = FluentMockServer.Start(6003))
            {

                var assetPath = AssetHelper.GetAssetPath("content.json");

                Assert.True(System.IO.File.Exists(assetPath));

                server
                    .Given(
                        Request
                            .Create()
                            .UsingGet()
                            .WithPath("/v1/content")
                    )
                    .RespondWith(
                        Response
                            .Create()
                            .WithStatusCode(HttpStatusCode.OK)
                            .WithHeader("Content-Type", "application/json")
                            .WithBodyFromFile(assetPath)
                    );

                using (var client = HttpClientFactory.Create())
                {
                    try
                    {
                        await client.GetStringAsync("http://localhost:6003/v1/content");
                    }
                    catch (Exception e)
                    {
                        var bodyDataBodyAsJson = server.LogEntries.First().ResponseMessage.BodyData?.BodyAsJson as StatusModel;

                        _output.WriteLine($"Failed response as json: {bodyDataBodyAsJson?.Status}");

                        throw;
                    }
                }
            }
        }
    }

System.Net.Http.HttpRequestException : Response status code does not indicate success: 500 (Internal Server Error).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at System.Net.Http.HttpClient.GetStringAsyncCore(Task`1 getTask)
at xxx.FluentMockServerTest.ReproduceIssue() in xxx\MockServerTests.cs:line 43
--- End of stack trace from previous location where exception was thrown ---

In the output I find:
Failed response as json: {"ClassName":"System.NullReferenceException","Message":"Object reference not set to an instance of an object.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at WireMock.ResponseBuilders.Response.ProvideResponseAsync(RequestMessage requestMessage, IFluentMockServerSettings settings) in /ResponseBuilders/Response.cs:line 419\r\n at WireMock.Mapping.ResponseToAsync(RequestMessage requestMessage) in /Mapping.cs:line 83\r\n at WireMock.Owin.WireMockMiddleware.InvokeInternal(HttpContext ctx) in /Owin/WireMockMiddleware.cs:line 121","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2147467261,"Source":"WireMock.Net","WatsonBuckets":null}

@zidad commented on GitHub (Jul 8, 2019): Something as simple as this fails with me with 1.0.21: ``` public class FluentMockServerTest { private readonly ITestOutputHelper _output; public FluentMockServerTest(ITestOutputHelper output) { _output = output; } [Fact] public async Task ReproduceIssue() { using (var server = FluentMockServer.Start(6003)) { var assetPath = AssetHelper.GetAssetPath("content.json"); Assert.True(System.IO.File.Exists(assetPath)); server .Given( Request .Create() .UsingGet() .WithPath("/v1/content") ) .RespondWith( Response .Create() .WithStatusCode(HttpStatusCode.OK) .WithHeader("Content-Type", "application/json") .WithBodyFromFile(assetPath) ); using (var client = HttpClientFactory.Create()) { try { await client.GetStringAsync("http://localhost:6003/v1/content"); } catch (Exception e) { var bodyDataBodyAsJson = server.LogEntries.First().ResponseMessage.BodyData?.BodyAsJson as StatusModel; _output.WriteLine($"Failed response as json: {bodyDataBodyAsJson?.Status}"); throw; } } } } } ``` System.Net.Http.HttpRequestException : Response status code does not indicate success: 500 (Internal Server Error). at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() at System.Net.Http.HttpClient.GetStringAsyncCore(Task`1 getTask) at xxx.FluentMockServerTest.ReproduceIssue() in xxx\MockServerTests.cs:line 43 --- End of stack trace from previous location where exception was thrown --- In the output I find: ` Failed response as json: {"ClassName":"System.NullReferenceException","Message":"Object reference not set to an instance of an object.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at WireMock.ResponseBuilders.Response.ProvideResponseAsync(RequestMessage requestMessage, IFluentMockServerSettings settings) in /ResponseBuilders/Response.cs:line 419\r\n at WireMock.Mapping.ResponseToAsync(RequestMessage requestMessage) in /Mapping.cs:line 83\r\n at WireMock.Owin.WireMockMiddleware.InvokeInternal(HttpContext ctx) in /Owin/WireMockMiddleware.cs:line 121","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2147467261,"Source":"WireMock.Net","WatsonBuckets":null}`
Author
Owner

@StefH commented on GitHub (Jul 8, 2019):

Thanks, I'll look into this.

@StefH commented on GitHub (Jul 8, 2019): Thanks, I'll look into this.
Author
Owner

@StefH commented on GitHub (Jul 8, 2019):

@zidad Can you try 1.0.22 preview version from MyGet ? (https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)

WireMock.Net.1.0.22-ci-11507

// btw : don't use a hard-coded port in your unit-tests

@StefH commented on GitHub (Jul 8, 2019): @zidad Can you try 1.0.22 preview version from MyGet ? (https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions) `WireMock.Net.1.0.22-ci-11507` // btw : don't use a hard-coded port in your unit-tests
Author
Owner

@zidad commented on GitHub (Jul 15, 2019):

Hi @StefH, it works, and thanks for the tip about the ports! :)

@zidad commented on GitHub (Jul 15, 2019): Hi @StefH, it works, and thanks for the tip about the ports! :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#188