2
votes

We have an installer (vdproj msi) that installs a Dynamics 2011 managed package (a zip file stored as an embedded resource) using the OrganizationServiceProxy. It constructs the OrganizationServiceProxy as follows:

var organizationUri = new Uri(string.Format(
  ORGANIZATION_SERVICE_URI_TEMPLATE, configuration.WebServiceUrl, 
  configuration.CrmOrganizationName));

var credentials = new ClientCredentials();
credentials.Windows.ClientCredential = GetNetworkCredentials();

credentials.UserName.UserName = credentials.Windows.ClientCredential.UserName;
credentials.UserName.Password = credentials.Windows.ClientCredential.Password;

var client = new OrganizationServiceProxy(organizationUri, null, credentials, null)
  { Timeout = TimeSpan.FromMilliseconds(WEB_SERVICE_TIMEOUT) };

return client;

And executes an ImportSolutionRequest

var importSolutionRequest = new ImportSolutionRequest
{
  CustomizationFile = Resources.DynamicsSolution,
  ImportJobId = Guid.NewGuid()
};
service.Execute(importSolutionRequest);

This yields the wonderfully obscure error:

The Web Service plug-in failed in OrganizationId: 510c06a3-6ee9-43a7-ba54-677054348813; SdkMessageProcessingStepId: 1b830950-e106-4ee1-b3fd-d348cb65dc8d; EntityName: none; Stage: 30; MessageName: ImportSolution; AssemblyName: Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel, Version=5.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._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) 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.Globalization.CultureNotFoundException: Culture is not supported. Parameter name: culture 0 (0x0000) is an invalid culture identifier. at System.Globalization.CultureInfo.InitializeFromCultureId(Int32 culture, Boolean useUserOverride) at Microsoft.Crm.Tools.ImportExportPublish.SolutionPackageUpgrade..ctor(ExecutionContext context) at Microsoft.Crm.Tools.ImportExportPublish.RootImportHandler..ctor(ImportXml parent, Boolean overwriteUnmanagedCustomizations, Boolean publishWorkflows, Byte[] compressedCustomizationFile, Boolean setup, Version existingDatabaseVersion, ExecutionContext context, Boolean extractAllFiles) at Microsoft.Crm.Tools.ImportExportPublish.ImportXml..ctor(Boolean overwriteUnmanagedCustomizations, Boolean publishWorkflows, Byte[] compressedCustomizationFile, Guid importJobId, Boolean convertToManaged, ExecutionContext context) at Microsoft.Crm.WebServices.ImportXmlService.ImportSolution(Boolean overwriteUnmanagedCustomizations, Boolean publishWorkflows, Byte[] customizationFile, Guid importJobId, Boolean convertToManaged, ExecutionContext context)

After several hours of research and disassembling Microsoft Dynamics internal dlls (it would be funny if it weren't so sad that I needed to do this), I found that the CallerId in the incoming request's ExecutionContext was empty (even though the request authenticated correctly using the supplied credentials).

So, I looked up the SystemUserId I want to use from the SystemUser table and specified

client.CallerId = Guid.Parse("94DB2FFC-DBDE-E011-95D5-005056AF0052");

Lo and behold, the ImportSolutionRequest succeeded after doing this.

I'm left with the questions:

  1. Is there another way of accomplishing this absurdly basic task without specifying CallerId that actually works? Why doesn't it work without it?
  2. If not, how can I get the callerId to set on the OrganizationServiceProxy based on the credentials I supplied (without hard coding it).
  3. Why am I having these kinds of problems on a fresh, completely default installation of Dynamics on a brand new server?
1

1 Answers

1
votes

I don't have much experience with programmatically importing a solution, so I can't answer 1. For question 2, I think you could use the WhoAmIRequest. As for 3, I'm not sure I'd classify it as a problem until I get an answer to 1. :)