CommunityToolkit 8.2.2 with Wpf .Net framework 4.8.1 gets error The name '' does not exist in the current context

Dung Huynh 141 Reputation points
2024-07-29T08:08:27.2433333+00:00

Hi,

I am working with WPF .Net framework 4.8.1 using CommunityToolkit 8.2.2. I've already set the LangVersion to 8.0, and migrated the package.config.

In my MainWindowViewModel, there is a ObservableProperty string _myName, the Source Generator already generated the public string MyName. However, the build keeps building failed with the error The name '' does not exist in the current context.

Here is my ViewModel

User's image

Here is the Code generator

User's image

Here is my MainWindows.xaml

User's image

Here is the error:

User's image

Here is the Solution Explorer

User's image

Could you tell me what I am missing here to make the ObservableProperty works?

Thank you,

Dung Huynh.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,773 questions
0 comments No comments
{count} votes

Accepted answer
  1. Hui Liu-MSFT 48,531 Reputation points Microsoft Vendor
    2024-07-29T13:26:53.6966667+00:00

    Hi,@Dung Huynh. I found a workaround.
    You could try creating a .NET Standard 2.0 library, flip on C# 10, and moving your ViewModel there to see if it works.

    For more details, you can refer to the chat here.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Hui Liu-MSFT 48,531 Reputation points Microsoft Vendor
    2024-07-29T13:00:48.6866667+00:00

    Hi,@Dung Huynh. Welcome to Microsoft Q&A. I reproduce your problem in Microsoft Visual Studio Community 2022 Version 17.10.5 and got the following errors and warnings. I've already set the LangVersion to 8.0.

    enter image description here

    But it has been tested to work in .net 8.

    When i migrated the package.config to PackageReference ,the warning disapper. But still can't run.

    According to the documentation Introduction to the MVVM Toolkit , it does not support .NET Framework.

    You could migrate your application to .NET 6 or 8 Upgrade a WPF App to .NET 6 with the .NET Upgrade Assistant


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.