-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Descriptive Error for Improper Use of [AsParameters] #58218
base: main
Are you sure you want to change the base?
Conversation
Converting draft to PR despite some failing tests in Interop.FunctionalTests. [QuarantinedTest("https://github.com//issues/41074")] Justification: Seems like those tests failed with no regard to my changes. Also, tests are failing for the main branch. |
FYI @captainsafia |
/azp run |
Commenter does not have sufficient privileges for PR 58218 in repo dotnet/aspnetcore |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
@@ -821,6 +821,15 @@ private static Expression CreateArgument(ParameterInfo parameter, RequestDelegat | |||
$"Nested {nameof(AsParametersAttribute)} is not supported and should be used only for handler parameters."); | |||
} | |||
|
|||
// Parameters like IFormFileCollection should throw "The abstract type ... is not supported" rather than |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we can't throw this exception in the same place where the other exception is thrown?
throw new InvalidOperationException($"The abstract type '{TypeNameHelper.GetTypeDisplayName(type, fullName: false)}' is not supported."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@captainsafia
Fixed. I moved the exception to ParameterBindingMethodCache.cs, works well.
@smnsht Thanks for changing the code here! I also realized that similar to the other PR you're working on, we'll need to add checks in the RDG implementation for this. Here is the code that needs to be modified in the source generator. Instead of throwing there, we emit diagnostics when the type is invalid. |
Done |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
@@ -466,6 +467,12 @@ private static bool TryGetAsParametersConstructor(Endpoint endpoint, INamedTypeS | |||
return false; | |||
} | |||
|
|||
if (type.AllInterfaces.Any(x => x.ToString() == typeof(IEnumerable).FullName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing a string-based comparison check, we should do a symbol-based comparison using the extension method that is defined here.
You'll need to add the IEnumerable type to the well-known types cache in this file then resolve it from the WellKnownTypes cache based to this call path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do this in February.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for letting me know! I removed the pr: pending author input
label so that the bot doesn't out-close your PR in the meantime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
symbol-based comparison - done.
Appreciate the tip!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
Files not reviewed (1)
- src/Http/Http.Extensions/gen/Resources.resx: Language not supported
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
Descriptive Error for Improper Use of [AsParameters]
Description
Throw NotSupportedException if [AsParameters] is applied to an enumerable class.
Preserve existing behavior for collections that are also abstract classes, like IFormCollection. In order to do this, a dedicated unit test was added.
Fixes #56114