InvalidCastException: Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'Xrm.new_salestransaction.

Unanswered InvalidCastException: Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'Xrm.new_salestransaction.

  • Saturday, May 05, 2012 1:39 AM
     
     

    Hi there,

    I have the Xrm class in a class library which my plugin project reference. But getting the InvalidCastException: Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'Xrm.new_salestransaction. How do I need to do? Thanks

    publicvoidExecute(IServiceProviderserviceProvider)

            {

               

    ITracingServicetracingService =

                    (

    ITracingService)serviceProvider.GetService(typeof(ITracingService));

               

             

                    serviceProvider.GetService(

    typeof(IPluginExecutionContext));

    IPluginExecutionContextcontext = (IPluginExecutionContext)IOrganizationServiceFactoryserviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    IOrganizationServiceservice = serviceFactory.CreateOrganizationService(context.UserId);

    varCrmContext = new Xrm.XrmServiceContext(service); 

    var entity = CrmContext.new_salestransaction.Where(o => o.aea_BatchId.Id == batchId).singleorDefault();                      

               

    • Edited by SPCRM2011 Saturday, May 05, 2012 1:47 AM
    •  

All Replies