Hi Im developing plugins to CRM 2013 On-premises with Claims-based Authentication.
Im experiencing problems with using early-binding together with Claims-based authentication.
I can generate the proxy classes with svcutil.exe but when I try to use them in my plugins I get this error:
Exception: Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'Crm.Context.Account'.
This is the plugin code that fails:
var context = serviceProvider.GetPluginExecutionContext();
var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.UserId);
var targetEntity = context.InputParameters[ParameterName.Target] as Entity
if (context.MessageName != MessageName.Create || targetEntity.LogicalName != Account.EntityLogicalName) return;
using (var ctx = new ProxyContext(service))
{
var query = from a in ctx.AccountSet
where a.AccountId.Equals(targetEntity.Id)
select a;
var account = query.ToList().FirstOrDefault();
}
Any help would be greatly appreciated.