Microsoft – PowerShell – Error Message – Cannot set the Value property for PSMemberInfo object of type “System.Management.Automation.PSMethod”.

Cannot set the Value property for PSMemberInfo object

of type “System.Management.Automation.PSMethod”.

Microsoft .Net Class – friend.cs

using System;
using System.Collections.Generic;
using System.Collections;

public class friend
{

	ArrayList objListofFriends = null;

	public friend()
	{
		objListofFriends = new ArrayList();
	}

	public void clearLists()
	{
		objListofFriends.Clear();
	}

	public void friendAdd(String friend)
	{
		objListofFriends.Add(friend);
	}

	public void friendAddRange(ArrayList objList)
	{
		objListofFriends.AddRange(objList);
	}

	// return list of Friend
	public ArrayList listofFriends()
	{
   		return (objListofFriends);

	}

	// return list of Friend
	public ArrayList listofFriendsProperty
	{
		get
		{
			return (objListofFriends);
		}	

	}

}

Microsoft Powershell Class

    $file = 'friend.cs';
    $fileFullPath = resolve-path $file;
    $Source = [System.IO.File]::ReadAllText($file);

    $strLog = "Import Files :- fileFullPath: {0}"-f $fileFullPath
    Write-Debug $strLog
    Add-Type -TypeDefinition $Source -Language CSharpVersion3;

    $objFriend = New-Object friend;

    #To add friends
    $objFriend.friendAdd("John Smith");
    $objFriend.friendAdd("Sandra B.")

    # to get list of friends
    [array] $objList = $null;
    $objList = $objFriend.listofFriends;

    #to get object type and number of entries
    $strLogFormat = "Friend Object Type {0} & # of Friends {1}";

    $strLog = $strLogFormat -f 
                    $objList.getType()
                  , $objList.Length;

    Write-Host($strLog);

    $strLog = $strLogFormat -f 
                   ($objFriend.listofFriends).getType()
                 , ($objFriend.listofFriends).Count;

    Write-Host($strLog);

    $strLog = $strLogFormat -f 
                 ($objFriend.listofFriendsProperty).getType()
               , ($objFriend.listofFriendsProperty).Count;

    Write-Host($strLog);

Output

--When we invoked the Method, stored a local reference, and reference that local
--object
Friend Object Type System.Object[] & Number of Friends 1

-- when we invoked the Method and Reference the result of that reference
Friend Object Type System.Management.Automation.PSMethod & Number of Friends

-- when we invoked the property and Reference the result of that reference
Friend Object Type System.Collections.ArrayList & Number of Friends 2

If in C# Source Code the Object’s data are not properly “exposed” as properties, you might possibly get errors such as

1) Cannot set the Value property for PSMemberInfo object of type “System.Management.Automation.PSMethod”.

To get better data on how the Object’s data are exposed use the getType() method call.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s