[Bug]: In a simple setup with co-hosted controllers: System.ObjectDisposedException: Message is closed.
- Dominant language
- C#
- Stars
- 1.8k
- Forks
- 320
- PR merge metrics
- No merged PRs in 30d
Description
### Duplicate ?
- [X] I have searched issues/discussions and did not find other issues/discussions reporting this bug.
### Product version
1.5.2
### Describe expected behavior
CoreWCF services function properly.
### Describe actual behavior
Receiving an exception
`System.ObjectDisposedException: Message is closed.`
with the following stack trace
```
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.ObjectDisposedException: Message is closed.
at CoreWCF.Channels.BufferedMessage.get_Properties()
at CoreWCF.Channels.AspNetCoreReplyChannel.HandleRequest(HttpContext context)
at CoreWCF.Channels.RequestDelegateHandler.HandleRequest(HttpContext context)
at CoreWCF.Channels.ServiceModelHttpMiddleware.InvokeAsync(HttpContext context)
at CoreWCF.Channels.MetadataMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at NSwag.AspNetCore.Middlewares.SwaggerUiIndexMiddleware.Invoke(HttpContext context)
at NSwag.AspNetCore.Middlewares.RedirectToIndexMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
```
Absolutely no special middleware/interceptor that can read the message has been registered.
My setup:
```
builder.Services.AddServiceModelServices();
builder.Services.AddServiceModelMetadata();
builder.Services.AddSingleton();
```
```
app.UseStaticFiles(...);
app.UseSwaggerUi(x => x.DocumentPath = "/openapi.yaml");
app.UseAuthentication();
app.UseAuthorization();
app.UseServiceModel(serviceBuilder =>
{
serviceBuilder.AddService();
serviceBuilder.AddServiceEndpoint(new WSHttpBinding(SecurityMode.None), "/soap");
var serviceMetadataBehavior = app.Services.GetRequiredService();
serviceMetadataBehavior.HttpGetEnabled = true;
});
app.MapControllers();
```
### Which binding
WsHttp
### security
None
### Which .NET version
.NET 7
### Which os platform
Windows
### Code snippet used to reproduce the issue
_No response_
### Stacktrace if any
```shell
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.ObjectDisposedException: Message is closed.
at CoreWCF.Channels.BufferedMessage.get_Properties()
at CoreWCF.Channels.AspNetCoreReplyChannel.HandleRequest(HttpContext context)
at CoreWCF.Channels.RequestDelegateHandler.HandleRequest(HttpContext context)
at CoreWCF.Channels.ServiceModelHttpMiddleware.InvokeAsync(HttpContext context)
at CoreWCF.Channels.MetadataMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at NSwag.AspNetCore.Middlewares.SwaggerUiIndexMiddleware.Invoke(HttpContext context)
at NSwag.AspNetCore.Middlewares.RedirectToIndexMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
```
Contributor guide
Assessment
This issue has not been assessed yet.