CS0450 invalid type constraint in generated code with generic view base class · Issue #185 · reactiveui/ReactiveUI.Binding.SourceGenerators · GitHub
Skip to content

CS0450 invalid type constraint in generated code with generic view base class #185

Open

Description

@StuYarrow

Prerequisites

  • I have searched this repository's open and closed issues for duplicates.
  • I am using the latest stable release.

What happens

My project has ViewModel and View base classes that provide, amongst other things, some common interactions to all the derived views and view models.

I recently updated from ReactiveUI.Blazor.Reactive 24.2.0 to 26.2.1 and after fixing various other issues related to breaking changes, I am left with CS0450 compiler errors in generated code.

I think the key to the problem is the definition of my generic view base class:

class View<TViewModel> : ReactiveComponentBase<TViewModel> where TViewModel : ViewModel

It looks like the error is caused by the source generator adding a class type constraint on top of the ViewModel constraint when generating interaction bindings between the view and view model base classes.

What you expected instead

Generated code should compile.

Minimal reproduction

StuYarrow/MWE-ReactiveUI-source-generator-CS0450

Steps to reproduce

  1. Compile the MWE project.

Exception and stack trace

On compiling the MWE project, the compiler reports:
`'ViewModel': cannot specify both a constraint class and the 'class' or 'struct' constraint`

Package and version

ReactiveUI.Blazor.Reactive 26.0.1

UI framework

Blazor

Operating system

Windows

Target framework

net10.0

Device and OS version

No response

IDE

No response

Did this work in an earlier version?

Worked in ReactiveUI.Blazor.Reactive 24.2.0

Workaround

No response

Additional information

No response

Activity

  1. added theissue type on Oct 21, 2026
  2. StuYarrow commented on Oct 21, 2026

    @StuYarrow
    Author

    Ah, so it seems the fix is to use BindCommandUnsafe() and WhenAnyValueUnsafe(). If the MWE had generated error RXUIBIND016 then I think I would have figured it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions