-1

I'm novice in C#. I've cloned the project, built it successfully. Now I want to debug Postman POST request. I found the place where that request in handled in Project. That .cs file looks like this:

namespace Blah.Something
{
    public class SomethingRequest: IInterface
    {
        ...
        public object DoRequest (SomeRequest request)
        {
            ...
        }
    }
}

When I start SomethingRequest class, I have this error: enter image description here

I've tried to set .csproj in which SomethingRequest class is located as "Set as a Startup Project" as per suggestion here, and then rebuilt the solution, but I keep receiving same error. Can anyone help me to resolve that issue?

Eric Klaus
  • 923
  • 1
  • 9
  • 24
  • Please check here. https://stackoverflow.com/questions/3363106/a-project-with-an-output-type-of-class-library-cannot-be-started-directly also shouldn't your inlet be at Main()? –  Nov 04 '19 at 14:40
  • 2
    _"I've cloned the project"_ - check the project's documentation for which project should be the startup project. Because you name PostMan, I guess you should look for a Web Application project. – CodeCaster Nov 04 '19 at 14:41
  • 1
    @xTwisteDx , I already mentioned that I tried solution in that post and that didn't work, and I can't see Main there – Eric Klaus Nov 04 '19 at 14:41
  • 2
    You can't run a dll. You must create a project targetting an executable or a web site that uses this dll –  Nov 04 '19 at 14:43
  • 1
    Possible duplicate of ["A project with an Output type of Class Library cannot be started directly"](https://stackoverflow.com/questions/3363106/a-project-with-an-output-type-of-class-library-cannot-be-started-directly) – Stephen Kennedy Nov 05 '19 at 00:46
  • @StephenKennedy , please read post first, I'm referring to that post , saying that didn't help. If that post didn't help, this can't be a duplicate – Eric Klaus Nov 05 '19 at 13:08

1 Answers1

-1

You can't run the classlibrary directly. I have two solutions and you may refer to it.

First, Please create a new project(such as console app) to call the method in that library.

Like the following:

Classlibrary:

namespace Testlibrary
{
  public  class Student
    {
        public void SayHello(string name)
        {
            Console.WriteLine("Hello, I am {0}",name);
        }
    }
}

Console app:(Please add reference)

using System;
using Testlibrary;

namespace _1.Test_for_using_library
{
    class Program
    {
        static void Main(string[] args)
        {
            Student s = new Student();
            s.SayHello("Jack");
            Console.ReadKey();
        }
    }
}

Result:

enter image description here

Second, you can change the classlibrary to the console app to call the method.

Right click the Classlibrary->Properties-> Change Output type to Console Application -> Add the following code in the Student Class.

static void Main()
        {
            Student student = new Student();
            student.SayHello("Jack");
            Console.ReadKey();
        }

Finally, you will the same result as the before.

Jack J Jun
  • 5,633
  • 1
  • 9
  • 27