Mapping string[] to string[] throws CS8081
See original GitHub issueDescribe the bug Mapping string array to a string array throws a CS8081: “Expression does not have a name”.
The picture describes the error:
To Reproduce Steps to reproduce the behavior:
- Use the code snippets and check the generated code
Expected behavior No CS8081 exception in the generated code. Also the generated code is different with no generated code header comment which is strange behavior?
Code snippets A.cs:
namespace Namespace;
using System;
public class A
{
public string[] Items { get; set; }
public A()
{
Items = Array.Empty<string>();
}
public A(string[] array)
{
Items = array;
}
}
B.cs:
// //------------------------------------------------------------------------------
// // <auto-generated>
// // This code was generated by a tool.
// //
// // Changes to this file may cause incorrect behavior and will be lost if
// // the code is regenerated.
// // </auto-generated>
// //------------------------------------------------------------------------------
namespace AnotherNamespace
{
using System;
public class A
{
public string[] Items { get; set; }
public A()
{
Items = Array.Empty<string>();
}
public A(string[] array)
{
Items = array;
}
}
}
Mapper.cs:
namespace Namespace;
using Riok.Mapperly.Abstractions;
[Mapper]
public partial class Mapper
{
public partial A AtoA(AnotherNamespace.A abcde);
}
Environment:
- Mapperly Version: 2.8.0
- .NET Version: .NET SDK 7.0.203
- Target Framework: net6.0
- IDE: Visual Studio v17.5.5
- OS: Windows 11 22H2
Issue Analytics
- State:
- Created 4 months ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Mapping with automapper system.strin to string exception
I'm trying to create mapping, everything works fine but app throws exception. {"LINQ to Entities does not recognize the method 'System.
Read more >Case Statements for string to string mapping [duplicate]
If you have multiple different mappings for different objects across multiple different projects, that is fine.
Read more >Converting Map to Map in Java
Let's test it with our MAP1: Map<String, String> result = checkAndTransform(MAP1); assertEquals(EXPECTED_MAP1, result); Moreover, once the input map holds some ...
Read more >Mapping String Data
The purpose of the NONE map on the Server canvas is to turn off mapping of string data in any stage in which...
Read more >Transforming data with map() – Hacking with Swift+
This will accept a single Any parameter and return the string ... Swift's own map() is able to deal with a throwing transformation....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Minimal example
Simplified issue
It also looks like a lot of tests are broken, Dictionary and Enumerable tests both generate invalid code.
@latonz No, the mapper I used was the default one. Same as in the snippet. I think the problem is when having both enabled and disabled nullable references. As @TimothyMakkison also acknowledge. Both properties have setters (see snippet). Nullable in csprojects is enabled for all classes. But I think that the header for generated code makes disables nullable.
After a bit of research, I came upon this doc that explains why it disables nullable for generate code: https://github.com/dotnet/roslyn/blob/main/docs/features/nullable-reference-types.md#generated-code