Skip to content

Quality

Compile-time diagnostics

The generator validates every store and fails the build with a precise message rather than emitting code that does not compile.

Overview

All 29 diagnostics live in the Bit.Blex.Generators category. Of those, 24 are errors - they describe shapes the generator genuinely cannot emit - and 5 are warnings about code that compiles but almost certainly does not do what you meant.

CodeSeveritySummary
BLEX001 Error Store class must be partial
BLEX002 Error Cannot derive action name
BLEX003 Error Cannot derive computed name
BLEX004 Error Computed method must be parameterless
BLEX005 Error Generated member name collides
BLEX006 Error Unsupported store class shape
BLEX007 Error Effect method must return Task or ValueTask
BLEX008 Error Blex member must be a writable instance member
BLEX009 Warning Latest effect cannot cancel without a CancellationToken
BLEX010 Error Action must not be 'async void'
BLEX011 Warning Action return value is discarded
BLEX012 Error State field name equals generated property name
BLEX013 Error Unsupported parameter modifier
BLEX014 Error Generic action/effect/computed methods are not supported
BLEX015 Error Store must be a plain class
BLEX016 Error Store cannot have another base class
BLEX017 Error Computed method must return a value
BLEX018 Warning Blex member attribute outside a store
BLEX019 Error Effect debounce cannot be negative
BLEX020 Warning Typed action descriptors are not generated
BLEX021 Error Action name is used more than once
BLEX022 Error Effect retry and timeout values cannot be negative
BLEX023 Error Effect timeout needs a CancellationToken
BLEX024 Error Store version cannot be negative
BLEX025 Warning Store version has no effect without Persist
BLEX026 Error Store declares a member the generator overrides
BLEX027 Error Effect throttle cannot be negative
BLEX028 Error Effect cannot both debounce and throttle
BLEX029 Error State comparer is not an equality comparer of the state's type
Nothing is emitted for a rejected store

When a store fails validation, the generator reports the diagnostic and emits no partial for it. Expect a cascade of "does not contain a definition for Count" errors alongside the Blex diagnostic - fix the Blex one first and the rest disappear.

Suppressing a warning

The 5 warnings are suppressible like any other - BLEX009, say, for a Latest effect whose superseded runs are fine to let finish.

MyApp.csproj
<PropertyGroup>
  <NoWarn>$(NoWarn);BLEX009</NoWarn>
</PropertyGroup>
Or locally
#pragma warning disable BLEX009
[BlexEffect(Concurrency = BlexEffectConcurrency.Latest)]
// Writes no state, so a superseded run finishing is harmless; one assigning state would overwrite the newer run's.
private async Task OnTrackView(string page) => await _analytics.TrackPageViewAsync(page);
#pragma warning restore BLEX009

BLEX001 - Store class must be partial

The generator adds members through a second partial declaration, so the class has to be partial.

Rejected
[BlexStore]
public class CounterStore   // BLEX001
{
    [BlexState] private int _count;
}
Fix
[BlexStore]
public partial class CounterStore
{
    [BlexState] private int _count;
}

BLEX002 - Cannot derive action name

An action or effect method must either start with On followed by an uppercase letter, or supply a usable Name. Note that a Name containing spaces is treated as a display label only, so the method still needs the On prefix.

Rejected
[BlexAction]
private void Increment() { }              // BLEX002 -- no "On" prefix

[BlexAction(Name = "Apply preset")]
private void ApplyPreset() { }            // BLEX002 -- label only, still no "On"
Fix
[BlexAction]
private void OnIncrement() { }            // -> Increment()

[BlexAction(Name = "Bump")]
private void Increment() { }              // -> Bump()   (valid identifier)

[BlexAction(Name = "Apply preset")]
private void OnApplyPreset() { }          // -> ApplyPreset(), labelled "Apply preset"

BLEX003 - Cannot derive computed name

A computed method's name must start with Compute or Get and have something after it.

Rejected
[BlexComputed]
private int DoubleCount() => Count * 2;   // BLEX003
Fix
[BlexComputed]
private int ComputeDoubleCount() => Count * 2;   // -> DoubleCount

[BlexComputed]
private int GetDoubleCount() => Count * 2;       // -> DoubleCount

BLEX004 - Computed method must be parameterless

A computed value backs a property, so there is nowhere to pass arguments. Use an ordinary method for a parameterised projection.

Rejected
[BlexComputed]
private int ComputeTotalFor(int rate) => Count * rate;   // BLEX004
Fix
[BlexComputed]
private int ComputeTotal() => Count * Rate;   // rate lives in [BlexState]

// ... or just a plain method, with no [BlexComputed] and no memoization:
private int TotalFor(int rate) => Count * rate;

BLEX005 - Generated member name collides

Two generated members would share a name, or a generated member would collide with something you already declared or with a BlexStoreBase member. The check covers the memoization backing fields (__XxxValid, __XxxValue) and the effect fields (__XxxPending, __XxxError, __XxxCts, …) too.

Rejected
[BlexStore]
public partial class Store
{
    [BlexState] private int _count;

    [BlexComputed] private int ComputeCount() => 0;   // BLEX005 -- both want "Count"

    [BlexAction] private void OnBatch() { }           // BLEX005 -- BlexStoreBase.Batch
}
Fix
[BlexStore]
public partial class Store
{
    [BlexState] private int _count;

    [BlexComputed] private int ComputeDoubled() => Count * 2;

    [BlexAction] private void OnApplyAll() { }
}

BLEX006 - Unsupported store class shape

The generator writes a flat, top-level partial declaration, so nested and generic stores would produce broken output.

Rejected
public class Outer
{
    [BlexStore]
    public partial class Inner { }        // BLEX006 -- nested
}

[BlexStore]
public partial class Cache<T> { }         // BLEX006 -- generic
Fix
[BlexStore]
public partial class Inner { }            // top level

[BlexStore]
public partial class StringCache { }      // closed over a concrete type

BLEX007 - Effect method must return Task or ValueTask

An effect owns the loading and error lifecycle, so it cannot hand back a result. Non-generic Task or ValueTask only.

Rejected
[BlexEffect]
private async Task<User> OnLoadUser(int id) => await _api.GetAsync(id);   // BLEX007

[BlexEffect]
private void OnLoadUser(int id) { }                                       // BLEX007
Fix
[BlexEffect]
private async Task OnLoadUser(int id)
{
    User = await _api.GetAsync(id);   // results go into [BlexState]
}

BLEX008 - Blex member must be a writable instance member

[BlexState], [BlexComputed], [BlexAction] and [BlexEffect] members are per-instance and must be assignable. static, const and readonly are rejected.

Rejected
[BlexState] private static int _count;      // BLEX008
[BlexState] private readonly int _max = 10; // BLEX008

[BlexAction] private static void OnReset() { }   // BLEX008
Fix
[BlexState] private int _count;

// Constants that are not state need no attribute:
private const int Max = 10;

[BlexAction] private void OnReset() => Count = 0;

BLEX009 - Latest effect cannot cancel without a CancellationToken

Latest marks the superseded run stale so it cannot overwrite newer state - but without a token the superseded body keeps running to completion, because nothing can observe the cancellation.

Rejected
[BlexEffect(Concurrency = BlexEffectConcurrency.Latest)]
private async Task OnSearch(string query)          // BLEX009 (warning)
    => Results = await _api.SearchAsync(query);
Fix
[BlexEffect(Concurrency = BlexEffectConcurrency.Latest)]
private async Task OnSearch(string query, CancellationToken ct)
    => Results = await _api.SearchAsync(query, ct);

BLEX010 - Action must not be 'async void'

An async void method cannot be awaited, so the dispatch pipeline cannot know when it finished or record it correctly.

Rejected
[BlexAction]
private async void OnSave() => await _api.SaveAsync();   // BLEX010
Fix
[BlexAction]
private async Task OnSave() => await _api.SaveAsync();

// ... or, if it has a loading/error lifecycle:
[BlexEffect]
private async Task OnSave() => await _api.SaveAsync();

BLEX011 - Action return value is discarded

An action's wrapper returns what the method returns, but a ref struct (Span<T>, ReadOnlySpan<char>) or a pointer cannot be held across the dispatch: that wrapper returns void and the value is dropped.

Rejected
[BlexAction]
private ReadOnlySpan<char> OnTrim() => Name.AsSpan().Trim();   // BLEX011 (warning) -- the caller never sees it
Fix
[BlexAction]
private string OnTrim() => Name.Trim();

// The wrapper hands the result back:
var trimmed = store.Trim();

BLEX012 - State field name equals generated property name

The property is derived by trimming a leading underscore and capitalizing. A field already in that form would collide with its own property.

Rejected
[BlexState] private int Count;    // BLEX012 -- the property would also be "Count"
Fix
[BlexState] private int _count;   // -> Count
[BlexState] private int count;    // -> Count  (also fine)

BLEX013 - Unsupported parameter modifier

The wrapper captures arguments by value so they can travel as the action payload, which is impossible for a by-ref parameter.

Rejected
[BlexAction]
private void OnTryParse(string text, out int value)   // BLEX013
{
    int.TryParse(text, out value);
}
Fix
[BlexAction]
private void OnParse(string text)
    => Value = int.TryParse(text, out var value) ? value : 0;

BLEX014 - Generic action/effect/computed methods are not supported

The generated member cannot carry type parameters: an action or effect becomes a wrapper method with a typed descriptor, and a computed becomes a property - which cannot be generic at all.

Rejected
[BlexAction]
private void OnSet<T>(T value) { }        // BLEX014

[BlexComputed]
private T ComputeFirst<T>() => default!;  // BLEX014
Fix
[BlexAction]
private void OnSetName(string value) => Name = value;

[BlexAction]
private void OnSetCount(int value) => Count = value;

[BlexComputed]
private string ComputeInitial() => Name[..1];

BLEX015 - Store must be a plain class

Records get value-equality members and a synthesized clone, which fight the mutable reactive-container model a store needs.

Rejected
[BlexStore]
public partial record CounterStore        // BLEX015
{
    [BlexState] private int _count;
}
Fix
[BlexStore]
public partial class CounterStore
{
    [BlexState] private int _count;
}

// Records are ideal for the values *inside* state:
public sealed record Todo(int Id, string Title, bool Done);

BLEX016 - Store cannot have another base class

The generated partial adds : Bit.Blex.BlexStoreBase. A different base class would make the type inherit from two classes.

Rejected
[BlexStore]
public partial class CounterStore : MyBaseViewModel   // BLEX016
{
    [BlexState] private int _count;
}
Fix
// Compose instead of inheriting -- or implement an interface, which is fine.
[BlexStore]
public partial class CounterStore : ICounter
{
    private readonly MyHelper _helper = new();
    [BlexState] private int _count;
}

// Explicitly deriving from BlexStoreBase is also accepted:
[BlexStore]
public partial class CounterStore : BlexStoreBase { }

BLEX017 - Computed method must return a value

A computed backs a memoized property, so there has to be something to memoize; a void method would emit public void Xxx { get; }, which does not compile.

Rejected
[BlexComputed]
private void ComputeSummary() { }         // BLEX017
Fix
[BlexComputed]
private string ComputeSummary() => $"{Count} items";

// Something that only performs work (no value) is an action, not a computed:
[BlexAction]
private void OnRefreshSummary() { }

BLEX018 - Blex member attribute outside a store

A [BlexState], [BlexComputed], [BlexAction] or [BlexEffect] member only means something inside a [BlexStore] class. Outside one it compiles cleanly and generates nothing at all - which reads exactly like a broken generator, so this warning says so instead.

Rejected
// Forgot the [BlexStore] -- Count never appears.
public partial class CounterStore
{
    [BlexState] private int _count;    // BLEX018
}

// Same for a type nested inside a store: the nested type is not itself a store.
[BlexStore]
public partial class OuterStore
{
    [BlexState] private int _count;
    public class Inner { [BlexState] private int _x; }   // BLEX018
}
Fix
[BlexStore]
public partial class CounterStore
{
    [BlexState] private int _count;
}

BLEX019 - Effect debounce cannot be negative

DebounceMilliseconds becomes a Task.Delay in the generated wrapper, which rejects a negative delay at runtime - from inside generated code, where the stack trace explains nothing. Use 0 to disable debouncing.

Rejected
[BlexEffect(DebounceMilliseconds = -1)]      // BLEX019
private async Task OnSearch(string query) { }
Fix
[BlexEffect(DebounceMilliseconds = 300)]
private async Task OnSearch(string query) { }

// 0 (the default) means "no debouncing":
[BlexEffect]
private async Task OnSearch(string query) { }

BLEX020 - Typed action descriptors are not generated

The generator puts a typed descriptor for every action and effect into a nested Actions class (CartStore.Actions.Add), which subscribers, filters and tests match instead of a string. A store that already has a member called Actions - a property, a method, a nested type, or state whose generated property is Actions - keeps compiling exactly as before, but goes without the typed descriptors. Its actions can still be dispatched by name. Rename the member to get them.

Rejected
[BlexStore]
public partial class AuditStore                // BLEX020
{
    [BlexState] private string[] _actions = [];  // generates "Actions"

    [BlexAction] private void OnLog(string entry) => Actions = [.. Actions, entry];
}
Fix
[BlexStore]
public partial class AuditStore
{
    [BlexState] private string[] _entries = [];

    [BlexAction] private void OnLog(string entry) => Entries = [.. Entries, entry];
}

// AuditStore.Actions.Log is now a BlexAction<AuditStore, string>.

BLEX021 - Action name is used more than once

An action's name - its Name, or the wrapper name derived from the method - is what identifies it everywhere outside C#: SubscribeToAction, a descriptor's Matches, DevTools, DispatchAsync and a replayed log. Two actions dispatched under one name cannot be told apart there: dispatching by that name always runs the first, and a subscription to either fires for both. Wrapper names are checked by BLEX005, but a display label is free text, and a direct assignment to a state property X is dispatched as Set X (except in a store that sets EnforceActions, which records none).

Rejected
[BlexAction(Name = "Save it")]
private void OnSaveDraft() { }

[BlexAction(Name = "Save it")]                // BLEX021
private void OnSaveFinal(int version) { }

// With [BlexState] private int _count, a direct assignment is "Set Count" already:
[BlexAction(Name = "Set Count")]              // BLEX021
private void OnChangeCount(int value) => Count = value;
Fix
[BlexAction(Name = "Save draft")]
private void OnSaveDraft() { }

[BlexAction(Name = "Save final")]
private void OnSaveFinal(int version) { }

[BlexAction(Name = "Change count")]
private void OnChangeCount(int value) => Count = value;

BLEX022 - Effect retry and timeout values cannot be negative

RetryCount, RetryDelayMilliseconds and TimeoutMilliseconds are counts and durations. A negative one would only fail at runtime, deep inside the generated wrapper; 0 is how to turn retries, the backoff or the timeout off.

Rejected
[BlexEffect(RetryCount = -1)]                 // BLEX022
private async Task OnLoad(CancellationToken ct) => Orders = await _api.GetOrdersAsync(ct);
Fix
[BlexEffect(RetryCount = 3, RetryDelayMilliseconds = 500)]
private async Task OnLoad(CancellationToken ct) => Orders = await _api.GetOrdersAsync(ct);

BLEX023 - Effect timeout needs a CancellationToken

A timeout stops an attempt by cancelling the token the attempt was handed. An effect without a trailing CancellationToken parameter has nothing to cancel: the timed-out attempt would carry on and change state after its run had already failed. Add the parameter and pass it to the work the effect awaits.

Rejected
[BlexEffect(TimeoutMilliseconds = 5000)]      // BLEX023
private async Task OnLoad() => Orders = await _api.GetOrdersAsync();
Fix
[BlexEffect(TimeoutMilliseconds = 5000)]
private async Task OnLoad(CancellationToken ct) => Orders = await _api.GetOrdersAsync(ct);

BLEX024 - Store version cannot be negative

[BlexStore(Version = n)] gives a persisted store a version of its own. Only a positive one does: 0 means the store follows BlexPersistenceOptions.Version, and a negative one would quietly do the same, so the version you wrote would never be checked.

Rejected
[BlexStore(Name = "layout", Persist = true, Version = -1)]   // BLEX024
public partial class LayoutStore
{
    [BlexState] private string _view = "grid";
}
Fix
[BlexStore(Name = "layout", Persist = true, Version = 1)]
public partial class LayoutStore
{
    [BlexState] private string _view = "grid";
}

BLEX025 - Store version has no effect without Persist

A store's Version versions the state it saves. A store without Persist = true saves nothing, so the version is never written or checked - usually Persist = true was left out.

Rejected
[BlexStore(Name = "layout", Version = 2)]                    // BLEX025
public partial class LayoutStore
{
    [BlexState] private string _view = "grid";
}
Fix
[BlexStore(Name = "layout", Persist = true, Version = 2)]
public partial class LayoutStore
{
    [BlexState] private string _view = "grid";
}

BLEX026 - Store declares a member the generator overrides

The generated half of a store overrides some BlexStoreBase members: Name, SerializeState and DeserializeState always, and others when the store asks for them - Persist and PersistVersion for Persist = true and Version = n, and the members behind EnforceActions, RollbackOnError, transient state, computeds, cancellable effects and actions. A store that writes one of those itself would declare it twice, so the build would fail inside generated code. Say it through the attribute instead, or drop the attribute setting and keep your own override.

Rejected
[BlexStore(Name = "layout", Persist = true, Version = 2)]
public partial class LayoutStore
{
    [BlexState] private string _view = "grid";

    public override int PersistVersion => 3;                 // BLEX026
}
Fix
[BlexStore(Name = "layout", Persist = true, Version = 3)]
public partial class LayoutStore
{
    [BlexState] private string _view = "grid";
}

BLEX027 - Effect throttle cannot be negative

ThrottleMilliseconds is the window after a run starts during which further invocations are dropped. A negative window has no meaning; 0 turns throttling off.

Rejected
[BlexEffect(ThrottleMilliseconds = -1)]                      // BLEX027
private async Task OnRefresh(CancellationToken ct) => Orders = await _api.GetOrdersAsync(ct);
Fix
[BlexEffect(ThrottleMilliseconds = 2000)]
private async Task OnRefresh(CancellationToken ct) => Orders = await _api.GetOrdersAsync(ct);

BLEX028 - Effect cannot both debounce and throttle

A debounce waits for a burst of invocations to end and runs the last one; a throttle runs the first one at once and drops the rest of the burst. Together they contradict each other, so pick the one that matches what the effect is for: debounce a search box, throttle a refresh button.

Rejected
[BlexEffect(DebounceMilliseconds = 300, ThrottleMilliseconds = 300)]   // BLEX028
private async Task OnSearch(string query, CancellationToken ct) => Results = await _api.SearchAsync(query, ct);
Fix
[BlexEffect(DebounceMilliseconds = 300, Concurrency = BlexEffectConcurrency.Latest)]
private async Task OnSearch(string query, CancellationToken ct) => Results = await _api.SearchAsync(query, ct);

BLEX029 - State comparer is not an equality comparer of the state's type

[BlexState(Comparer = nameof(X))] names a field or property of the store holding the IEqualityComparer<T> the generated setter passes on. When the store has no such member, or it holds something else - a comparer of another type, a method - the setter could not compile.

Rejected
private static readonly IEqualityComparer<string> Ordinal = StringComparer.Ordinal;

[BlexState(Comparer = nameof(Ordinal))] private int[] _ids = [];     // BLEX029
Fix
private static readonly IEqualityComparer<int[]> SameIds = BlexComparers.Sequence<int>();

[BlexState(Comparer = nameof(SameIds))] private int[] _ids = [];
An unhandled error has occurred. Reload 🗙