Skip to content

Add: XPC3004 error diagnostics, to avoid people using RegisterStep<Entity, LocalPluginContext> which fails at runtime.#7

Merged
mkholt merged 3 commits intomainfrom
fix-registerstep-with-localplugincontext-306
Mar 31, 2026
Merged

Add: XPC3004 error diagnostics, to avoid people using RegisterStep<Entity, LocalPluginContext> which fails at runtime.#7
mkholt merged 3 commits intomainfrom
fix-registerstep-with-localplugincontext-306

Conversation

@mkholt
Copy link
Copy Markdown
Member

@mkholt mkholt commented Mar 31, 2026

This pull request introduces a new analyzer and code fix to prevent a common runtime error when using RegisterStep<TEntity, TService> with LocalPluginContext as the service type. It adds a Roslyn analyzer that detects this misuse at compile time, provides a code fix to automatically rewrite the call to the correct RegisterPluginStep<TEntity> API, and documents the rule and its rationale. Comprehensive tests are included to ensure correct diagnostic and code fix behavior.

Key changes:

Analyzer and Code Fix Implementation

  • Added LocalPluginContextAsServiceAnalyzer to report an error (XPC3004) when RegisterStep<TEntity, LocalPluginContext> is used, preventing a runtime exception due to LocalPluginContext not being registered in the DI container. [1] [2]
  • Added LocalPluginContextAsServiceCodeFixProvider to provide an automatic fix that rewrites RegisterStep<TEntity, LocalPluginContext> to RegisterPluginStep<TEntity>.

Diagnostics and Rule Documentation

  • Registered the new diagnostic rule XPC3004 in AnalyzerReleases.Unshipped.md and documented it in README.md and a new rule file rules/XPC3004.md. [1] [2] [3]
  • Added a detailed rule explanation and examples for XPC3004, including both interim and recommended migration paths.

Testing

  • Introduced comprehensive unit tests in LocalPluginContextAsServiceAnalyzerTests to verify the analyzer and code fix, including positive and negative cases, code fix correctness, and title.

These changes help catch a subtle but critical error at compile time, improving developer experience and reliability when migrating or writing plugins with dependency injection.


This fixes #6

@mkholt mkholt merged commit 36d8e12 into main Mar 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RegisterStep<T> with Action<LocalPluginContext> method group silently resolves to wrong overload, causing StackOverflow

1 participant