Nukepayload2.CodeAnalysis.ExtendRestrictedTypes 1.0.2-beta

This is a prerelease version of Nukepayload2.CodeAnalysis.ExtendRestrictedTypes.
dotnet add package Nukepayload2.CodeAnalysis.ExtendRestrictedTypes --version 1.0.2-beta
                    
NuGet\Install-Package Nukepayload2.CodeAnalysis.ExtendRestrictedTypes -Version 1.0.2-beta
                    
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="Nukepayload2.CodeAnalysis.ExtendRestrictedTypes" Version="1.0.2-beta">
  <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="Nukepayload2.CodeAnalysis.ExtendRestrictedTypes" Version="1.0.2-beta" />
                    
Directory.Packages.props
<PackageReference Include="Nukepayload2.CodeAnalysis.ExtendRestrictedTypes">
  <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 Nukepayload2.CodeAnalysis.ExtendRestrictedTypes --version 1.0.2-beta
                    
#r "nuget: Nukepayload2.CodeAnalysis.ExtendRestrictedTypes, 1.0.2-beta"
                    
#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 Nukepayload2.CodeAnalysis.ExtendRestrictedTypes@1.0.2-beta
                    
#: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=Nukepayload2.CodeAnalysis.ExtendRestrictedTypes&version=1.0.2-beta&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Nukepayload2.CodeAnalysis.ExtendRestrictedTypes&version=1.0.2-beta&prerelease
                    
Install as a Cake Tool

RefStructHelper

中文介绍

This is a .NET analyzer project designed to extend the concept of restricted types to all ref structs in Visual Basic. This analyzer detects various operations that could throw InvalidProgramException when using restricted types.

What are Restricted Types?

Restricted types (called ref struct in C#) are structures with the System.Runtime.CompilerServices.IsByRefLikeAttribute attribute. These types:

  • Can only be allocated on the stack (cannot be boxed)
  • Cannot nest ByRef
  • Have usage restrictions related to stack references (scoped/unscoped ref) to ensure memory safety

Current Implementation

Completed Features

  • BCX31394: Detects violations of restricted types being converted to Object or ValueType
  • BCX31396: Restrictions on converting restricted types to Nullable(Of T) and related limitations
  • BCX32061: Restrictions on using restricted types as generic parameters
  • BCX36598: Prevent boxing of restricted types in LINQ
  • BCX36640: Prevent boxing of restricted types in Lambda closures
  • BCX37052: Restrictions on restricted type variables in Async/Iterator state machines
  • BCX31393: Prevent boxing when calling instance methods inherited by restricted types
  • en-US and zh-CN Localization support for diagnostic messages

Future Plans

  • Flow analysis for returning restricted types (scoped and unscoped)
  • Flow analysis for declaring variables of restricted types in Async or Iterator methods
  • Respect the allows ref struct constraint
  • More resource translations

Project Structure

RefStructHelper/                 # Main analyzer project
RefStructHelper.Demo/            # Demo project
RefStructHelper.Tests/           # Test project

Installation and Usage

Requirements

  • .NET SDK that supports Visual Basic 17.13 or later

Via NuGet Package Manager

NuGet

Via Project Reference

Add the following configuration to the target project's .vbproj file to enable the analyzer:

<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <ProjectReference Include="..\RefStructHelper\RefStructHelper.vbproj" 
                      OutputItemType="Analyzer" 
                      ReferenceOutputAssembly="false" />
  </ItemGroup>
</Project>

License

Please see the LICENSE file for licensing information.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Nukepayload2.CodeAnalysis.ExtendRestrictedTypes:

Package Downloads
Nukepayload2.CompilerServices.InteriorPointer

Provides functionality for manipulating interior pointers with VB. - Convert ByRef to interior pointer, or convert interior pointer back to ByRef. - Load or store unmanaged values indirectly. - No extra runtime dependencies. - Supports addition, subtraction, increment, decrement, equality, inequality, greater than, greater than or equal, less than, and less than or equal operator. - Provides helper types and functions for easier code conversion from C#, C++, or Classic VB to VB.NET. - Runtime-check for the use of InteriorPointer(Of T) is enabled. Commonly used types: Nukepayload2.CompilerServices.InteriorPointer Nukepayload2.CompilerServices.Unsafe.InteriorPointer(Of T) Nukepayload2.CompilerServices.Unsafe.UnsafeOperators Nukepayload2.CompilerServices.Unsafe.PinnedPointer(Of T) Nukepayload2.CompilerServices.Unsafe.TransientPointer(Of T)

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2-beta 133 8/30/2025
1.0.1-beta 127 8/30/2025
1.0.0-beta 130 8/30/2025

Initial beta release with comprehensive ref struct boxing detection for VB.NET.