‘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

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

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

解決方法 十分簡單

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

string OriginalStringText = Encoding.UTF8.GetString(StringAsByteArray,0, StringAsByteArray.Length);

Hope you find it useful

Leave a Reply