Error cs1555 could not find program specified for main method

User398343642 posted
  • Remove From My Forums
  • Question

  • User398343642 posted

    Hello,

    I’ve just finished an asp.net core 2.0 application and wanted to publish it to my local file system, but I got two diffferent errors depending on the value of the startup object.

    So when I go to my website’s properties in Visual Studio, under ‘Application -> Startup Object’, I have four options available: Not set,
    appName.Program, Program, and Program (yes, there are two options named the same ‘Program’, I don’t know what the difference might be). So in case I choose one of the first two, I get an error something like this: «The command «»dotnet» exec —runtimeconfig
    «..pathappNamenetcoreapp2.0appName.runtimeconfig.json« —depsfile «pathappNamenetcoreapp2.0appName.deps.json» «C:Program FilesdotnetsdkNuGetFallbackFoldermicrosoft.aspnetcore.mvc.razor.viewcompilation2.0.0buildnetstandard2.0Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.dll»
    @»objReleasenetcoreapp2.0microsoft.aspnetcore.mvc.razor.viewcompilation.rsp»» exited with code 1″».

    If I choose any of the ‘Program’ options, I get this error: «CS1555 — Could not find ‘Program’ specified for Main method». I don’t know why that could be, since there clearly is a program class with a main method (I used VS’s template which has it by default,
    of course).

    Any suggestions why I get these errors?

    Thank you

    Spartai

I am following this Microsoft guide to create a windows service.

However when I try and build it on the auto generated page called «Program.cs»
That has this code in it

namespace BetfairBOTV2Service
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
            { 
                new BrainiacVersion2() // not green though!!!!!
            };
            ServiceBase.Run(ServicesToRun);
        }
    }
}

I get this error «Could not find BrainiacV2.Program» specified for Main Method

I did everything the tutorial told me to.

I have an App.Config, a Program.cs (code above), a BrainiacV2.cs which holds all my code for the service and starts like this

namespace BetfairBOTV2Service
{
    public partial class BrainiacV2 : ServiceBase
    {
        public BrainiacV2()
        {
            InitializeComponent();

My ProjectInstaller.cs with two installer objects on them
(name) serviceInstaller
Display Name: My new BetfairBotV2
ServiceName: BrainiacVersion2

And that is that.

This is the only error I am getting

The solution is called BrainiacV2

I have tried changing the code in Program.cs to

new BrainiacV2()

which turns it green but then I just get

Could not find BrainiacV2.Program specified for main method.

What am I doing wrong or need to change?

Any help would be much appreciated — thanks!

Win 7, 64 bit, .NET 4.5, C#

Я получил проект C#/Docker от коллеги и должен использовать его со своим собственным сервисом. Это REST API. Мой коллега использовал для этого Visual Studio Community 2019. Теперь я хочу запустить его на Linux-машине с установленным докером.
Есть файл докера. Когда я запускаю сборку докеров, я получаю сообщение об ошибке, что в файле *.csproj не указан основной метод. Поэтому я указал объект запуска в файле csproj. Раньше его не было.

<Project Sdk = "Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <StartupObject>Program</StartupObject> // <-- I added this line nothing else
  </PropertyGroup>

  <ItemGroup>
    <Folder Include = "wwwroot" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include = "Microsoft.AspNetCore.App" />
    <PackageReference Include = "Microsoft.AspNetCore.Razor.Design" Version = "2.1.2" />
    <PackageReference Include = "Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version = "1.4.10" />
    <PackageReference Include = "Microsoft.VisualStudio.Web.CodeGeneration.Design" Version = "2.1.9" />
  </ItemGroup>

</Project>

Но я все еще получаю сообщение об ошибке при запуске сборки докера:

user@notebook:~/Schreibtisch/DeviceApi/DeviceApi$ sudo docker build -t deviceApi .
[...]
CSC : error CS1555: Could not find 'Program' specified for Main method [/src/DeviceApi/DeviceApi.csproj]

Структура проекта следующая.
Существует каталог с именем DeviceApi. Это мой рабочий каталог (как видно из командной строки выше).
В этом каталоге есть эти файлы рядом с другими файлами проекта: Dockerfile, DeviceApi.csproj, Program.cs (который содержит основной метод)

user@notebook:~/Schreibtisch/DeviceApi/DeviceApi$ ls
appsettings.Development.json  DeviceApi.csproj             Program.cs
appsettings.json              DeviceApi.csproj.user        Properties
bin                           Handler                      ResponseFilter
Controllers                   Startup.cs                   DBManager
Models                        Util                         Dockerfile
obj                           wwwroot

Вот содержимое Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
WORKDIR /src
COPY ["DeviceApi.csproj", "DeviceApi/"]
RUN dotnet restore "DeviceApi/DeviceApi.csproj"
COPY . .
WORKDIR "/src/DeviceApi"
RUN dotnet build "DeviceApi.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "DeviceApi.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "DeviceApi.dll"]

Вот содержимое Program.cs:

namespace DeviceApi
{
    public class Program
    {

        public static ILogger<Program> LOGGER = null;
        public static IConfiguration CONF = null;
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();
            LOGGER = host.Services.GetRequiredService<ILogger<Program>>();
            CONF = Startup.Configuration;
            host.Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) => [...] ;
    }
}

Мой коллега использовал для этого Visual Studio.
Раньше я не использовал C#, и у меня мало опыта работы с Visual Studio. Я предполагаю/надеюсь, что на моей стороне небольшая ошибка пользователя, но я не знаю, что я сделал не так.

Спасибо за ваши усилия.

Понравилась статья? Поделить с друзьями:
  • Error cs1529 unity
  • Error cs1525 unexpected symbol void
  • Error cs1525 unexpected symbol public
  • Error cs1525 unexpected symbol expecting
  • Error cs1525 unexpected symbol end of file