If you already have data as PhpBytes, passing it as String may corrupt encoding (but it is cause of wrong configuration anyway)

You can accept data as Object (object data), and check the type of variable additionally inside the function:
if (data is PhpBytes) ... else { string str = Convert.ObjectToString(data); }