C#,Craft.Net抛出JSON.Net异常。无法启动

时间:2013-12-10 02:28:32

标签: c# json.net minecraft

我开始研究改装的Minecraft发射器。当我将用户名和密码传递给Craft.Nets Session.DoLogin()

时,我不断收到此错误
private void bLaunch_Click(object sender, EventArgs e)
{
    string sessionID = Session.DoLogin(lblUser.Text, lblPass.Text).SessionId;
}

Newtonsoft.Json.dll中出现未处理的“Newtonsoft.Json.JsonSerializationException”类型异常

其他信息:ISerializable类型'Craft.Net.Client.Session + MinecraftAuthenticationException'没有有效的构造函数。要正确实现ISerializable,应该存在一个采用SerializationInfo和StreamingContext参数的构造函数。路径'',第1行,第107位。

到底发生了什么?它与JSON有关吗?或者是Craft.Net的问题?

项目中包含了来自Craft.Net 1.7.x分支的DotMinecraft.cs,PKCSKeyGenerator.cs,RuntimeInfo.cs和Session.cs。来自NuGet的Json.Net也包括在内

抛出错误的会话代码:

var serializer = new JsonSerializer();
            try
            {
                var request = (HttpWebRequest)WebRequest.Create("https://authserver.mojang.com/authenticate");
                request.ContentType = "application/json";
                request.Method = "POST";
                var token = Guid.NewGuid().ToString();
                var blob = new AuthenticationBlob(username, password, token);
                var json = JsonConvert.SerializeObject(blob);
                var stream = request.GetRequestStream();
                using (var writer = new StreamWriter(stream))
                    writer.Write(json);
                var response = request.GetResponse();
                stream = response.GetResponseStream();
                var session = serializer.Deserialize<Session>(new JsonTextReader(new StreamReader(stream)));
                session.UserName = username;
                return session;
            }
            catch (WebException e)
            {
                var stream = e.Response.GetResponseStream();
                var json = new StreamReader(stream).ReadToEnd();
                stream.Close();
                throw JsonConvert.DeserializeObject<MinecraftAuthenticationException>(json);
            }

0 个答案:

没有答案