Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/mvvm/generators/errors/MVVMTK0035.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dev_langs:

# MVVM Toolkit error MVVMTK0035

All attributes targeting the generated property for a field annotated with [ObservableProperty] must correctly be resolved to valid types. This error is shown when a given `property:` attribute over a field with `[ObservableProperty]` is not correctly resolved to a type, which helps identifying issues at compile time as soon as possible. A common example where this can happen is if a `using` directive for the attribute is missing.
All attributes targeting the generated property for a field annotated with `[ObservableProperty]` must correctly be resolved to valid types. This error is shown when a given `property:` attribute over a field with `[ObservableProperty]` is not correctly resolved to a type, which helps identifying issues at compile time as soon as possible. A common example where this can happen is if a `using` directive for the attribute is missing.

The following sample generates MVVMTK0035:

Expand Down
61 changes: 61 additions & 0 deletions docs/mvvm/generators/errors/MVVMTK0036.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: MVVM Toolkit error MVVMTK0036
author: Sergio0694
description: MVVM Toolkit error MVVMTK0036
keywords: community toolkit, dotnet, csharp, mvvm, net core, net standard, source generators
dev_langs:
- csharp
---

# MVVM Toolkit error MVVMTK0036

All attributes targeting the generated field or property for a method annotated with `[RelayCommand]` must correctly be resolved to valid types. This error is shown when a given `field:` or `property:` attribute over a method with `[RelayCommand]` is not correctly resolved to a type, which helps identifying issues at compile time as soon as possible. A common example where this can happen is if a `using` directive for the attribute is missing.

The following sample generates MVVMTK0036:

```csharp
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace MyApp;

public partial class SampleViewModel : ObservableObject
{
[ObservableProperty]
private int counter;

[RelayCommand]
[property: JsonIgnore]
private void IncrementCounter()
{
Counter++;
}
}
```

You can see that `JsonIgnore` has no `using` directive here, and as such is not resolved correctly. You can fix this by updating the code as follows:

```csharp
using System.Text.Json.Serialization;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace MyApp;

public partial class SampleViewModel : ObservableObject
{
[ObservableProperty]
private int counter;

[RelayCommand]
[property: JsonIgnore]
private void IncrementCounter()
{
Counter++;
}
}
```

## Additional resources

- You can find more examples in the [unit tests](https://github.com/CommunityToolkit/dotnet/tree/main/tests/CommunityToolkit.Mvvm.SourceGenerators.UnitTests).
2 changes: 2 additions & 0 deletions docs/mvvm/generators/errors/TOC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ items:
href: MVVMTK0034.md
- name: MVVMTK0035
href: MVVMTK0035.md
- name: MVVMTK0036
href: MVVMTK0036.md