Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

StringAttributeMetadata cannot be serialized

Posted on by 240

Hello All,

I try to create the "Auto Number " field from C# Console while Execute the "Create Attribute Request ", I am getting the Following Issue .


 Type 'AutoNumber.StringAttributeMetadata' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute

Class Program

{

       static OrganizationServiceProxy _organizationProxy = null;
 
       static void Main(string[] args)
       {
           CreateCRMProxy();
           CreateAutoNumberAttributeProxy(_organizationProxy, "gitta_employee""gitta_empid""gitta_Empid""EMP-{SEQNUM:4}""Employee AUTO ID""Employee AUTO Number Description");
           //if (ConnectToCRM_Method3())
           //{
           //    Console.WriteLine("CRM Connection Established..");
           //    CreateAutoNumberAttribute(_orgService, "gitta_employee", "gitta_empid", "gitta_empid", "EMP-{SEQNUM:4}", "Employee AUTO ID", "Employee AUTO Number Description");
           //}
           //else
           //{
           //    Console.WriteLine("CRM Connection Established Failed ..");
           //}
           Console.ReadLine();
       }
}

public static void CreateAutoNumberAttributeProxy(OrganizationServiceProxy _organizationProxy, string EntityName, String LogicalName, string SchemaName, string AutonumberFormat, string DisplayName, string DisplayDescription)
       {
 
           CreateAttributeRequest employeeIdAutoNumber = new CreateAttributeRequest
           {
               EntityName = EntityName,
               Attribute = new StringAttributeMetadata
               {
                   AutoNumberFormat = "EMP-{SEQNUM:5}",
                   LogicalName = LogicalName,
                   SchemaName = SchemaName,
                   RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
                   DisplayName = new Label(DisplayName, 1033),
                   Description = new Label(DisplayDescription, 1033),
 
 
               }
           };
 
           _organizationProxy.Execute(employeeIdAutoNumber);
}


public static void CreateCRMProxy()
        {
            string orgServiceUrl = ConfigurationManager.AppSettings["Url"];
 
 
            string userName = ConfigurationManager.AppSettings["username"];
 
 
            string password = ConfigurationManager.AppSettings["password"];
 
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
 
            ClientCredentials clientCredentials = new ClientCredentials();
 
            clientCredentials.UserName.UserName = userName;
            clientCredentials.UserName.Password = password;
 
            // Set security protocol to TLS 1.2 for version 9.0 of Customer Engagement Platform
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
 
            _organizationProxy= new OrganizationServiceProxy(new Uri("">gitta9.crm.dynamics.com/.../Organization.svc"),
            null, clientCredentials, null);
 
 
        }

 Type 'AutoNumber.StringAttributeMetadata' cannot be serialized. Consider marking it with the DataContractAttr
ibute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute

I am unable to found what is Root Cause.

*This post is locked for comments

  • Suggested answer
    RE: StringAttributeMetadata cannot be serialized

    Hi Sairam

    Not sure what the issue is with your code but you could avoid coding by using one of these apps for configuring autonumbers

    1. This XrmToolbox plugin http://anm.xrmtoolbox.com

    2. My app detailed in this article josephmcmac.wordpress.com/.../configuring-autonumbers-in-dynamics-365-with-josephm-dynamics-365-dev-app

    Hope this helps

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans