Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:42:39+00:00 2026-06-11T18:42:39+00:00

I am trying to use AutoMapper to map a very simple Enum. The reason

  • 0

I am trying to use AutoMapper to map a very simple Enum.

The reason this mapping exists is PriorityType is in my dotnet 4.0 domain model assembly that runs on the server, but I need the Dto in dotnet 3.5 in my DataContract assembly.

public enum PriorityType// : byte
{
    Low = 0,
    Medium,
    High,
    Urgent
}

[Serializable]
public enum PriorityTypeDto// : byte
{
    Low = 0,
    Medium,
    High,
    Urgent
}

Mapper.CreateMap<PriorityType, PriorityTypeDto>();

If I uncomment out the byte parent type (I really don’t need more than 255 possible entries!), I get a TypeInitializationException. Haven’t been able to work around it using ConvertUsing either.

Why the hiccup around byte?

Edit 1

Debugging AutoMapper further, it essentially retrieves all the writable properties in the destination and checks for a corresponding property with the same name.

In the case of Enums there is a field named value__ that is visible with reflection that AutoMapper attempts to map.

The error is different with v2.2 (was on 2.1) but still it throws an exception when mapping enums of bytes but does just fine when mapping enums of int32.

The error occurs here,

public delegate object LateBoundFieldGet(object target);

Expression<LateBoundFieldGet> lambda =
    Expression.Lambda<LateBoundFieldGet>(
        Expression.Convert(member, typeof(object)),
        instanceParameter);

return lambda.Compile();

The lambda.Compile() throws an InvalidProgramException.

Still trying to understand why.

Edit 2

Issue reported on AutoMapper GitHub as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:42:40+00:00Added an answer on June 11, 2026 at 6:42 pm

    You don’t need the CreateMap call – AutoMapper automatically handles enum types without any configuration. Just remove CreateMap and you’re set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Automapper to map to objects, the issue is one of
I am trying to use automapper to map a list of objects in a
I'm trying to create a custom mapping with AutoMapper, but I can't use 3.0
I am trying to use automapper to create a single map for a parent
I am trying to use AutoMapper to map some DTO (data contract) objects received
I am need paint my image. I'm trying use JQuery in here this link:
I've been trying to use AutoMapper to save some time going from my DTOs
I'm developing an ASP.NET MVC application with NHibernate and I'm trying to use Automapper
I am trying to use AutoMapper with web application running on IIS 7. The
I am trying use MySql and Entity Framework, using Connector/Net 6.1 with this as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.