Skip to content

New-CrmEntityReference throws error in latest module versions #489

@ghost

Description

On Windows Server 2012 R2 with PowerShell 4.0 we had to downgrade the module from v2.8.14 to v2.8.11 because we started receiving the following error when fetching CRM data:

System.Management.Automation.RuntimeException: Method invocation failed because [Microsoft.Xrm.Sdk.EntityReference] does not contain a method named 'new'.
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0) at System.Management.Automation.PSScriptCmdlet.RunClause(Action1 clause, Object dollarUnderbar, Object inputToProcess)
at System.Management.Automation.PSScriptCmdlet.DoEndProcessing()
at System.Management.Automation.CommandProcessorBase.Complete()
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-CrmRecordsByFetch
+ PSComputerName : localhost

OperationStopped: (:String) [], RuntimeException
+ CategoryInfo : OperationStopped: (:String) [], RuntimeException
+ FullyQualifiedErrorId :
+ PSComputerName : localhost

We traced the issue to the implementation of the New-CrmEntityReference cmdlet, where the previous method of creating a new EntityReference

$crmEntityReference = New-Object -TypeName Microsoft.Xrm.Sdk.EntityReference

has been replaced by

$crmEntityReference = [Microsoft.Xrm.Sdk.EntityReference]::new()

We assume this has something to do with the PS version, since on Windows 10 the latest module version works perfectly.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions