riok / mapperly

A .NET source generator for generating object mappings. No runtime reflection.
https://mapperly.riok.app
Apache License 2.0
2.86k stars 146 forks source link

Rider: Partial method must have an implementation part because it has accessibility modifiers. #1574

Closed Versure closed 2 days ago

Versure commented 3 days ago

Describe the bug We've recently upgraded Mapperly from version 4.0.0 to 4.1.0 and now we run into the following error in Rider: Partial method 'UpdateDataSheetCommand ToCommand(this UpdateDataSheetRequestApiModel, int)' must have an implementation part because it has accessibility modifiers

This error does not occur when reverting back to version 4.0.0.

Declaration code

public sealed record UpdateDataSheetRequestApiModel
{
    public required ICollection<UpdateDataSheetTranslationApiModel> Translations { get; set; }

    public sealed record UpdateDataSheetTranslationApiModel
    {
        public required int Id { get; init; }

        public int? DocumentFileId { get; init; }
    }
}
public sealed record UpdateDataSheetCommand
    : ICommand<OneOf<Success, NotFound<DataSheet>, CustomError<DataSheetTranslationNotFound>>>
{
    public int DataSheetId { get; set; }

    public required ICollection<UpdateDataSheetTranslationModel> Translations { get; init; }

    public sealed record UpdateDataSheetTranslationModel
    {
        public required int Id { get; init; }

        public int? DocumentFileId { get; init; }
    }
}
[Mapper]
internal static partial class UpdateDataSheetRequestApiModelExtensions
{
    internal static partial UpdateDataSheetCommand ToCommand(this UpdateDataSheetRequestApiModel model, int dataSheetId);
}

Environment (please complete the following information):

Additional context Rider does seem to build the project without issues and Visual Studio does not seem to be affected by this issue.

TadijaBagaric commented 3 days ago

Same thing with us just that it is not related to Rider. It is happening using dotnet CLI on dev machines and inside pipelines using linux containers with dotnet CLI as well.

Issue started popping up with upgrade 4.0.0 -> 4.1.0. Looks like an unexpected breaking change or a bug.

Target Framework .NET 8.0 C# Language Version: 12.0 OS: Win 11 WSL (22.04.2 LTS (Jammy Jellyfish)) dotnet cli: 8.0.103

latonz commented 3 days ago

Could you create a minimal reproducible on GitHub, that would be very helpful, thank you!

Versure commented 3 days ago

Could you create a minimal reproducible on GitHub, that would be very helpful, thank you!

You could use the example from your docs: https://mapperly.riok.app/docs/configuration/additional-mapping-parameters/

image

I've created a minimal reproducible for you just in case: https://github.com/Versure/Mapperly

latonz commented 3 days ago

Unfortunately I cannot reproduce this... The repro you provided is actually not a valid c# project due to CS5001: Program does not contain a static 'Main' method suitable for an entry point. If I just add a console writeline to the program cs file, it works perfectly fine. Does it work for you if you add an executable line (fix CS5001)?

Versure commented 2 days ago

Unfortunately I cannot reproduce this... The repro you provided is actually not a valid c# project due to CS5001: Program does not contain a static 'Main' method suitable for an entry point. If I just add a console writeline to the program cs file, it works perfectly fine. Does it work for you if you add an executable line (fix CS5001)?

No it does not. I've pushed some changes to make it run. The IDE gives you an error (shown in the screenshot above) but the app builds en runs without any issues.

I'll let some colleagues double check if they have the same issue and let you know the results.

latonz commented 2 days ago

I tried the following and it works just fine πŸ€”

Maybe it is related to the sdk build or OS. I'll run more tests later today. Let me know the results after checking with your colleagues 😊

Versure commented 2 days ago

I tried the following and it works just fine πŸ€”

  • Checked out the projoect you provided
  • run dotnet build with .NET 9.0 => works as expected
  • clean and run dotnet build with .NET 8.0 => works as expected
  • clean again and build in docker using docker run --rm -v $(PWD):/data -w /data mcr.microsoft.com/dotnet/sdk:9.0 dotnet build => works as expected
  • clean again and build in docker using docker run --rm -v $(PWD):/data -w /data mcr.microsoft.com/dotnet/sdk:8.0 dotnet build => works as expected

Maybe it is related to the sdk build or OS. I'll run more tests later today. Let me know the results after checking with your colleagues 😊

Ok, I think the mystery has been solved. 2 of my colleagues didn't have the same issue, but were running on a newer version of Rider. So I've updated my Rider version to 2024.2.7 and this seems to solve my issue.

Sorry for wasting your time @latonz and thank you for your help and quick feedback. But kinda strange that this issue didn't occur with version 4.0.0.

latonz commented 2 days ago

πŸ‘