Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

MS CRM 2013 on-premise - c# code - Error "An unexpected error occurred" on retrieve of metadata.

(0) ShareShare
ReportReport
Posted on by 1,077

Hi All,

I need an urgent help.

I am working on MS CRM 2013 on-Premise version. I am writing c#code to retrieve metadata of entity and getting error on below color(yellow) line. Please check code and error detail after code -

//Creating connection

Uri sOrganizationuri = new Uri("">xxxxx.com/.../Organization.svc");

ClientCredentials sCredentials = new ClientCredentials();

sCredentials.Windows.ClientCredential = new NetworkCredential("username", "password", "domain");

OrganizationServiceProxy sService = new OrganizationServiceProxy(sOrganizationuri, null, sCredentials, null);

// getting metadata code

RetrieveEntityRequest retrieveEntityRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.All,

LogicalName = "account",

RetrieveAsIfPublished = true
};

RetrieveEntityResponse retrieveAccountEntityResponse = (RetrieveEntityResponse)sService.Execute(retrieveEntityRequest);

EntityMetadata EntityMetaData = retrieveAccountEntityResponse.EntityMetadata;

foreach (object attribute in EntityMetaData.Attributes)
{

AttributeMetadata a = (AttributeMetadata)attribute;
string attributeName = a.LogicalName;

}

}

Detail Error 

The Web Service plug-in failed in OrganizationId: be747ce0-89cd-e911-a301-00155d016b08; SdkMessageProcessingStepId: 38b005c5-b7f8-4c22-97ed-a7abc9c22b6c; EntityName: none; Stage: 30; MessageName: RetrieveEntity; AssemblyName: Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35; ClassName: Microsoft.Crm.Extensibility.InternalOperationPlugin; Exception: Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)
at Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider serviceProvider)
at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
Inner Exception: System.MissingMethodException: Method not found: 'Void Microsoft.Xrm.Sdk.Metadata.EntityMetadata.set_IsStateModelAware(System.Nullable`1<Boolean>)'.
at Microsoft.Crm.Sdk.Metadata.EntityMetadataFactory.FillEntityMetadata(EntityMetadata entityMetadata, MetadataBusinessEntity entity, MetadataLoader loader)
at Microsoft.Crm.Sdk.Metadata.EntityMetadataFactory.CreateEntityMetadata(Guid entityId, String entityName, EntityFilters entityItems, MetadataLoader loader)
at Microsoft.Crm.Sdk.Metadata.MetadataReaderFromDatabase.RetrieveEntity(EntityFilters entityItems, String logicalName, Guid metadataId, Boolean retrieveAsIfPublished, ExecutionContext context)
at Microsoft.Crm.Sdk.Metadata.MetadataServiceProvider.RetrieveEntity(EntityFilters entityItems, String logicalName, Guid metadataId, Boolean retrieveAsIfPublished, ExecutionContext context)
.

*This post is locked for comments

  • Suresh Sorde Profile Picture
    Suresh Sorde 1,077 on at
    RE: MS CRM 2013 on-premise - c# code - Error "An unexpected error occurred" on retrieve of metadata.

    Can any one please help me to resolve this issue?

  • Suresh Sorde Profile Picture
    Suresh Sorde 1,077 on at
    RE: MS CRM 2013 on-premise - c# code - Error "An unexpected error occurred" on retrieve of metadata.

    Thanks Alex,

    Its not credential related error. I already check this code with MS CRM 2016 and its working. I am getting error on MS CRM 2013 version. 

    Thanks

  • Suggested answer
    Naudine Profile Picture
    Naudine on at
    RE: MS CRM 2013 on-premise - c# code - Error "An unexpected error occurred" on retrieve of metadata.

    Hi There

    Commercient provides ERP and CRM systems integrations to connect the front and back office, to assist companies track data scattered between systems. The cherry on top, mapping and coding are taken out of the equation, making the integration simple and maintenance-free. Check out our services here http://bit.ly/SYNCDynamics365

  • Suggested answer
    AlexCollins Profile Picture
    AlexCollins 15 on at
    RE: MS CRM 2013 on-premise - c# code - Error "An unexpected error occurred" on retrieve of metadata.

    I used your code and successfully got a response back, the only difference being how I set up the credentials. 

    I'm not convinced this is the solution but try changing the credential setup to this: 

    ClientCredentials clientCredentials = new ClientCredentials();
    clientCredentials.UserName.UserName = "username";
    clientCredentials.UserName.Password = "password";

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans