Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automapper 5.0.2: System.Guid and TryExpression #1495

Closed
alecrt opened this issue Jul 8, 2016 · 2 comments
Closed

Automapper 5.0.2: System.Guid and TryExpression #1495

alecrt opened this issue Jul 8, 2016 · 2 comments
Labels
Milestone

Comments

@alecrt
Copy link

alecrt commented Jul 8, 2016

I get the following error using Automapper 5.0.2 on .NET Core RTM (netcoreapp1.0 only)

TryExpression is not supported as a child expression when accessing a member on type 'System.Guid' >because it is a value type. Construct the tree so the TryExpression is not nested inside of this expression.

I had no problem with previous 4.2.1 version

@alecrt alecrt changed the title Automapper 5.0.2 error Automapper 5.0.2: System.Guid and TryExpression Jul 8, 2016
@jonsagara
Copy link

I get the same error when trying to map an object like this:

public class MyObject
{
    public Guid Id { get; set; }
    public string Name { get; set; }

    public override string ToString() => Name;
}

to a System.Web.Mvc.SelectListItem.

Mapping:

CreateMap<MyObject, SelectListItem>()
            .ForMember(d => d.Text, o => o.MapFrom(s => s.Name))
            .ForMember(d => d.Value, o => o.MapFrom(s => s.Id))
            .ForMember(d => d.Group, o => o.Ignore())
            .ForMember(d => d.Disabled, o => o.Ignore())
            .ForMember(d => d.Selected, o => o.Ignore());

Note that changing the third line of the mapping to o.MapFrom(s => s.Id.ToString())) (i.e., explicitly mapping as a string) fixed the error for me.

So is it correct to say that AutoMapper <= 4.x automatically converted to a string, whereas you must be explicit about your mappings in AutoMapper >= 5.x?

@jbogard jbogard added the Bug label Jul 11, 2016
@jbogard jbogard added this to the 5.1.0 milestone Jul 11, 2016
@lock
Copy link

lock bot commented May 7, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants