【发布时间】:2020-03-04 23:37:27
【问题描述】:
我遇到了一个非常奇怪的问题,今天早些时候我有大量代码在 Visual Studio 中运行和运行,我的表单运行完美。我去吃午饭回来了,试图打开它,什么也没有。它运行,有 0 个错误,它使用内存但它不会显示表单。据我所知,我没有改变任何东西。
我创建了一个新的 Windows 窗体应用程序并逐行重写了代码,我找到了破坏它的原因,但是我终生无法弄清楚它为什么会破坏它。
Form1.cs 损坏
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RestSharp;
using Newtonsoft;
using Newtonsoft.Json;
namespace RestApiViewerWUG
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var client = new RestClient("http://notrelevent.whocares.com/api/v1/token");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Basic cmVzdDo5RGJSIypkQDQ=");
request.AddHeader("Content-Type", "text/plain");
request.AddParameter("text/plain", "userName=rest&password=xxxxxx&grant_type=password", ParameterType.RequestBody);
IRestResponse response = client.Execute(request); //THIS LINE BREAKS IT
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
问题
只需删除“IRestResponse response = client.Execute(request);”行修复它并允许表单出现。
我尝试了什么?
- 我已确保正确安装和引用了 RestSharp,我有 甚至尝试了几个版本。
- 我已经卸载并重新安装了 Visual Studio 2015
- 如前所述,我已经逐行创建了一个全新的项目
- 断点/写入控制台/日志什么都不做,0 当该行留在代码中时会发生任何事情
其他信息
程序.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RestApiViewerWUG
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
形式:
实际上只是文本框,其确切名称为 textBox1
【问题讨论】:
标签: c# winforms visual-studio-2015 restsharp