The BinaryFormatter in .Net is highly platform dependent, it can't be used across different versions of the CLR never mind between programming languages. The PHP serialize function, when called on an array will actually produce output that should be simple enough to reproduce in C#, e.g.:
$array["a"] = "Foo";
$array["b"] = "Bar";
print serialize($array);
Result:
a:2:{s:1:"a";s:3:"Foo";s:1:"b";s:3:"Bar";}
Try
public static string phpStringArray(Dictionary<string, string> arr)
{
StringBuilder sb = new StringBuilder("a:")
.Append(arr.Count).Append(":{");
foreach (string key in arr.Keys)
{
sb.AppendFormat("s:{0}:\"{1}\";s:{2}:\"{3}\";",
key.Length, key, arr[key].Length, arr[key]);
}
return sb.Append('}').ToString();
}
Then
Console.WriteLine(
phpStringArray(
new Dictionary<string, string> { { "a", "Foo" }, { "b", "Bar" } })
);
Just need to Base64 Encode the result of that.