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.
201 stars 64 forks source link

Issue while running in Azure DevOps pipeline #488

Closed mschoneman closed 2 years ago

mschoneman commented 2 years ago

We've been using this library for a while, but just started getting the following error yesterday:

Unable to connect to CRM: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.Unable to Login to Dynamics CRM Unable to Login to Dynamics CRMOrganizationWebProxyClient is null OrganizationWebProxyClient is null

Any thoughts?

seanmcne commented 2 years ago

Thanks for reaching out, sorry you're having some trouble with this, I setup a test just to make sure it was working for me and so far it's working well. Can you share how you've configured your build pipeline? I also tried windows-2019.

image

image

mschoneman commented 2 years ago

It's a YAML pipeline:

trigger:
- main

stages:
- stage: TestCRM
  displayName: TestCRM
  jobs:
  - job: TestPowerShell
    pool:
      vmImage: windows-latest

    steps:
    - task: AzurePowerShell@5
      displayName: 'Test Dynamics 365 Connection'
      inputs:
          azureSubscription: 'DevTest'
          ScriptPath: 'TestDynamicsConnection.ps1'
          azurePowerShellVersion: LatestVersion
          pwsh: false

Here's the script:

Install-Module Microsoft.Xrm.Data.PowerShell -Scope CurrentUser -AllowClobber -Force -Verbose -SkipPublisherCheck -AcceptLicense

Import-Module Microsoft.Xrm.Data.Powershell -verbose

$connection = Connect-CrmOnline -ServerUrl https://xxx.crm.dynamics.com -ClientSecret <hardcoded for test> -OAuthClientId <hardcoded for test>

$connection

if ($connection.IsReady)
{
    Write-Host("Connected")
} else {
    throw "Not connected"
}
seanmcne commented 2 years ago

Are you using powershell core? If so, it isn't compatible with .NET framework modules and that very well could be the problem. I believe non-core powershell scripts are PowerShell@2

mschoneman commented 2 years ago

Shouldn't be. The pwsh: false should according to the docs use regular powershell instead of ps core

mschoneman commented 2 years ago

Script works fine on my local box (still) and had been running without issue in Azure DevOps until Oct 21. After that started failing in Azure DevOps.

mschoneman commented 2 years ago

Based on your comment I switch from the AzurePowerShell@5 task to the PowerShell@2 task and things seem to be working. Not sure what changed in the DevOps environment, but I'll just be happy that it is working. Thanks for the help, I appreciate your time and the library you've provided.