atw*_*pub 63 c# visual-studio-2010
我开始将我的代码组织成seperarate .cs文件,并且为了允许与UI一起工作的方法继续这样做,我将在相同的命名空间和公共部分类名下创建.cs代码,以便方法可以是可互操作的.
我的标题在四个文件中看起来像这样,包括我调用的主要核心文件:
public shell()
{
InitializeComponent();
}
Run Code Online (Sandbox Code Playgroud)
与UI一起使用的.cs文件的标头区域(并且似乎导致了这种新的冲突):
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Data.SqlServerCe;
using System.Diagnostics;
using System.Threading;
using System.Collections.Specialized;
using System.Net;
using System.Runtime.InteropServices;
using watin = WatiN.Core;
using WatiN.Core.Native.InternetExplorer;
using System.Web;
namespace WindowsFormsApplication1
{
public partial class shell : Form
{
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试调试/预览我的应用程序时(BTW这是Visual Studio 2010 Express中的Windows应用程序),我收到以下错误消息:
不包含适用于入口点的静态"主"方法
我在Application-> Startup对象中查看了应用程序属性,但它没有提供任何选项.如何通知应用程序从具有InitializeComponent()的.cs文件开始; 命令?
我还是很新,这是我第一次用c#代码组织方法.
小智 105
我也在考虑这个问题,在我看来,解决方案太容易了.我在解决方案中添加了一个新的空项目.新添加的项目将自动设置为控制台应用程序.但由于添加的项目是一个"空"项目,因此该新项目中不存在任何Program.cs.(正如所料)
我需要做的就是将项目属性的输出类型更改为类库
Aut*_*ted 65
将项目>属性下的输出类型更改为"类库"的输出类型.默认情况下,此设置可能已设置为"控制台应用程序".
eyo*_*ssi 16
尝试将此方法添加到类中,看看是否仍然出现错误:
[STAThread]
static void Main()
{
}
Run Code Online (Sandbox Code Playgroud)
小智 13
确保您没有使用void
类似async
的
static async void Main(string[] args)
Run Code Online (Sandbox Code Playgroud)
如果是,那就void
改成Task
喜欢
static async Task Main(string[] args)
Run Code Online (Sandbox Code Playgroud)
ROM*_*ROM 11
如果您没有命名文件Program.cs
,只需添加一个新类并命名Program.cs
.
然后粘贴此代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Sales {
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());
}
}
}
Run Code Online (Sandbox Code Playgroud)
<OutputType>Library</OutputType>
干杯!
在 VS 2017 中出现此问题的原因是:
静态异步任务Main(string[] args)
(功能“async main”在 C# 7.0 中不可用。请使用 7.1 或更高版本的语言)
添加
<LangVersion>latest</LangVersion>
对 app.csproj 有帮助。
小智 5
我遇到了此错误,并通过此解决方案解决了。
--> Right click on the project
--> and select "Properties"
--> then set "Output Type" to "Class Library".
Run Code Online (Sandbox Code Playgroud)
小智 5
对我来说,该错误实际上是由“功能 'async main' 在 C# 7.0 中不可用。请使用语言版本 7.1 或更高版本”产生的。此问题导致错误列表中出现“不包含适合入口点的静态‘main’方法”消息,但输出窗口显示“不可用”错误。为了更正此问题,我在高级构建设置下将语言版本从“C# 最新次要版本(默认)”更改为“C# 最新次要版本(最新)”。
归档时间: |
|
查看次数: |
198741 次 |
最近记录: |