mirror of https://github.com/dapr/dotnet-sdk.git
Fixing an issue of a null reference exception where the model binder is checked against a null BindingSource (#371)
This commit is contained in:
parent
3b5065f283
commit
aa52a5d6a2
|
|
@ -29,7 +29,7 @@ namespace Dapr.AspNetCore
|
|||
|
||||
private static bool CanBind(ModelBinderProviderContext context, out Type type)
|
||||
{
|
||||
if (context.BindingInfo.BindingSource.Id == "state")
|
||||
if (context.BindingInfo.BindingSource?.Id == "state")
|
||||
{
|
||||
// [FromState]
|
||||
type = Unwrap(context.Metadata.ModelType);
|
||||
|
|
|
|||
|
|
@ -46,5 +46,12 @@ namespace Dapr.AspNetCore.IntegrationTest.App
|
|||
state.Value.Count++;
|
||||
await state.SaveAsync();
|
||||
}
|
||||
|
||||
[HttpPost("/echo-user")]
|
||||
public ActionResult<UserInfo> EchoUser([FromQuery]UserInfo user)
|
||||
{
|
||||
// To simulate an action where there's no Dapr attribute, yet MVC still checks the list of available model binder providers.
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,5 +69,19 @@ namespace Dapr.AspNetCore.IntegrationTest
|
|||
widget.Count.Should().Be(18);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ModelBinder_CanGetOutOfTheWayWhenTheresNoBinding()
|
||||
{
|
||||
using (var factory = new AppWebApplicationFactory())
|
||||
{
|
||||
var httpClient = factory.CreateClient();
|
||||
var daprClient = factory.DaprClient;
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/echo-user?name=jimmy");
|
||||
var response = await httpClient.SendAsync(request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue