我用一个类创建简单的 cs 文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Bed
{
public class TimeoutWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri uri)
{
WebRequest w = base.GetWebRequest(uri);
w.Timeout = 30 * 1000;
return w;
}
}
}
突然间,我的 Visual Studio 将其解释为一个表单类。我哪里出错了?
这些是我使用的版本:
Microsoft Visual Studio Ultimate 2013
Version 12.0.21005.1 REL
Microsoft .NET Framework
Version 4.5.50938
最佳答案
我不确定它是怎么发生的,但我是这样解决的:
- 右键单击项目并选择“卸载”
- 右键单击项目并选择“编辑”
- 在文件“TimeoutWebClient”中找到
我希望你能找到这样的东西:
<ItemGroup>
<Compile Include="TimeoutWebClient.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="TimeoutWebClient.Designer.cs">
<DependentUpon>TimeoutWebClient.cs</DependentUpon>
</Compile>
<!-- other files go here -->
删除 SubType
标签。如果您还想撤消任何依赖项,请删除 <DependentUpon>
标签也是如此。
保存您的项目文件,右键单击它并选择“重新加载”。
验证您是否达到了所需。
关于c# - Visual Studio 2013 将我的文件解释为表单文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23180941/