Skip to content

MVVM Source Generators: CS1038 Error if [ObservableProperty] attribute is in a #region block #4225

Closed
@JasonWei512

Description

@JasonWei512

Describe the bug

Compilation fails If the Microsoft MVVM Toolkit source generator attribute [ObservableProperty] is in a #region block.

  • Is this bug a regression in the toolkit? If so, what toolkit version did you last see it work:

Steps to Reproduce

  • Can this be reproduced in the Sample App? (Either in a sample as-is or with new XAML pasted in the editor.) If so, please provide custom XAML or steps to reproduce. If not, let us know why it can't be reproduced (e.g. more complex setup, environment, dependencies, etc...)

Sample project:

https://github.com/JasonWei512/MicrosoftMvvmToolkitSourceGeneratorBug

Steps to reproduce the behavior:

When compiling the following code, you will get a "CS1038 #endregion directive expected" error:

// Doesn't compile

#region Properties

[ObservableProperty]
private int counter = 0;

#endregion

If you delete the #region Properties and #endregion lines, the code will compile:

// Compiles

// #region Properties

[ObservableProperty]
private int counter = 0;

// #endregion

Expected behavior

The code should compile.

Screenshots

None.

Environment

NuGet Package(s):

  • Microsoft.Toolkit.Mvvm

Package Version(s):

  • 7.1.0-rc1

Windows 10 Build Number:

  • Fall Creators Update (16299)
  • April 2018 Update (17134)
  • October 2018 Update (17763)
  • May 2019 Update (18362)
  • May 2020 Update (19041)
  • Insider Build (22000.168)

App min and target version:

  • Fall Creators Update (16299)
  • April 2018 Update (17134)
  • October 2018 Update (17763)
  • May 2019 Update (18362)
  • May 2020 Update (19041)
  • Insider Build ({build_number})

Device form factor:

  • Desktop
  • Xbox
  • Surface Hub
  • IoT

Visual Studio version:

  • 2017 (15.{minor_version})
  • 2019 (16.{minor_version})
  • 2022 (17.{minor_version})

Additional context

None.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions