dotvvm icon indicating copy to clipboard operation
dotvvm copied to clipboard

Fail fast on issues with viewmodel serialization

Open cafour opened this issue 3 years ago • 1 comments

Currently, DotVVM reports serialization issues only if an instance of a type that cannot be serialized is sent to the client. This means that a lot of issues are discovered very late.

A sample:

public class Position
{
    public int X { get; set; }
    public int Y { get; set; }

    public Position(int x, int y)
    {
        X = x;
        Y = y;
    }
}

public class ViewModel
{
    public List<Position> Positions { get; set; }
}

DotVVM currently complains about a missing parameterless constructor in Position only when the Positions list is non-empty. It would be beneficial to learn about serialization issues as soon as possible, during any request to the page at the latest.

cafour avatar Aug 04 '22 17:08 cafour

  1. The current version should support putting data into the constructor.

  2. That's not easy to do, if we don't want to report false positives. We currently have don't have a way to analyze the entire object tree, and adding such analyzer would most likely report many errors which don't occur in practice. Specifically the missing constructor is only a problem if you need to deserialize the object.

  3. There is the analyzer which is designed to do something like this, but it won't fail the page entirely

exyi avatar Aug 04 '22 18:08 exyi