C
C#4mo ago
DWTD

CS 0101 , CS 0111 error[Solved]

this is code:
// C# 샘플 코드
using System;
using System.Net;
using System.Net.Http;
using System.IO;

namespace ConsoleApp1
{
class Program
{
static HttpClient client = new HttpClient();
static void Main(string[] args)
{
string url = "[api url]"; // URL
url += "?ServiceKey=" + "[api key]"; // Service Key
url += "&pageNo=1";
url += "&numOfRows=10";
url += "&dataType=XML";
url += "&fromTmFc=20171101";
url += "&toTmFc=20171129";

var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";

string results = string.Empty;
HttpWebResponse response;
using (response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
results = reader.ReadToEnd();
}

Console.WriteLine(results);
}
}
}
// C# 샘플 코드
using System;
using System.Net;
using System.Net.Http;
using System.IO;

namespace ConsoleApp1
{
class Program
{
static HttpClient client = new HttpClient();
static void Main(string[] args)
{
string url = "[api url]"; // URL
url += "?ServiceKey=" + "[api key]"; // Service Key
url += "&pageNo=1";
url += "&numOfRows=10";
url += "&dataType=XML";
url += "&fromTmFc=20171101";
url += "&toTmFc=20171129";

var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";

string results = string.Empty;
HttpWebResponse response;
using (response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
results = reader.ReadToEnd();
}

Console.WriteLine(results);
}
}
}
this is the error: Severity Code Description Project File Line Suppression Status Error CS0111 Type 'Program' predefines a member 'Main' with the same parameter type. Ei C:\Users[name]\source\repos\ei\ei\Form1.Designer.cs 12 active, Severity Code Description Project File Line Suppression Status Error CS0101 Namespace 'Program' already contains a definition for 'ConsoleApp1'. Ei C:\Users[name]\source\repos\Ei\Ei\Form1.Designer.cs 9 active
9 Replies
TheRanger
TheRanger4mo ago
yeah it seems u have 2 files that define 2 classes of Program and 2 main methods delete one of the files usually a file that ends with .designer.cs should be only for designing forms, not for main methods
SG97
SG974mo ago
Why do you have a HttpClient if you're not using it? WebRequest is not recommended
DWTD
DWTD4mo ago
Currently CS0017 error is appearing. // C# 샘플 코드 using System; using System.Net; using System.Net.Http; using System.IO; namespace ConsoleApp1 { class Program { static HttpClient client = new HttpClient(); public static HttpClient Client { get => Client1; set => Client1 = value; } public static HttpClient Client1 { get => Client3; set => Client3 = value; } public static HttpClient Client2 { get => Client3; set => Client3 = value; } public static HttpClient Client3 { get => client; set => client = value; } static void Main(string[] args) { string url = "http://apis.data.go.kr/1360000/EqkInfoService/getEqkMsg"; // URL url += "?ServiceKey=" + "[API KEY}"; // Service Key url += "&pageNo=1"; url += "&numOfRows=10"; url += "&dataType=XML"; url += "&fromTmFc=20171101"; url += "&toTmFc=20171129"; var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; string results = string.Empty; HttpWebResponse response; using (response = request.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); results = reader.ReadToEnd(); } Console.WriteLine(results); } } }
Angius
Angius4mo ago
Means you have more than one main method Is there any other file you have in the project?
DWTD
DWTD4mo ago
Umm There is a file
Angius
Angius4mo ago
Does it have a Main method inside? Or, on the contrary, no methods or classes, just top-level code?
DWTD
DWTD4mo ago
Hmm, it looks like I put the same code in different files. :pepeCEASE: But which file should I put that code in?:bigthonk:
Angius
Angius4mo ago
You can have only one, single, main file You can spread the code across however many other files you want, yes But there can only be one entry point
DWTD
DWTD4mo ago
The error has been resolved. Thank you to everyone who helped.