-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Recent change to Attribute.GetCustomAttributes is breaking in ASP.NET Core #66496
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-system-reflection Issue DetailsDescriptionI know it's possible that this was an intentional breaking change and perhaps the correct resolution is to change things in ASP.NET Core. However it's worth checking. We're getting a test failure in MapEndpoint_GeneratedDelegateWorks when it runs this logic: // Add delegate attributes as metadata
var attributes = requestDelegate.Method.GetCustomAttributes();
// This can be null if the delegate is a dynamic method or compiled from an expression tree
if (attributes != null) The exception is Note that the exception is coming from runtime code, not our test code, so this may be a real regression that would affect customers. It looks very likely that the cause is the changes in #65237 from last week. I see that previously, if the delegate was a dynamic method or compiled from an expression tree, then Is that an intentional change? It seems unlikely because:
If we have to change ASP.NET Core to try/catch around this call then technically we can do so, but perhaps other customer code would also be broken by this change, and the use of try/catch for control flow here might be problematic for perf. Reproduction StepsSee the failing build at https://dev.azure.com/dnceng/public/_build/results?buildId=1657756&view=ms.vss-test-web.build-test-results-tab&runId=45670040&resultId=102702&paneView=debug Expected behaviorRetain existing behavior of returning null. Or if you don't want to return null, then return an empty array. Actual behaviorThrows Regression?Yes, this was not happening in the last runtime build ingested by ASP.NET Core. Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
cc: @jkotas |
Probably DynamicMethod needs similar updates to the ones made in my PR (and test coverage for this). |
We should revert the original change until this is understood and fixed: #66508 |
The API is not supposed to return null, i believe we should return and empty array in this case |
This change makes DynamicMethod.GetCustomAttributes() compatible with Attribute.GetCustomAttributes(). Fix dotnet#66496
@SteveSandersonMS this is fixed in preview 5, could you check, you might need to update your code as it is now return empty array instead of null |
This issue has been marked |
This issue has been automatically marked |
This issue will now be closed since it had been marked |
Description
I know it's possible that this was an intentional breaking change and perhaps the correct resolution is to change things in ASP.NET Core. However it's worth checking.
We're getting a test failure in MapEndpoint_GeneratedDelegateWorks when it runs this logic:
The exception is
System.InvalidCastException : Unable to cast object of type 'System.Object[]' to type 'System.Attribute[]'
. An example failing build is here.Note that the exception is coming from runtime code, not our test code, so this may be a real regression that would affect customers.
It looks very likely that the cause is the changes in #65237 from last week. I see that previously, if the delegate was a dynamic method or compiled from an expression tree, then
GetCustomAttributes
would have returnednull
, whereas in the newer runtime code, it throws thisInvalidCastException
.Is that an intentional change? It seems unlikely because:
TryGetCustomAttributes
InvalidCastException
really seems to be an internal implementation detail of the runtime. I'd expect a more meaningful exception with a message saying why it's illegal to ask about custom attributes for this specific method.If we have to change ASP.NET Core to try/catch around this call then technically we can do so, but perhaps other customer code would also be broken by this change, and the use of try/catch for control flow here might be problematic for perf.
Reproduction Steps
See the failing build at https://dev.azure.com/dnceng/public/_build/results?buildId=1657756&view=ms.vss-test-web.build-test-results-tab&runId=45670040&resultId=102702&paneView=debug
Expected behavior
Retain existing behavior of returning null. Or if you don't want to return null, then return an empty array.
Actual behavior
Throws
InvalidCastException
Regression?
Yes, this was not happening in the last runtime build ingested by ASP.NET Core.
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: