‘System.Text.Encoding.GetString(byte[])’ is inaccessible due to its protection level

今天嘗試在Silverlight 上把Byte Array 轉成String的時候出現了以下的錯誤信息
Error 1 ‘System.Text.Encoding.GetString(byte[])’ is inaccessible due to its protection level
'System.Text.Encoding.GetString(byte[])' is inaccessible due to its protection level

CSharp

[csharp]
byte[] StringAsByteArray = Convert.FromBase64String(source);
string OriginalStringText = Encoding.UTF8.GetString(StringAsByteArray);
return OriginalStringText;
[/csharp]

經過一會兒的Research之後找到了解決的方法了

解決方法 十分簡單

我們需要用以下的Code去把Byte 讀出來
CSharp

[csharp]
string OriginalStringText = Encoding.UTF8.GetString(StringAsByteArray,0, StringAsByteArray.Length);
[/csharp]

Hope you find it useful

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.