-
Notifications
You must be signed in to change notification settings - Fork 10.3k
.NET 7 Preview 7 ProblemDetailsService is not working as expected. #43261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cc @brunolins16 |
@TanvirArjel I have very happy that you have tried the new ProblemDetailsService 😁. If you take a look at the same release notes (Diagnostics middleware updates) we mentioned about updates in the middleware to make the response consistent and there we have mentioned a key important aspect of this change. The following sample configures the app to generate a problem details response for all HTTP client and server error responses that do not have a body content yet. Basically, it means that once you have a body defined the middleware will not call the problem details service to generate a In your code |
Yes! That's why this behavior is inconsistent and error-prone and the response for the bad requests always should be the same. |
With all that said, that is the current expected behavior. However, I can understand your expectation once the service is registered and I think since now we have a service that allow a consistent generation might be an interesting change to generate PD in these scenarios as well, |
Yes! otherwise, the Client App calling the ASP.NET Core API will be broken while handling the bad request error response. |
Totally agree! I think we have commented at same time. In my opinion, adding the new service was a start point to make the Problem Details generation consistent, but we still need to make additional changes to allow it to be customizable and consistent in scenarios as you mentioned. |
For now, to make it consistent I recommend you keep using |
@brunolins16 This is a very crucial bug. I am surprised that this very basic requirement is not noticed by ASP.NET Core Team while they are going to release version 7.0 soon. |
Thanks! I am aware of this. |
I understand you, but I don't see, in your specific example, how uglier it is since it is basically a validation problem already,
I was the team member who worked on this and to be honest probably I missed because the main scenario was the Unfortunately, we are very late in .NET 7 development and might not be possible to have it done :( |
@brunolins16 Wish you all the very best for dotNET 8.0 :) But please don't miss this. |
I see! It's a good workaround. Thanks again. |
But would that writer even be invoked? It seems like the If you want the behavior you're after you should check out the ProblemDetailsMiddleware nuget which supports that and more. My hope was to migrate off it but I'm not sure it'll be possible as I rely on some of the features that aren't included in the new services |
@pinkfloydx33 it does, let me double check and share with you where it is called. |
It is called here
|
Any writer registered before the call to the |
Ahh my mistake... It's tucked away in the factory; I was looking for it in the writer similar to the default one. Good to know it's there.
Ok...so if using MVC Controllers (and not minimal API) you'd have to be sure to call FWIW the outputs from the two are mostly the same anyways, though by default |
Exactly.
The biggest difference between them is the MVC implementation supports content-negotiation, so, we can produce XML Problem Details. |
Hi, I think this may be related, but the casing for ProblemDetails is also inconsistent. ProblemDetails itself defaults to camel case, but as you can see above when describing the "Summary" field, it's capitalized. Shouldn't that be lower case, assuming @TanvirArjel is using the default naming policy? I've also noticed ProblemDetails does not obey
should give a response like
but it does not, at least from what I can tell. Maybe this is by design since the spec (https://www.rfc-editor.org/rfc/rfc7807) explicitly lists the properties lower/regular camel case, but it also doesn't seem to explicitly call out camelcase must be used. I think anyone who is using problem details should be able to use whatever casing their API uses already rather than being forced to either a) have inconsistent casing returned or b) use camel case. |
In MVC for scenarios where the Validation Problem Details is auto generated, by default, it does not change it unless (.NET 7 only) you:
services..AddControllers(options => options.ModelMetadataDetailsProviders.Add(new SystemTextJsonValidationMetadataProvider()))
services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.DictionaryKeyPolicy = System.Text.Json.JsonNamingPolicy.CamelCase;
}); We have plans to make the provider default for |
@jchoca Interesting, let me investigate but problem details serialization should use the naming policy. Can you share a simplified repro? |
@jchoca I just took a look at our
|
@brunolins16 thanks for checking! I created a simple web app here that illustrates the problem: https://github.com/jchoca/ProblemDetailsJsonSettings if you hit the root endpoint it returns pascal case, but if you hit |
I had to register my custom |
@zwoolli If I am not mistaken @Rick-Anderson maybe we could add something about it in the docs if not there yet. |
See #29152 |
@brunolins16 - You are correct. I looked into it and
|
@TanvirArjel is this still an issue for you. If it is could you post a repro of the original issue including an example of the HTTP requests that you are firing into the controller? I tried to repro the issue you were describing and couldn't which makes me think that there is some context missing. |
Hi @TanvirArjel. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate. See our Issue Management Policies for more information. |
Is there an existing issue for this?
Describe the bug
The release note says that:
I have done so. Now I have the following endpoint:
Now if I don't provide the value of the summary then the response shows as follows:
This is fine!
But when I provide less than 100 chars, the response shows as follows:
Which is totally inconsistent. I want the response should be:
I have also tried the following but the result is the same:
.NET Version
.NET 7.0 Preview 7
The text was updated successfully, but these errors were encountered: