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

  • SEARCH
  • Home
  • 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 9234795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:52:23+00:00 2026-06-18T06:52:23+00:00

I have two objects(classes) with exact properties. say : class class1 { public string

  • 0

I have two objects(classes) with exact properties. say :

class class1
{
  public string prop1{get;set;}
  public string prop2{get;set;}
}

class class2
{
    public string prop1{get;set;}
    public string prop2{get;set;}
}

I want to map these classes using reflection, I have already used AutoMapper and it doesn’t work for my situation, as I have object inside object….

When using reflection I need to pass the property name and i don’t want to do this one by one is there other way:

PropertyInfo propinfo = listToReturn.GetType().GetProperty(nameofproperty);

EDIT::

Here is what i have tried with automapper:

 internal static DTO_objectclass  ConvertFOS(objectclass q)
        {
            DTO_objectclass  resultsToReturn = new DTO_objectclass();

            AutoMapper.Mapper.CreateMap<objectclass , DTO_objectclass  >();

            resultsToReturn = AutoMapper.Mapper.Map<objectclass , DTO_objectclass>(q);

            return resultsToReturn;
        }

this works until it comes to a property where I have something like this in objectclass :

property class3 parentClass{get; set;}

and in DTO_objectclass i got :

 property guid parentClass{get; set;}

where i get exception of failed to convert..

Trying to map System.Guid to parentclient.\nUsing mapping configuration for DTO_objectclass   to objectclass \nDestination property: ParentClass\nException of type 'AutoMapper.AutoMapperMappingException' was thrown.
  • 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-18T06:52:25+00:00Added an answer on June 18, 2026 at 6:52 am

    The exception explains the issue. AutoMapper can’t convert a GUID to a ParentClass. AutoMapper will assume that two properties/fields with the same name will be of the same type in the absence of better information.

    To overcome this, you’ll need to write a conversion method. If that method were called ConvertGuidToParentClassInstance, for example, you could then write a mapping like this:

    Mapper.CreateMap<DTO_objectcass, objectclass>()
      .ForMember(dest => dest.parentClass)
        .MapFrom(src => ConvertGuidToParentClassInstance(src.parentClass));
    

    With such a mapping in place, AutoMapper can handle this case.

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

Sidebar

Related Questions

Suppose I have these two objects: public class Object1 { string prop1; string prop2;
I have a class that contains objects of two other classes. I need one
I have two objects and I want to merge them: public class Foo {
I have two objects that are derived from same the base class. Lets say
I have two different types of objects, say of classes Object1 and Object2. I
We have two classes that have the exact same public accessors (and many of
I have two classes, A and B like this : class A { public:
I have two similar classes : Person , PersonDto public class Person { public
Lets say I have a class Public Class Person Public Name As String Public
In my NSArray, I have two types of objects, let's say objects of class

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.