AppVer.Development.CodeAnalyzer.VisualBasic
1.1.1
See the version list below for details.
dotnet add package AppVer.Development.CodeAnalyzer.VisualBasic --version 1.1.1
NuGet\Install-Package AppVer.Development.CodeAnalyzer.VisualBasic -Version 1.1.1
<PackageReference Include="AppVer.Development.CodeAnalyzer.VisualBasic" Version="1.1.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="AppVer.Development.CodeAnalyzer.VisualBasic" Version="1.1.1" />
<PackageReference Include="AppVer.Development.CodeAnalyzer.VisualBasic"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add AppVer.Development.CodeAnalyzer.VisualBasic --version 1.1.1
#r "nuget: AppVer.Development.CodeAnalyzer.VisualBasic, 1.1.1"
#:package AppVer.Development.CodeAnalyzer.VisualBasic@1.1.1
#addin nuget:?package=AppVer.Development.CodeAnalyzer.VisualBasic&version=1.1.1
#tool nuget:?package=AppVer.Development.CodeAnalyzer.VisualBasic&version=1.1.1
AppVer.Development.CodeAnalyzer.VisualBasic
Roslyn analyzers for Visual Basic projects.
Explicit return statements
Enforces explicit Return or Throw statements in all functions to help prevent hidden fall-through paths.
- Reports missing return paths as warnings by default (configurable via
.editorconfig). - Supports Visual Basic projects targeting .NET Framework and .NET Core.
Function CalculateValue(x As Integer) As Integer
If x > 10 Then
Return 5
End If
' Missing explicit Return or Throw
End Function
Ref-struct safety for VB.NET
Visual Basic can consume ref-like types such as Span(Of T), ReadOnlySpan(Of T), and C# ref struct types through a compiler workaround, but the VB compiler does not enforce C# ref-struct lifetime rules. These analyzers restore that safety at compile time.
The VB workaround
Apply a non-error Obsolete attribute to members (or types) that use ref-like types:
Imports System
<Obsolete("Allow ref structs", False)>
Public Sub ReadSecondValue()
Dim values As New Span(Of Integer)({1, 2, 3})
Console.WriteLine(values(1))
End Sub
For fields and properties, apply the attribute at class level:
<Obsolete("Allow ref structs", False)>
Public Class BufferView
Private _span As Span(Of Integer)
End Class
The analyzer treats every ref-like use as safety-sensitive. See RefStructSafetyPlan.md for full design details.
Diagnostics
| ID | Rule | Default severity |
|---|---|---|
| VBRS0001 | Ref-like value cannot convert to a reference type or be boxed | Warning |
| VBRS0002 | Ref-like local cannot be captured by a lambda | Warning |
| VBRS0003 | Ref-like value cannot be stored in a field, auto-property, or Static Dim |
Warning |
| VBRS0004 | Ref-like value cannot be retained in an async method | Warning |
| VBRS0005 | Ref-like value cannot be retained in an iterator method | Warning |
| VBRS0006 | Ref-like type cannot be used as array element or generic type argument | Warning |
Async and iterator safety is covered entirely by VBRS0004/0005 (conservative retention at declaration). There are no separate use-after-Await/Yield rules.
ByRef parameters
Passing a ref-like value ByRef is not diagnosed at the call site. Dangerous callee behavior is caught inside the callee by the rules above:
- Field or auto-property storage → VBRS0003
- Boxing or reference conversion → VBRS0001
- Lambda capture → VBRS0002
ByRef parameters cannot appear in Async or Iterator methods (compiler error BC36926), so retention rules do not apply to that path.
For compiled C# APIs (BCL, NuGet libraries), ref-like ByRef parameters were checked by C#'s ref-safety analysis at compile time. For other VB assemblies compiled with the same Obsolete workaround and consumed only as metadata, passing ref-like values ByRef is caller-beware — the analyzer cannot see those bodies.
Example violations
' VBRS0001: boxing
Dim s As Span(Of Integer)
Dim o As Object = s
' VBRS0002: lambda capture
Dim f = Function() s.Length
' VBRS0003: field storage
Private _span As Span(Of Integer)
' VBRS0004: ref-like local in Async method
Public Async Function M() As Task
Dim s As Span(Of Integer)
End Function
Configuration
Configure severity per diagnostic in .editorconfig.
Example:
dotnet_diagnostic.VBRS0001.severity = error
dotnet_diagnostic.VBRS0002.severity = warning
dotnet_diagnostic.VBRS0003.severity = none
Usage
Install the NuGet package for your VB project. Visual Studio and dotnet build will run the analyzers automatically under Analyzers in Solution Explorer.
dotnet add package AppVer.Development.CodeAnalyzer.VisualBasic
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.