Home > Software engineering >  MVVMToolkit ObservableValidator several "Duplicate" errors
MVVMToolkit ObservableValidator several "Duplicate" errors

Time:07-14

I'm using Microsoft MVVM Toolkit 7.1.2 in a WPF .Net Core 3.1 project. If I use the ObservableObject class it works fine, but, whenever I try to create an ObservableValidator class in my application it gives me several errors in auto generated source files:

Error messages

Even in an test class like really simple:

public class Test : ObservableValidator
{

    private decimal _internalProp;
    public decimal ExternalProp
    {
        get { return _internalProp; }
        set { SetProperty(ref _internalProp, value); }
    }

}

I can't find what is causing this error!

This is the auto generated source files that gives the errors, linked in the error messages:

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#pragma warning disable
namespace Microsoft.Toolkit.Mvvm.ComponentModel.__Internals
{
    [global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Toolkit.Mvvm.SourceGenerators.ObservableValidatorValidateAllPropertiesGenerator", "7.1.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCode]
    [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
    [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
    [global::System.Obsolete("This type is not intended to be used directly by user code")]
    internal static partial class __ObservableValidatorExtensions
    {
        [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
        [global::System.Obsolete("This method is not intended to be called directly by user code")]
        public static global::System.Action<object> CreateAllPropertiesValidator(global::Sid.Models.Test _)
        {
            static void ValidateAllProperties(object obj)
            {
                var instance = (global::Sid.Models.Test)obj;
            }

            return ValidateAllProperties;
        }
    }
}

CodePudding user response:

i think this is known issue atm, see for workaround https://github.com/CommunityToolkit/dotnet/issues/343

  • Related