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

Cannot convert enum to nullable int #191

Closed
peef opened this issue Apr 3, 2012 · 3 comments
Closed

Cannot convert enum to nullable int #191

peef opened this issue Apr 3, 2012 · 3 comments

Comments

@peef
Copy link

peef commented Apr 3, 2012

public enum DummyTypes : int
{
    Foo = 1,
    Bar = 2
}

public class DummySource
{
    public DummyTypes Dummy { get; set; }
}

public class DummyDestination
{
    public int? Dummy { get; set; }
}

[TestMethod]
public void MapDummy()
{
    Mapper.CreateMap<DummySource, DummyDestination>();
    Mapper.AssertConfigurationIsValid();
    DummySource src = new DummySource()
    {
        Dummy = DummyTypes.Bar
    };
    Mapper.Map<DummySource, DummyDestination>(src);
}

Exception:
Exception of type 'AutoMapper.AutoMapperMappingException' was thrown. ---> System.InvalidCastException: Invalid cast from 'DummyTypes' to 'System.Nullable`1[[System.Int32, ...

@dvorobiov
Copy link
Contributor

I've added code to fix this issue to requests.

jbogard pushed a commit to jbogard/AutoMapper that referenced this issue Apr 20, 2012
@jbogard
Copy link
Member

jbogard commented Apr 20, 2012

Fixed!

@jbogard jbogard closed this as completed Apr 20, 2012
@lock
Copy link

lock bot commented May 5, 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 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants