PowerShell – Error – “Cannot process argument transformation on parameter ”. Reference type is expected in argument.

Error

Error – Text

readConfigurationFile : Cannot process argument transformation on parameter 'loadDuration'. Reference type is expected in argument.

Error – Image

PowerShell_Error_20181018_0558PM

Reproduce

Code


function readConfigurationFile
{

	Param(

			  [parameter(Mandatory=$true)]
			  [String]
			  $scriptName

			, [parameter(Mandatory=$true)]
			  [Object]
			  $cstrbld		

			, [parameter(Mandatory=$true)]
			  [ref] [int]
			  $loadDuration
    )

	###########################################################
	# Get Current Folder
	###########################################################
	$currentFolder=Convert-Path .

	###########################################################
	# Ini - Get Current File
	###########################################################
	$fileIni = "dbsettings.ini"

}

Remediation

Outline

  1. The third argument is an int and for changes to persists it needs to be passed as ref
  2. Current Entry
    • [ref] [int]
      • We are defining it as both ref and int
  3. Revision
    • [ref]
      • Please remove [int] and have system pass along as reference
      • reference obviously means a pre-recorded address in memory

Code



function readConfigurationFile
{

	Param(
	
			  [parameter(Mandatory=$true)]
			  [String]
			  $scriptName
			  
			, [parameter(Mandatory=$true)]
			  [Object]
			  $cstrbld		
			  
			, [parameter(Mandatory=$true)]
			  [ref] #[int]
			  $loadDuration
    )
	
	###########################################################
	# Get Current Folder
	###########################################################
	$currentFolder=Convert-Path .
}

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s