mapperly: Configuration apis using enums are broken in visual studio 16.7+
Describe the bug
Starting with 3.0.0 the generator fails when using PropertyNameMappingStrategy.CaseInsensitive with error message.
Could not resolve enum reflection type of PropertyNameMappingStrategy or Riok.Mapperly.Abstractions.PropertyNameMappingStrategy is not supported.
Cleaning and rebuilding as well as cleaning, closing VS and deleting the .vs folder and reopening did not resolve the issue. Everything seems to build fine using the dotnet cli.
To Reproduce Try to build the sample code below from visual studio 2022.
Expected behavior
The generator should complete without error and Stringfield should be mapped to StringField
Code snippets
using Riok.Mapperly.Abstractions;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
var mapper = new Mapper();
var from = new FromObject
{
Stringfield = "test"
};
var to = mapper.Map(from);
Console.WriteLine(to.StringField);
}
}
public class FromObject
{
public string Stringfield { get; set; }
}
public class ToObject
{
public string StringField { get; set; }
}
[Mapper(PropertyNameMappingStrategy = PropertyNameMappingStrategy.CaseInsensitive)]
public partial class Mapper
{
public partial ToObject Map(FromObject input);
}
}
Environment (please complete the following information):
- Mapperly Version: 3.0.0
- .NET Version: 6.0.411
- Target Framework: net6.0
- IDE: Visual studio 17.6.2
- OS: Windows 10
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 20 (8 by maintainers)
Nice digging 👍
I can recreate the issue, VS doesn’t run for me. Even after restarting
As I’m using macOS I don’t have access to VS and it works with the cli and in Rider. Does it work again if you downgrade to
2.8.0?@latonz Yep, that version works! Thanks!
@pnquest could you verify this issue is resolved with
3.1.0-next.2?I’ve tested it on a old VS Version (17.5), where the Code Snippet still works. After upgrading to 17,7 I also get that error
a bit more digging and I was able to get a stack trace from the generator:
Line numbers seem to have changed a bit, but that looks to be from here. https://github.com/riok/mapperly/blob/main/src/Riok.Mapperly/Configuration/AttributeDataAccessor.cs#L186
So it looks like this is returning null: https://github.com/riok/mapperly/blob/main/src/Riok.Mapperly/Configuration/AttributeDataAccessor.cs#L191
Maybe visual studio is loading libraries into the assembly differently than the cli.