web
You’re offline. This is a read only version of the page.
close
Skip to main content
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

I have the same question (0)
  • Suggested answer
    AlexCollins Profile Picture
    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";

  • Suggested answer
    Naudine Profile Picture
    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

  • Suresh Sorde Profile Picture
    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

  • Suresh Sorde Profile Picture
    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?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans