On Windows8.1 PowerShell calls ToString() method of an object when it is passed as argument to a script function.
Votes from Connect: 3
Original Date Submitted: 7/10/2015 6:50:26 PM
Description:
Contact Information
Handle: Dimitar Milov
Site Name: PowerShell
Feedback ID: 1529031
Frequency: PowerShell
Regression:
Problem Description:
The issue seems to be OS specific and only reproduces on Windows 8/8.1 and Windows 10. When a .NET object instance is passed to a function as an argument the function calls the object's ToString method.
Product Studio item created by Connect Synchronizer due to creation of feedback ID 1529031 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=1529031).
Repro Steps:
Expected Results:
$Source = @"
using System;
namespace Test
{
public class TestClass
{
private bool _ts;
public bool ToStringCalled {
get {
return _ts;
}
}
public override string ToString() {
_ts = true;
return "test";
}
}
}
"@
Add-Type -TypeDefinition $Source -Language CSharp
$obj = new-object "Test.TestClass"
function test($o) {}
test $obj
$obj.ToStringCalled
> True
Internal BugId: 15638
