Immutype icon indicating copy to clipboard operation
Immutype copied to clipboard

Generated extension methods in a library are not found in a consuming library.

Open tstockwell opened this issue 2 years ago • 1 comments

Hi,

I have a library, library1, that uses Immutype to generate extension methods. I have another library, library2, that imports library1 using a project reference. Library2 cannot 'see' the generated extension methods, I get compiler errors that no suitable extension method can be found.

Can you give me any advice for fixing this?


Here are the details...

Library1 contains this class for which Immuttype generates extensions methods...

  [Immutype.Target]
   public record Person(
           string Name,
           bool HasPassport = true,
           int Age = 0,
           ImmutableArray<Person> Friends = default);

The generated extension methods can be reused within Library1 with no problems.

Library2 contains Library 1 as a project reference....

  <ItemGroup>
    <ProjectReference Include="..\Library1\Library1.csproj" />
  </ItemGroup>

But, this code in Library2 fails, the call to the 'ShouldBe' method is not found.

            var john = new Person("John", false, 15)
                .AddFriends(
                    new Person("David").WithAge(16),
                    new Person("James").WithAge(17)
                        .WithFriends(new Person("Tyler").WithAge(16)));

            john.Friends.Length.ShouldBe(2);

tstockwell avatar Feb 27 '22 17:02 tstockwell