Giter Site home page Giter Site logo

Comments (10)

Timovzl avatar Timovzl commented on May 19, 2024 1

There’s an edge case I hadn’t considered. 😄

Great find. I’ll look into this in the next few days. I expect it will be easy to release a new patch version for this.

For now, may I recommend that you take IEnumerable as a parameter and use IReadOnlyList as the property? Assignment can go like this:

this.Values = values?.ToList() ?? throw new ArgumentNullException(nameof(values));

As a matter of fact, this will get you a true value object: one that is immutable. The defensive copy also helps ensure that we are not holding a list that the caller could modify after-the-fact.

(For single-valued objects, WrapperValueObject<T> can also make life easier.)

from architect.domainmodeling.

Timovzl avatar Timovzl commented on May 19, 2024

Hi @ebarkalov,

Thanks for your bug report!

If you create a blank solution, add the package, and paste in your ValueObject (working around any compiler errors), do you get the same error from the source generator?

Once we can reproduce it in such a minimal way, could you share the ValueObject so that I can investigate the bug?

from architect.domainmodeling.

ebarkalov avatar ebarkalov commented on May 19, 2024

Hi @Timovzl

Thank you so much for your prompt reply!

Indeed, it does work on the blank solution!

Tried to clean my VS solution - no luck. Will continue investigation - will let you know if I find the cause.

from architect.domainmodeling.

Timovzl avatar Timovzl commented on May 19, 2024

Pity! I was hoping for an easy repro.

In that case, it will probably be quicker if you debug from within your own solution. You can do this as follows:

  • Download this package's source.
  • In your own project, remove the package reference to DomainModeling.
  • Add both the DomainModeling and the DomainModeling.Generator projects to your solution.
  • In your own project, add a project reference to DomainModeling.
  • In your own project, add an analyzer project reference to DomainModeling.Generator. (You can just modify a regular project reference to match the linked example.)
  • Uncomment this line in your local copy.
  • Rebuild.

When you build with the Debugger.Launch() line enabled, VS will prompt you for which window to debug in. Hopefully this will reveal the exact line number where the null ref occurs. If not, you can even add a breakpoint to ValueObjectGenerator.TransformSyntaxNode to identify the problematic line manually.

Please share any findings, and let's see if we can nip this in the bud.

from architect.domainmodeling.

ebarkalov avatar ebarkalov commented on May 19, 2024

Hi @Timovzl

I actually found the cause! It seems that ValueObjectGenerator does not like arrays. The following value object makes generator to fail.

[SourceGenerated]
public sealed partial class Color : ValueObject
{
  public Color(ushort[] rgb)
  {
    RGB = rgb;
  }

  public ushort[] RGB { get; }
}

from architect.domainmodeling.

ebarkalov avatar ebarkalov commented on May 19, 2024

image

tuple.Type.ContainingNamespace is null.

from architect.domainmodeling.

ebarkalov avatar ebarkalov commented on May 19, 2024

Thank you so much! Completely agree. Will do as you suggested!

from architect.domainmodeling.

Timovzl avatar Timovzl commented on May 19, 2024

Edit: The issue seems to be resolved when I change the problematic line to the following:

dataMemberHashCode = (tuple.Type.ContainingNamespace?.ToString() ?? "").GetStableHashCode64(dataMemberHashCode);

from architect.domainmodeling.

Timovzl avatar Timovzl commented on May 19, 2024

@ebarkalov A 2.0.1 prerelease package has been published.

Would you test the fix, please? Perhaps you could confirm that it works well with both your new and your old code - especially the arrays, of course.

from architect.domainmodeling.

ebarkalov avatar ebarkalov commented on May 19, 2024

Hi @Timovzl

Thank you for the quick fix. I do confirm that arrays are working now in ValueObjects. Had to restart VS after upgrading package to pre-release for error to disappear.

As you mentioned in your comment before, it's better not to use arrays in value objects to support immutability principle. Switched to IReadOnlyList.

Thank you for all the support and such a great library that increases productivity when coding domain objects.

from architect.domainmodeling.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.