seanmcne / Microsoft.Xrm.Data.PowerShell

This module uses the CRM connection from Microsoft.Xrm.Tooling.CrmConnector.Powershell and provides common functions to create, delete, query, and update data as well as functions for common tasks such as publishing, and manipulating System & CRM User Settings, etc. The module should function for both Dynamics CRM Online and On-Premise environment.
200 stars 64 forks source link

Unable to export solution from Dynamics 365 on-premise v8.2 #530

Open prasath2k4 opened 7 months ago

prasath2k4 commented 7 months ago

I'm trying to use the below Power Shell script to export solution from CRM and it results in an error (details below), Any help is much appreciated.

``

CRM Solution Export

Set-StrictMode -Version latest

Define CRM Connection Parameters

$crmServerSourceUrl = "https://aseanicint......"
$crmServerSourcePassword = "adfsfsf" $crmServerSourceUsername = "sfsfsdf\fdfsdf" $crmServerSourceSecurePassword = ConvertTo-SecureString -String $crmServerSourcePassword -AsPlainText -Force $crmServerSourceOrgName = "CRM"

Specify the Solution Name to Export

$solutionName = "Deploy_1234"

Specify the Export File Path and Name

$exportFilePath = "C:\Temp\CRM\" $exportFileName = "Deploy_1234.zip"

InstallRequiredModule

Set-ExecutionPolicy –ExecutionPolicy Unrestricted –Scope CurrentUser

Import Micrsoft.Xrm.Data.Powershell module

Import-Module Microsoft.Xrm.Data.Powershell

Load CRM Assemblies

Add-Type -Path "C:\Temp\CRM\Microsoft.Crm.Sdk.Proxy.dll" Add-Type -Path "C:\Temp\CRM\System.ServiceModel.dll"

create pscredential

$crmSourceCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $crmServerSourceUsername, $crmServerSourceSecurePassword

create crm connection

$crmSourceConn = Get-CrmConnection -OrganizationName $crmServerSourceOrgName -ServerUrl $crmServerSourceUrl -Credential $crmSourceCredential -HomeRealmUrl $crmServerSourceUrl

export solution

Export-CrmSolution -conn $crmSourceConn -SolutionName $solutionName -SolutionFilePath $exportFilePath -SolutionZipFileName $exportFileName ``

It results in the error below

PS C:\Windows\system32> $crmSourceConn.LastCrmException An unexpected error occurred.

PS C:\Windows\system32> $crmSourceConn.LastCrmError **** FaultException`1 - ExportSolution : User Defined |=> An unexpected error occurred. An unexpected error occurred. => System.TypeInitializationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #89E14481 => System.Security.SecurityException: Microsoft Dynamics CRM has experienced an error. Refer ence number for administrators or support: #036728EF[TerminalFailure] Failed to Execute Command - ExportSolution : RequestID=419ec57a- 412d-460e-8e40-0dfac4cb8339 : User Defined duration=00:00:22.2312230 ExceptionMessage = An unexpected error occurred. An unexpected error occurred. => System.TypeInitializationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #89E14481 => System.Security.SecurityException: Microsoft Dynamics CRM has experienced an error. Refer ence number for administrators or support: #036728EF


The event viewer shows the below error

The Web Service plug-in failed in OrganizationId: 89a93214-eec9-4e73-abd7-47f37fca7ca4; SdkMessageProcessingStepId: 681f0f11-8e01-40a1-8d84-424242bb392c; EntityName: none; Stage: 30; MessageName: ExportSolution; AssemblyName: Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel, Version=8.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.TypeInitializationException: The type initializer for 'MS.Utility.EventTrace' threw an exception. at MS.Utility.EventTrace.EasyTraceEvent(Keyword keywords, Event eventID) at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, FileAccess packageAccess, Boolean streaming) at Microsoft.Crm.CrmZip..ctor() at Microsoft.Crm.Tools.ImportExportPublish.RootExportHandler.RunExport() at Microsoft.Crm.WebServices.ExportXmlService.ExportSolutionWithTargetVersion(String solutionName, Boolean managed, String targetVersion, Boolean exportAutoNumberingSettings, Boolean exportCalendarSettings, Boolean exportCustomizationSettings, Boolean exportEmailTrackingSettings, Boolean exportGeneralSettings, Boolean exportMarketingSettings, Boolean exportOutlookSynchronizationSettings, Boolean exportRelationshipRoles, Boolean exportIsvConfig, Boolean exportSales, Boolean exportExternalApplications, ExecutionContext context) Inner Exception: System.Security.SecurityException: Requested registry access is not allowed. at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource) at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) at Microsoft.Win32.Registry.GetValue(String keyName, String valueName, Object defaultValue) at MS.Utility.EventTrace.IsClassicETWRegistryEnabled() at MS.Utility.EventTrace..cctor() .

prasath2k4 commented 7 months ago

@seanmcne can you kindly help to check on this please? Appreciate your help

seanmcne commented 7 months ago

@prasath2k4 This module uses CrmConnector to export solutions (this script is a wrapper around CrmConnector to make it easier to use). That said, here's a couple of things I've noticed or have suggestions for:

I don't believe you need to run the following - these should be loaded when the module is loaded. If you're getting errors or they aren't registering, there may be a conflict locally that needs sorting out: Add-Type -Path "C:\Temp\CRM\Microsoft.Crm.Sdk.Proxy.dll" Add-Type -Path "C:\Temp\CRM\System.ServiceModel.dll"

Are you running the modules on the same PC serving/hosting the v8.2 product? If so, there could be v8.2 global assemblies registered on the same computer which might cause a conflict it would be a good idea to run the script from another PC.