locked
CRM 2011 - Early bound proxy classes double loading RRS feed

  • Question

  • I'm working with a plugin which does some task automation for my company. One of those tasks is to create a sharepoint site reference in an organization. One of the steps is to see if the site reference has already been created:

     

    private static bool CheckSiteAssociated(IOrganizationService organizationService, pareto_organization organization)
    {
    	bool exists;
    	using (var osc = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(organizationService))
    	{
    		exists = (from ss in osc.CreateQuery("sharepointsite")
    			where (string)ss["absoluteurl"] == organization.pareto_SharePointSiteURL
    			select ss).ToList().Any();
    	}
    	return exists;
    }

     

    NOTE: This code is not running in the same organization that the sharepoint site reference is being created. eg. Organization A manages a list of organizations. When a user associates a sharepoint site with organization B (from our objects in organization A) the plugin will create the sharepoint reference.

    So I am creating a new IOrganizationService and making a call (see above) to the new organization. When I create a new OrganizationServiceContext I get the below exception. My guess is that because I'm using an OrganizationServiceContext for Organization A and initializing another one for Organization B that its trying to load the proxy classes twice. I figured if I used the default OrganizationServiceContext from the Microsoft.Xrm.Sdk.Client library that it wouldn't try to load the proxy types again... Apparently this wasn't true. 

    Plugin Trace:
    
    [Pareto.Crm2011.Server.Plugins.CRMAutomation: Pareto.Crm2011.Server.Plugins.CRMAutomation.CRMAutomationPlugin]
    [64741d2c-5065-e011-9975-000c29d6f977: Pareto.CRMAutomationPlugin: Post - Create of pareto_organization]
    Create of type pareto_organization
    Target admin-test-create
    Retrieved deployment devel
    Created deployment service
    
    
    Error Message:
    
    Unhandled Exception: Microsoft.Xrm.Sdk.InvalidPluginExecutionException: A proxy type with the name account has been defined by another assembly. Current type: Pareto.Crm2011.Server.Plugins.CRMAutomation.Services.Account, Pareto.Crm2011.Server.Plugins.CRMAutomation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9d04a1dca2c654ed, Existing type: Pareto.Crm2011.Server.Plugins.CRMAutomation.Services.Account, Pareto.Crm2011.Server.Plugins.CRMAutomation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9d04a1dca2c654ed
    Parameter name: account
      at Microsoft.Crm.Asynchronous.EventOperation.CreateAsyncResultFromException(AsyncExecutionContext context, Exception e)
      at Microsoft.Crm.Asynchronous.EventOperation.InvokePlugin(AsyncExecutionContext context, IPlugin pluginInstance)
      at Microsoft.Crm.Asynchronous.EventOperation.InternalExecute(AsyncEvent asyncEvent)
      at Microsoft.Crm.Asynchronous.AsyncOperationCommand.Execute(AsyncEvent asyncEvent)
      at Microsoft.Crm.Asynchronous.QueueManager.PoolHandler.ProcessAsyncEvent(AsyncEvent asyncEvent)
    Inner Exception: System.ArgumentException: A proxy type with the name account has been defined by another assembly. Current type: Pareto.Crm2011.Server.Plugins.CRMAutomation.Services.Account, Pareto.Crm2011.Server.Plugins.CRMAutomation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9d04a1dca2c654ed, Existing type: Pareto.Crm2011.Server.Plugins.CRMAutomation.Services.Account, Pareto.Crm2011.Server.Plugins.CRMAutomation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9d04a1dca2c654ed
    Parameter name: account
    
    Server stack trace: 
      at Microsoft.Xrm.Sdk.AppDomainBasedKnownProxyTypesProvider.AddTypeMapping(Assembly assembly, Type type, String proxyName)
      at Microsoft.Xrm.Sdk.KnownProxyTypesProvider.LoadKnownTypes(Assembly assembly)
      at Microsoft.Xrm.Sdk.KnownProxyTypesProvider.RegisterAssembly(Assembly assembly)
      at Microsoft.Xrm.Sdk.KnownProxyTypesProvider.InitializeLoadedAssemblies()
      at Microsoft.Xrm.Sdk.KnownProxyTypesProvider.GetInstance(Boolean supportIndividualAssemblies)
      at Microsoft.Xrm.Sdk.ProxySerializationSurrogate.System.Runtime.Serialization.IDataContractSurrogate.GetObjectToSerialize(Object obj, Type targetType)
      at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
      at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
      at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
      at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)
      at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)
      at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameter(XmlDictionaryWriter writer, PartInfo part, Object graph)
      at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameters(XmlDictionaryWriter writer, PartInfo[] parts, Object[] parameters)
      at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)
      at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)
      at System.ServiceModel.Channels.BodyWriter.WriteBodyContents(XmlDictionaryWriter writer)
      at System.ServiceModel.Security.SecurityAppliedMessage.WriteBodyToSignThenEncryptWithFragments(Stream stream, Boolean includeComments, String[] inclusivePrefixes, EncryptedData encryptedData, SymmetricAlgorithm algorithm, XmlDictionaryWriter writer)
      at System.ServiceModel.Security.WSSecurityOneDotZeroSendSecurityHeader.ApplyBodySecurity(XmlDictionaryWriter writer, IPrefixGenerator prefixGenerator)
      at System.ServiceModel.Security.SecurityAppliedMessage.OnWriteMessage(XmlDictionaryWriter writer)
      at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)
      at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
      at System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message)
      at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
      at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
      at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
      at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
      at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
      at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
      at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    
    Exception rethrown at [0]: 
      at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
      at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
      at Microsoft.Xrm.Sdk.IOrganizationService.Execute(OrganizationRequest request)
      at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.ExecuteCore(OrganizationRequest request)
      at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.Execute(OrganizationRequest request)
      at Microsoft.Xrm.Sdk.Linq.QueryProvider.RetrieveEntityCollection(OrganizationRequest request, NavigationSource source)
      at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute(QueryExpression qe, Boolean throwIfSequenceIsEmpty, Boolean throwIfSequenceNotSingle, Projection projection, NavigationSource source, List`1 linkLookups, String& pagingCookie, Boolean& moreRecords)
      at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute[TElement](QueryExpression qe, Boolean throwIfSequenceIsEmpty, Boolean throwIfSequenceNotSingle, Projection projection, NavigationSource source, List`1 linkLookups)
      at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute[TElement](Expression expression)
      at Microsoft.Xrm.Sdk.Linq.QueryProvider.GetEnumerator[TElement](Expression expression)
      at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
      at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
      at Pareto.Crm2011.Server.Plugins.CRMAutomation.Managers.SharePointManager.CheckSiteAssociated(IOrganizationService organizationService, pareto_organization organization)
      at Pareto.Crm2011.Server.Plugins.CRMAutomation.Managers.SharePointManager.CreateSharepointSite(IOrganizationService orgService, pareto_organization organization)
      at Pareto.Crm2011.Server.Plugins.CRMAutomation.CRMAutomationPlugin.Execute(IServiceProvider serviceProvider)
      at Microsoft.Crm.Asynchronous.V5ProxyPlugin.Execute(IServiceProvider serviceProvider)
      at Microsoft.Crm.Asynchronous.EventOperation.InvokePlugin(AsyncExecutionContext context, IPlugin pluginInstance)
    

    Thank you in advance for your help. If you think you may be able to help with any of my unanswered threads please look at them here
    Monday, May 16, 2011 4:37 PM