AppVer.Development.CodeAnalyzer.VisualBasic 1.1.2

dotnet add package AppVer.Development.CodeAnalyzer.VisualBasic --version 1.1.2
                    
NuGet\Install-Package AppVer.Development.CodeAnalyzer.VisualBasic -Version 1.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AppVer.Development.CodeAnalyzer.VisualBasic" Version="1.1.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AppVer.Development.CodeAnalyzer.VisualBasic" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="AppVer.Development.CodeAnalyzer.VisualBasic">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AppVer.Development.CodeAnalyzer.VisualBasic --version 1.1.2
                    
#r "nuget: AppVer.Development.CodeAnalyzer.VisualBasic, 1.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AppVer.Development.CodeAnalyzer.VisualBasic@1.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AppVer.Development.CodeAnalyzer.VisualBasic&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=AppVer.Development.CodeAnalyzer.VisualBasic&version=1.1.2
                    
Install as a Cake Tool

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
There are no supported framework assets in this package.

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.

Version Downloads Last Updated
1.1.2 111 8/11/2026
1.1.1 94 8/11/2026
1.0.11 107 7/13/2026