Hi,
I have a netcoreapp2.0 project that failed to build with the following error when I tried to build it with dotnet build
:
CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point
Then I open the project in Visual Studio (d15prerel 26629.02), the project built fine in VS, and after that the error is gone from ‘dotnet build’ and it succeeds.
After I run ‘dotnet clean’, ‘dotnet build’ starts failing with the same error
Here is my project file:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.0</TargetFramework> <RuntimeIdentifiers>win10-x64</RuntimeIdentifiers> <!-- omitted AssemblyName and RootNamespace properties --> <LangVersion>Latest</LangVersion> <PackageTargetFallback>$(PackageTargetFallback);portable-net40+sl5+win8+wp8+wpa81;portable-net45+win8+wp8+wpa81</PackageTargetFallback> </PropertyGroup> <ItemGroup> <!-- some project references to other projects --> </ItemGroup> </Project>
There is only one Program.cs file in the project, it has this entry point:
namespace ... { static class Program { ... public static async Task Main(string[] args) { } ...
- Remove From My Forums
-
Question
-
Trying to compile RemoteUpload.cs (http://code.msdn.microsoft.com/CSASPNETRemoteUploadAndDown-a80b7cb5/sourcecode?fileId=21989&pathId=205455091)
using «C:WINDOWSMicrosoft.NETFrameworkv4.0.30319csc.exe» /t:exe /r:system.dll /out:RemoteUpload.exe f:RemoteUpload.csI’m getting: error CS5001: Program ‘c:WINDOWSMicrosoft.NETFrameworkRemoteUpload.exe’ does not contain a static ‘Main’ method suitable for an entry point
How could I add Main method to the code so that it could compile and get the executable?
Thanks.
Answers
-
This will need to be compiled as a DLL, not an EXE. The error (that there is no «Main» method) basically is saying that you don’t have any logic for how to
use the type as a program — it’s just the type (a library).
Reed Copsey, Jr. — http://reedcopsey.com
If a post answers your question, please click «Mark As Answer» on that post and «Mark as Helpful«.-
Proposed as answer by
Thursday, November 15, 2012 5:35 AM
-
Marked as answer by
Lisa Zhu
Tuesday, November 20, 2012 9:57 AM
-
Proposed as answer by
-
The upload and download code is not meant to produce an exe — it’s part of an ASP application.
You could possibly compile them as library routines (i.e. as dll) then write an app that uses them.
Alternatively, write an app and copy/paste the code into it (or use VS to add existing files).
Regards David R
—————————————————————
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
Object-oriented programming offers a sustainable way to write spaghetti code. — Paul Graham.
Every program eventually becomes rococo, and then rubble. — Alan Perlis
The only valid measurement of code quality: WTFs/minute.-
Proposed as answer by
Lisa Zhu
Thursday, November 15, 2012 5:34 AM -
Marked as answer by
Lisa Zhu
Tuesday, November 20, 2012 9:57 AM
-
Proposed as answer by
If you want to create an executable file from your ‘C#’ project or file, your code should contain a ‘static Main’ method. This is an entry point to ‘C#’ program. Otherwise, ‘C#’ compiler will throw the below error:
error CS5001: Program 'xyz.exe' does not contain a static 'Main' method suitable for an entry point
To resolve this error, we have two options here.
- One is, add ‘
static Main
‘ method into the project or the class.- Entry point for standalone ‘C#’ application is it’s ‘Main’ method. ‘
static Main
‘ method should exist in any one class in ‘C#’ project or file.
- Entry point for standalone ‘C#’ application is it’s ‘Main’ method. ‘
- Other option is, build the project or file as a library (DLL – Dynamic Link Library).
- These type of files are not self-executable. DLL files will be used into other assemblies or applications. So, for these file, ‘Main’ entry point is not required.
That said, depending on the requirement, we can create a self executable file or a DLL from the ‘C#’ code file or project.
Let’s take a simple example to produce the error and discuss about the steps to resolve the issue.
// Sample.cs public class Sample { public void Display() { System.Console.WriteLine("Hello, World!"); } };
When we compile above program; ‘C#’ compiler will throw below error:
c:>csc Sample.cs Microsoft (R) Visual C# Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 Copyright (C) Microsoft Corporation. All rights reserved. error CS5001: Program 'c:Sample.exe' does not contain a static 'Main' method suitable for an entry point
As we mentioned above, we have two ways to resolve this problem. Lets try to resolve this without modifying any code.
Compile the above program “Sample.cs” as a target library instead of an executable. Below is the command:
c:>csc /target:library Sample.cs Microsoft (R) Visual C# Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 Copyright (C) Microsoft Corporation. All rights reserved. Observe that 'C#' compiler successfully compiled the program and generates "Sample.dll" file.
Another way to resolve this error is, by adding the ‘static Main’ method. ‘Main’ method should be added into the ‘Sample’ class as a static method. After adding the ‘Main’ method above code looks like below.
// Sample.cs public class Sample { public void Display() { System.Console.WriteLine("Hello, World!"); } static void Main() { } };
Now compile this program and observe that ‘C#’ compiler successfully compiled the program and generates “Sample.exe” file. Below is the command to compile above code:
csc basic.cs
We can choose any one of these methods, depending on our requirements, to resolve this issue “error CS5001”.
(Raju)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApp6 { class Workwithstr { string s; public Workwithstr(string s) { this.s = s; } public void Ex1(string s) { DateTime dt = DateTime.Now; for (int i = 0; i < 100000; i++) { s += "1"; } Console.WriteLine("Со строкой: {0}", DateTime.Now - dt); dt = DateTime.Now; StringBuilder sb = new StringBuilder(); for (int i = 0; i < 100000; i++) { sb.Append("1"); } Console.WriteLine("Со StringBuilder: {0}", DateTime.Now - dt); } static public int Ex2(string s) { int c = 0; for (int i = 0; i < s.Length; i++) if (s[i] == ' ') c++; return c; } static public int Ex3(string s) { char prob = ' '; int k = 1; for (int i = 0; i < s.Length; i++) { if (s[i] == prob) { k++; } } return k; } public void Ex4(string s) { StringBuilder sb = new StringBuilder(s); int n = 0; char M = sb[0]; for (int i = 1; i < s.Length; i++) { if (sb[i] == ' ') { sb[n] = Char.ToUpper(s[i - 1]); sb[i - 1] = Char.ToUpper(M); n = i + 1; M = sb[n]; } if (i == sb.Length - 1) { sb[n] = Char.ToUpper(s[i]); sb[i] = Char.ToUpper(M); } } Console.WriteLine(sb); } public void Ex5(string s) { Console.WriteLine("Введите предложение:"); string str = Console.ReadLine(); char[] prd = str.ToLower().ToCharArray(); char[] vowels = new char[] { 'а', 'и', 'е', 'ё', 'о', 'у', 'ы', 'э', 'ю', 'я' }; char[] conson = new char[] { 'б', 'в', 'г', 'д', 'ж', 'з', 'й', 'к', 'л', 'м', 'н', 'п', 'р', 'с', 'т', 'ф', 'х', 'ц', 'ч', 'ш', 'щ' }; char[] punct = new char[] { '.', '?', '!', ':', ';', ',', '-', '(', ')', '"' }; int vowelsCount = 0; int consonCount = 0; int punctCount = 0; { foreach (char ch in prd) foreach (char cha in vowels) if (ch == cha) vowelsCount++; Console.WriteLine("Гласные: " + vowelsCount); } { foreach (char ch in prd) foreach (char cha in punct) if (ch == cha) punctCount++; Console.WriteLine("Знаки препинания: " + punctCount); } { foreach (char ch in prd) foreach (char cha in conson) if (ch == cha) consonCount++; Console.WriteLine("Согласные: " + consonCount); } } public void Ex6(string s) { Console.Write("Введите предложение: "); string prd = Console.ReadLine(); Console.Write("Введите символ: "); char c = (char)Console.Read(); int i = prd.IndexOf(c); if (i < 0) { Console.WriteLine("Такого символа в предложении нет"); } else { Console.WriteLine("Найден символ с номером {0}", i + 1); if (i > 0) { Console.WriteLine("Символ слева от него: {0}", prd[i - 1]); } if (i < prd.Length - 1) { Console.WriteLine("Символ справа от него: {0}", prd[i + 1]); } } } static public int Ex7(string s) { int k = 0; for (int i = 0; i < s.Length; i++) { int c = s[i]; while (c > 0) { k += c % 10; c /= 10; } } return k; } static public StringBuilder Ex8(string vs) { StringBuilder s = new StringBuilder(vs); string vr = "00.00.0000"; StringBuilder r = .StringBuilder(vr); if (s[1] == '/') { r[4] = s[0]; if (s[3] == '/') { r[1] = s[2]; } else { r[0] = s[2]; r[1] = s[3]; } } else { r[3] = s[0]; r[4] = s[1]; if (s[4] == '/') { r[1] = s[3]; } else { r[0] = s[3]; r[1] = s[4]; } } for (int i = 1; i < 5; i++) { r[r.Length - i] = s[s.Length - i]; } return r; } public void Ex9(string s) { string alph = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"; StringBuilder st = new StringBuilder(s); char[] prob = { ' ' }; double kpower = 0; double kwords = 1; for (int i = 0; i < s.Length; i++) { if (s.Substring(i, 1).IndexOfAny(prob) != -1) kwords++; } for (int i = 0; i < st.Length; i++) { char[] x = { s[i] }; for (int j = 0; j < alph.Length; j++) { if (alph.Substring(j, 1).IndexOfAny(x) != -1) kpower = kpower + j; } } double mean = kpower / kwords; Console.WriteLine(mean); double power = 0; int n = 0; int m = 0; for (int i = 0; i < st.Length; i++) { if (s.Substring(i, 1).IndexOfAny(prob) != -1) { m = i; for (int j = n; j < m; j++) { char[] x = { s[j] }; for (int l = 0; l < alph.Length; l++) { if (alph.Substring(l, 1).IndexOfAny(x) != -1) power = power + l; } } if (power < mean) { for (int j = 0; j < m; j++) { if (j >= n) { st[j] = System.Char.ToLower(st[j]); } } } else { for (int j = 0; j < m; j++) { if (j >= n) { st[j] = System.Char.ToUpper(st[j]); } } } n = i + 1; } m = i + 1; } for (int j = n; j < m; j++) { char[] x = { s[j] }; for (int l = 0; l < alph.Length; l++) { if (alph.Substring(l, 1).IndexOfAny(x) != -1) power = power + l; } } if (power < mean) { for (int j = 0; j < m; j++) { if (j >= n) { st[j] = System.Char.ToLower(st[j]); } } } else { for (int j = 0; j < m; j++) { if (j >= n) { st[j] = System.Char.ToUpper(st[j]); } } } Console.WriteLine(st); } static int CalculatePower(string word) { var chars = new HashSet<char>(); foreach (var letter in word) { chars.Add(letter); } return chars.Count; } static void SortByLengthAndPower(string[] words) { for (int i = 0; i < words.Length; i++) { for (int j = 0; j < words.Length - i - 1; j++) { if (words[j].Length > words[j + 1].Length) { var temp = words[j]; words[j] = words[j + 1]; words[j + 1] = temp; } if (words[j].Length == words[j + 1].Length) { if (CalculatePower(words[j]) > CalculatePower(words[j + 1])) { var temp = words[j]; words[j] = words[j + 1]; words[j + 1] = temp; } } } } } public void Ex10(string s) { var words = s.Split(' '); SortByLengthAndPower(words); foreach (var word in words) { Console.Write(word + " "); } } public void Ex11(string s) { StringBuilder sb = new StringBuilder(s); string g = "ауоыиэяюёе"; string st = "бвгджзйклмнпрстфхцчшщьъ"; string alf = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"; for (int i = 0; i < sb.Length; i++) { char A = Char.ToLower(s[i]); bool chec = true; for (int j = 0; j < g.Length; j++) { int a; if (Char.ToLower(sb[i]) == g[j]) { for (int t = 0; t < alf.Length; t++) { if (alf[t] == A) { a = t + 10; if (a >= alf.Length) { a = a - alf.Length; } sb[i] = System.Char.ToUpper(alf[a]); chec = false; } } } } for (int j = 0; j < st.Length; j++) { int a; if ((System.Char.ToLower(sb[i]) == st[j]) && chec) { for (int t = 0; t < alf.Length; t++) { if (alf[t] == A) { a = t - 10; if (a < 0) { a = alf.Length + a; } sb[i] = alf[a]; } } } } } Console.WriteLine("Зашифрованное предложение:"); Console.WriteLine(sb); string ALF = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"; for (int i = 0; i < sb.Length; i++) { char A = sb[i]; bool chec = true; for (int j = 0; j < ALF.Length; j++) { int a; if (A == ALF[j]) { a = j - 10; if (a < 0) { a = ALF.Length + a; } sb[i] = alf[a]; chec = false; } } for (int j = 0; j < alf.Length; j++) { int a; if ((A == alf[j]) && chec) { a = j + 10; if (a >= alf.Length) { a = a - alf.Length; } sb[i] = alf[a]; } } } sb[0] = System.Char.ToUpper(sb[0]); for (int i = 2; i < sb.Length; i++) { if (sb[i - 2] == '.' | sb[i - 2] == '?' | sb[i - 2] == '!') { sb[i] = System.Char.ToUpper(sb[i]); } } Console.WriteLine("Расшифрованное предложение:"); Console.WriteLine(sb); } public void Ex12(string s) { string k = ""; for (int i = s.Length; i > 0; i--) k += s[i - 1]; Console.WriteLine(k); string q = ""; for (int t = 0; t < s.Length; t++) if (s[t] == ' ') { for (int w = t + 1; w < s.Length; w++) q += s[w]; q += s[t]; for (int w = 0; w < t; w++) q += s[w]; Console.WriteLine(q); } string l = ""; for (int t = 0; t < s.Length; t++) if (s[t] == ' ') { for (int h = t; h > 0; h--) l += s[h - 1]; l += s[t]; for (int j = s.Length; j > t; j--) l += s[j - 1]; Console.WriteLine(l); Console.ReadLine(); } } public void Ex13() { var word = Console.ReadLine().ToUpper().ToCharArray(); var key = Console.ReadLine().ToCharArray(); var result = new Char[word.Length]; for (int i = 0; i < word.Length; i++) { result[i] = (char)((int)word[i] + (int)key[i % key.Length] - 48); } foreach (var letter in result) { Console.Write(letter); } } public static bool IsNumber(string s) { int k = 0; for (int i = 0; i < s.Length; i++) { if ((s[i] == '0') || (s[i] == '1') || (s[i] == '2') || (s[i] == '3') || (s[i] == '4') || (s[i] == '5') || (s[i] == '6') || (s[i] == '7') || (s[i] == '8') || (s[i] == '9')) k++; } if (k == s.Length) return true; return false; } public static bool Cut(ref string s) { if ((s[0] == '+') && (s[1] == '7')) { s = s.Substring(2); return true; } if (s[0] == '8') { s = s.Substring(1); return true; } return false; } public static bool Check1(string s) { if (!Cut(ref s)) return false; if (s.Length != 10) return false; if (!IsNumber(s)) return false; return true; } public static bool Check2(string s) { if (!Cut(ref s)) return false; if (s.Length != 12) return false; if ((s[0] != '(') || (s[4] != ')')) return false; else { s = s.Replace('(', '0'); s = s.Replace(')', '0'); } if (!IsNumber(s)) return false; return true; } public static bool Check3(string s) { if (!Cut(ref s)) return false; if (s.Length != 14) return false; if ((s[0] != ' ') || (s[4] != ' ') || (s[8] != ' ') || (s[11] != ' ')) return false; else { s = s.Replace(' ', '0'); } if (!IsNumber(s)) return false; return true; } public static bool Check4(string s) { if (!Cut(ref s)) return false; if (s.Length != 16) return false; if ((s[0] != ' ') || (s[1] != '(') || (s[5] != ')') || (s[6] != ' ') || (s[10] != ' ') || (s[13] != ' ')) return false; else { s = s.Replace('(', '0'); s = s.Replace(')', '0'); s = s.Replace(' ', '0'); } if (!IsNumber(s)) return false; return true; } public static bool Check5(string s) { if (!Cut(ref s)) return false; if (s.Length != 14) return false; if ((s[0] != '(') || (s[4] != ')') || (s[8] != '-') || (s[11] != '-')) return false; else { s = s.Replace('(', '0'); s = s.Replace(')', '0'); s = s.Replace('-', '0'); } if (!IsNumber(s)) return false; return true; } static void Search(char[] a, string s) { char[] b = new char[a.Length]; int[] c = new int[s.Length]; Array.Copy(a, b, a.Length); int k = 0; for (int i = 0; i < s.Length; i++) { for (int j = 0; j < b.Length; j++) { if (s[i] == b[j]) { b[j] = '1'; c[k] = j + 1; k++; break; } } } if (k == s.Length) { Array.Sort(c); string res = ""; for (int i = 0; i < c.Length; i++) { res = res + c[i] + " "; } Console.WriteLine("могу составить " + res); } else Console.WriteLine("не могу составить"); } public void Ex15() { Random rnd = new Random(); char[] a = new char[30]; for (int i = 0; i < 30; i++) { a[i] = Convert.ToChar(rnd.Next(1072, 1103)); Console.Write(a[i]); } Console.WriteLine(); Search(a, Console.ReadLine()); } public void Ex16(string s) { double a, b; Console.WriteLine("число"); a = Convert.ToDouble(Console.ReadLine()); b = Convert.ToInt32((a * 100) % 100); a = Math.Floor(a); if ((a % 10 == 1) && (a != 11)) { Console.Write("{0:0} руболь ", a); if ((b % 10 == 1) && (b != 11)) Console.WriteLine("{0:0} копейка", b); else if ((a % 10 >= 2) && (b % 10 <= 4) && (b != 12) && (b != 13) && (b != 14)) Console.WriteLine("{0:0} копейки", b); else Console.WriteLine("{0:0} копеек", b); } else if ((a % 10 >= 2) && (a % 10 <= 4) && (a != 12) && (a != 13) && (a != 14)) { Console.Write("{0:0} рубля ", a); if ((b % 10 == 1) && (b != 11)) Console.WriteLine("{0:0} копейка", b); else if ((b % 10 >= 2) && (b % 10 <= 4) && (b != 12) && (b != 13) && (b != 14)) Console.WriteLine("{0:0} копейки", b); else Console.WriteLine("{0:0} копеек", b); } else { Console.Write("{0:0} рублей ", a); if ((b % 10 == 1) && (b != 11)) Console.WriteLine("{0:0} копейка", a); else if ((b % 10 >= 2) && (b % 10 <= 4) && (b != 12) && (b != 13) && (b != 14)) Console.WriteLine("{0:0} копейки", b); else Console.WriteLine("{0:0} копеек", b); } } } } |
See more:
when i run this code, i am getting :
Severity Code Description Project File Line Suppression State Error CS5001 Program does not contain a static 'Main' method suitable for an entry point database C:UsersAdminDesktopVisualStudiodatabasedatabaseCSC 1 Active
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MySql.Data.MySqlClient; using System.Diagnostics; using System.IO; namespace connect { class DBConnect { private MySqlConnection connection; private string server; private string database; private string uid; private string password; public DBConnect() { Initialize(); } private void Initialize() { server = "localhost"; database = "first_db"; uid = "root"; password = ""; string connectionString; connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";"; connection = new MySqlConnection(connectionString); this.display(); } public void display() { int a = -1; a = this.Countrows(); int b = this.Countcolumns(); List<string>[] newlist = new List<string>[b]; newlist = this.Select(); Console.WriteLine("Id" + " " + "username" + " " + "password"); for (int j = 0; j < a; j++) { for (int i = 0; i < b; i++) { Console.Write(newlist[i][j] + " "); } Console.WriteLine(); } } public bool OpenConnection() { try { connection.Open(); Console.WriteLine("connection opened"); return true; } catch (MySqlException ex) { switch (ex.Number) { case 0: Console.WriteLine("Cannot connect to server. Contact administrator"); break; case 1045: Console.WriteLine("Invalid username/password, please try again"); break; } return false; } } public bool CloseConnection() { try { connection.Close(); Console.WriteLine("connection closed"); return true; } catch (MySqlException ex) { Console.WriteLine(ex.Message); return false; } } public void Insert() { string query = "INSERT INTO users (id, username, password) VALUES('23' ,'Jojo', '33') , ('99', 'jen', '66')"; if (this.OpenConnection() == true) { MySqlCommand cmd = new MySqlCommand(query, connection); Console.WriteLine("values inserted"); cmd.ExecuteNonQuery(); this.CloseConnection(); } } public void Update() { string query = "UPDATE users SET username='Joe', password='22', id='33' WHERE username='Joe'"; if (OpenConnection() == true) { MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = query; cmd.Connection = connection; cmd.ExecuteNonQuery(); this.CloseConnection(); } } public void Delete() { string query = "DELETE FROM users WHERE username='Joe'"; if (this.OpenConnection() == true) { MySqlCommand cmd = new MySqlCommand(query, connection); cmd.ExecuteNonQuery(); this.CloseConnection(); } } public List<string>[] Select() { string query = "SELECT * FROM users"; List<string>[] list = new List<string>[3]; list[0] = new List<string>(); list[1] = new List<string>(); list[2] = new List<string>(); if (this.OpenConnection() == true) { MySqlCommand cmd = new MySqlCommand(query, connection); MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { list[0].Add(dataReader["id"] + ""); list[1].Add(dataReader["username"] + ""); list[2].Add(dataReader["password"] + ""); } dataReader.Close(); this.CloseConnection(); return list; } else { return list; } } public int Countrows() { string query = "SELECT Count(*) FROM users"; int Count = -1; if (this.OpenConnection() == true) { MySqlCommand cmd = new MySqlCommand(query, connection); Count = int.Parse(cmd.ExecuteScalar() + ""); this.CloseConnection(); return Count; } else { return Count; } } public int Countcolumns() { string query = "SELECT Count(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'first_db' AND table_name = 'users'"; int Count = -1; if (this.OpenConnection() == true) { MySqlCommand cmd = new MySqlCommand(query, connection); Count = int.Parse(cmd.ExecuteScalar() + ""); this.CloseConnection(); return Count; } else { return Count; } } } }
What I have tried:
This is something , i have no concept of as i am completely new to C#.
This is a class, not an application — and you can’t execute a class on it’s own because the system doesn’t know where to begin.
And executable program needs a specific method to call — it’s called «Main» and it must be a static method:
static void Main(string[] args) { ... }
If that doesn’t exist, you can’t run the code!
The compiler can’t find the Main() method, just as the error message says. This method is the starting point of your program and is required.
If you are new, it may really be a good idea to take the advice from the comment above and look at a tutorial. There you will be shown how to start a new solution and what to do with the Main() method, which is pregenerated by VisualStudio.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
From what little you’ve mentioned, my guess is that you created a
WindowsApplication (.exe) project, not a ClassLibrary (.dll) project.
Have you been working with C# and .NET long?
—
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010
http://www.acadxtabs.com
Email: string.Format(«{0}@{1}.com», «tonyt», «caddzone»);
wrote in message news:6332176@discussion.autodesk.com…
I have a problem getting my program to work in C #.
The source code is an original Autodesk code and I implemented the resource
files acmgd.dll and acdbmgd.dll in my project.
However I always get an Compiler error: CS5001, Program ‘program’ does not
contain a static ‘Main’ method suitable for an entry point.
Since I use CommandMethod() I thought I needn’t the static Main() method.
Can anyone help me with this problem?
kind regards
Edited by: MartinSi on Feb 8, 2010 12:40 PM