JetBrains / JetBrains/ExternalAnnotations
Add InstantHandle annotations for NUnit Assert.DoesNotThrow overloads
- Dominant language
- Kotlin
- Stars
- 84
- Forks
- 46
- Avg merge
- 6h 55m
- Merged PRs (30d)
- 1
Description
### Summary
JetBrains' NUnit external annotations do not currently cover the `System.Action` overloads introduced by NUnit 4.6 for `Assert.DoesNotThrow`. As a result, Rider/ReSharper inspections can treat the callback as escaping the current scope and report false-positive closure/disposal warnings.
### Affected API
NUnit 4.6.0 and later add these overloads:
```csharp
public static void DoesNotThrow(Action code);
public static void DoesNotThrow(Action code, string message, params object[] args);
```
The existing JetBrains annotations cover the older `NUnit.Framework.TestDelegate` overloads, but not these `System.Action` overloads:
```xml
```
### How to reproduce
With NUnit 4.6.1 and Rider/ReSharper's nullable/disposal inspections enabled:
```csharp
using NUnit.Framework;
using System.Windows.Forms;
using var treeView = new TreeView();
Assert.DoesNotThrow(() => treeView.Nodes.Clear());
```
The callback is executed synchronously by NUnit, but the `Action` overload is not recognized as an instant-handle callback because the external annotation is missing. This results in a false-positive warning about using a disposable value from an outer scope ("AccessToDisposedClosure: Captured variable is disposed in the outer scope").
### Proposed change
The `code` parameter of both `System.Action` overloads should be annotated with `JetBrains.Annotations.InstantHandleAttribute`, just like the existing `TestDelegate` overloads. Rider/ReSharper should then understand that the callback is invoked immediately and should not report the false positive.
### Proposed annotation
```xml
```
### Version information
- NUnit: 4.6.1 (introduced with the NUnit 4.6 API changes)
- JetBrains Rider: current 2026.2 installation tested
- Target framework: .NET Framework 4.6.2
### Related references
- NUnit PR [#5196](https://github.com/nunit/nunit/pull/5196), which introduced the delegate API changes
### Workaround
Projects can temporarily provide the proposed XML in an `ExternalAnnotations/NUnit.Framework/` folder next to their solution. Alternatively, they can avoid the `DoesNotThrow` wrapper or suppress the affected IDE inspection, but neither workaround provides the correct library metadata.
Contributor guide
No contributing guide indexed for this repository
Research direction
Locate the NUnit.Framework external-annotation XML and compare the existing Assert.DoesNotThrow(TestDelegate) entries with the two System.Action overloads described in the issue. Add matching InstantHandle annotations for both code parameters, then validate the supplied NUnit/Rider reproduction no longer reports the closure or disposal warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 75/100