Circuit Disposal Before DotNetInvoke Causes Unhandled NullReferenceException
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
While investigating #45638, we found that JSInterop DotNet Invocation is being called on a circuit that has already been disposed from an exception during a RegExAttribute validation, which causes a `NullReferenceException`. While the particular `System.Format` error was caused by user error (unescaped curly braces which get parsed as empty formatting), there shouldn't be invocations on an already disposed circuit.
### Expected Behavior
There may need to be a restructure or added check(s) to ensure that the circuit is expected to be not null for the entirety of the invocation.
### Steps To Reproduce
https://github.com/Nick-Stanton/RegExCircuitCrash - Modified from the submitted repro in #45638
- Take note of the first RegEx in `Data\DataAnnotationsTest.cs` to see what may be invalidated.
- Launch app and navigate to "Data annotation test"
- Enter something invalid into the left text box (e.g. the character '=')
### Exceptions (if any)
In order of first appearance:
- System.FormatException: 'Input string was not in a correct format.'
- System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'
- System.OperationCanceledException: 'The operation was canceled.'
- System.Threading.Tasks.TaskCanceledException: 'A task was canceled.'
- System.NullReferenceException: 'Object reference not set to an instance of an object.'
### .NET Version
6.0+, untested on earlier versions
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.