Messagepack-csharp: MessagePackAnalyzer does not consider types marked by [DataContract] as valid

Created on 8 Mar 2020  路  7Comments  路  Source: neuecc/MessagePack-CSharp

Bug description

The documentaion states:
_You can use [DataContract] instead of [MessagePackObject]. If type is marked DataContract, you can use [DataMember] instead of [Key] and [IgnoreDataMember] instead of [IgnoreMember]._

But the analyzer considers types with [DataContract] not compliant. In fact they work well with MessagePack (1.9 and 2.1 as well).

Repro steps

    [DataContract]
    public struct Party {

        [DataMember(Order = 0)]
        public int Type;
        [DataMember(Order = 1)]
        public string Number;
    }

    [MessagePackObject]
    public class CallItemPoco
    {
        [Key(0)]
        public string Id { get; set; }
        [Key(1)]
        public Party Remote { get; set; }  // THIS IS MARKED WITH ERROR
   }

Expected behavior

No error should be generated.

Actual behavior

MsgPack003 Use MessagePackObjectAttribute

  • Version used: 2.1.90
  • Runtime: VS2019 16.4.5

Additional context

An exception was caught by VS, difficult to say, whether it is related to this bug:

System.ArgumentNullException : Value cannot be null.
Parameter name: document
at async Microsoft.CodeAnalysis.Editing.DocumentEditor.CreateAsync()
at async MessagePackAnalyzer.MessagePackCodeFixProvider.AddKeyAttributeAsync()
at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync()
at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync()
at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync()
at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync()
at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass11_0.b__0()
at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsyncT

bug no-issue-activity

All 7 comments

DataContract is used in various way.
Considering that it is not used only for MessagePack, it is excluded from detection.

Are you saying this is by design, @neuecc? I'm hoping you won't object to (my) fixing this.

I don't see why we would want to produce an error in this case since we do in fact support DataContract attributes. And the analyzer is clearly throwing an exception, making a nasty looking infobar in VS. So we clearly have something to fix here.

error is bug, should fix.
What I'm saying is whether to target DataContract to the Analyzer.
Current design is only work for MessagePackObjectAttribute.
https://github.com/neuecc/MessagePack-CSharp/blob/master/src/MessagePackAnalyzer/MessagePackAnalyzer.cs#L89-L91

Since you have this (very needed feature!) of respecting DataContract attribute, the analyzer should tolerate it as well. For me this means that I:

  • want to check my POCO objects - so I install analyzer
  • do the build, check result, mentally filter-out false positives
  • uninstall analyzer, since it would bother me during days when we do not touch pocos with errors and break possible builds
  • I guess that this is not solvable by some #pragma declarations, sine afaik work for warnings only ?

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days.

This is probably low-priority issue... no idea how much work it requires.

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Was this page helpful?
0 / 5 - 0 ratings