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 · 2 comments

Comments

Projects
None yet
3 participants
@peef

peef commented Apr 3, 2012

See also the stackowerflow question
http://stackoverflow.com/questions/9721466/automapper-cannot-convert-enum-to-nullable-int

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

This comment has been minimized.

Show comment
Hide comment
@dvorobiov

dvorobiov Apr 8, 2012

Contributor

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

Contributor

dvorobiov commented Apr 8, 2012

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

jbogard added a commit to jbogard/AutoMapper that referenced this issue Apr 20, 2012

@jbogard

This comment has been minimized.

Show comment
Hide comment
@jbogard

jbogard Apr 20, 2012

Member

Fixed!

Member

jbogard commented Apr 20, 2012

Fixed!

@jbogard jbogard closed this Apr 20, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment