i can't use Syetem.Data.SqlClient.
this is my code
using System;
using System.Data.SqlClient; // <== error
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
i make this project from console, and input 'dotnet new' and restore.
what shold i do?
Have you added "System.Data.dll" to your project reference?
Add reference for SQL server data from project references. If there is not such option then run the Setup of visual studio select option Modify and then select SQL data option and run the setup.
Related
I am getting an error on my code that says "Error CS5001
Program does not contain a static 'Main' method suitable for an entry point"
I am coding in C# using Microsoft Visual Studio and .NET. This is my code.
using System.IO;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using System;
class projectsummer
{
[CommandMethod("OpenDrawing", CommandFlags.Session)]
public static void OpenDrawing()
{
string strFileName = "C:\\DRAFT.dwg";
DocumentCollection acDocMgr = Application.DocumentManager;
if (File.Exists(strFileName))
{
acDocMgr.Open(strFileName, false);
}
else
{
acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + strFileName +
" does not exist.");
}
}
}
I am not sure how to go about this error. Thank you!
Looking at this post and your previous question, let's try and break down what's going on.
You created a new Console application in Visual Studio. You did not tick "Do not use top level statements". This gave you a Program.cs file that was essentially empty (there was no "Main" method visible).
You erased the Hello World code given to you, and went to make a static method - the code from your previous question.
Damien_The_Unbeliever commented that based on the error, you put your method inside a "top level statement" file, and to put your method inside a class.
You wrap your method (which is still inside Program.cs) in a class, and now suddenly you get a Can't Find Entry Point error.
User Ryan Pattillo posted a great explanation of the original issue - where your method was "by itself" in the Program.cs file. You should follow their advice, but you should also ensure that this class is in its own file.
You should end up with this:
Program.cs
// this is the entire contents of the file
using ConsoleApp1;
ProjectSummer.OpenDrawing();
ProjectSummer.cs
using System.IO;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using System;
namespace ConsoleApp1
{
public class ProjectSummer
{
[CommandMethod("OpenDrawing", CommandFlags.Session)]
public static void OpenDrawing()
{
// ...
}
}
}
Change ConsoleApp1 to the name of your project.
The entry point of your application, which right now is the only file that has "top level statements", remains Program.cs, thus you fix the Can't Find Entry Point error.
Another adjustment you can make, which seeing you're new to C# might be useful, is to not use top level statements at all. Modify your Program.cs to this:
namespace ConsoleApp1
{
internal static class Program
{
// this is your program's entry point
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
ProjectSummer.OpenDrawing();
}
}
}
Change ConsoleApp1 to the name of your project.
You cannot use the AutoCAD .NET API out of process. To be able to use the AutoCAD .NET libraries, you have to build a "class library" project (DLL) and NETLOAD this DLL from a running AutoCAD process. See this topic about in-process vs out-of-process and you can start from this other one to see how to create an AutoCAD .NET project.
I'm trying to establish connection to Azure DataExplorer cluster using C# ..
I referenced the C# in https://learn.microsoft.com/en-us/azure/kusto/api/netfx/about-kusto-data
and installed nuget package kusto.data in visual studio and copied the code and did dotnet run in cmd prompt, but it didn't work.
Below is my code-
using Microsoft.Azure.Management.Kusto;
using System;
namespace LensDashboradOptimization
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
//var clusterUrl = "https://masvaas.kusto.windows.net";
//var kcsb = new Kusto.Data.KustoConnectionStringBuilder(clusterUrl);
//Console.WriteLine(kcsb);
// Read the first row from reader -- it's 0'th column is the count of records in MyTable
// Don't forget to dispose of reader when done.
var client = Kusto.Data.Net.Client.KustoClientFactory.CreateCslQueryProvider("https://masvaas.windows.net/Samples;Fed=true");
var reader = client.ExecuteQuery("MyTable | count");
Console.WriteLine(reader);
}
}
}
I tried both fed=true and WithAadUserPromptAuthentication(); both didn't work. Am I missing something?
Hello and welcome to Stack Overflow!
I tried and faced a similar error when I was checking this out. But the issue turned out to be with the version of .Net Framework that I was running. The Kusto.Data package requires .Net Framework 4.6.2 as a dependency. When I had that installed, I was able to install and import the package, and also subsequently connect to the intended Kusto cluster and read data. This is the snippet that worked for me:
using System;
using Kusto.Data;
namespace hello_world
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var client = Kusto.Data.Net.Client.KustoClientFactory.CreateCslQueryProvider("https://help.kusto.windows.net/Samples;Fed=true");
var reader = client.ExecuteQuery("StormEvents | sort by StartTime desc | take 10");
}
}
}
Please double check on the dependencies and let me know if you still run into issues. Hope this helps!
using Kusto.Data;
using Kusto.Data.Common;
using Kusto.Data.Net.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Only these using statement do the job that you are trying to. For that all you need to install SDK from nuget gallery .
Also, only install Microsoft.Azure.Kusto.Data and Microsoft.Azure.Management.Kusto from above. That is sufficient.
Hope this help.
Few more things you can look on as: 1) Static IP 2)VS 2019 community edition with Azure dev packages installed
WithAadUserPromptAuthentication, this method is not supported now as kusto database first need authentication for the user. and the console application is not able to open a prompt window. I recommend to use a web application.
I want to use SikuliIntegrator in C#.
I run VS as administrator, install SikuliIntegrator throught NuGet manager and want to test him on simple task.
Heres my code
using SikuliModule;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SikuliTrainingNet
{
class Program
{
static void Main(string[] args)
{
string MyPicture = #"c:\111\Sik\MyPicture.png";
SikuliAction.Click(MyPicture);
}
}
}
after running code (and have prepared MyPicture on screen), all i get is exception "###FAILURE" any idea why?
I dont wanna use Sikuli4Net, becose its look like it work on web aps and I need just few simple clicks on desktop aplication.
I try sikuli in Java, and there it works with no problem. But I need to make my program in C#.
I Used This Code For Sikuli4Net in C#,It Was Working For Me First You need add the References please see this link for Reference
http://interviews.ga/angularjs/sikulic/
static void Main(string[] args)
{
APILauncher launch = new APILauncher(true);
Pattern image1 = new Pattern(#"C:\Users\Ramesh\Desktop\Images\userName.png");
Pattern image2 = new Pattern(#"C:\Users\Ramesh\Desktop\Images\password.png");
Pattern image3 = new Pattern(#"C:\Users\Ramesh\Desktop\Images\Login.png");
launch.Start();
IWebDriver driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Url = "http://gmail.com";
Screen scr = new Screen();
scr.Type(image1, "abc#gmail.com", KeyModifier.NONE);
scr.Type(image2, "12345", KeyModifier.NONE);
scr.Click(image3, true);
Console.ReadLine();
}
I used this code and it was working fine. First you should open the webpage on which you want to click and then give a path of the image(it should be a part of the webpage)
here is my code:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SikuliModule;
using OpenQA.Selenium;
namespace WordPressAutomation.DifferentTests
{
[TestClass]
public class Sikuli
{
[TestMethod]
public void TestMethod1()
{
driver.Initialize();
driver.instance.Navigate().GoToUrl("https://www.google.co.in");
SikuliAction.Click("E:/img.png");
}
}
}
To use SikuliInyegrator, you need to check the execution results in these files:
C:\SikuliExceptionLog.txt
C:\SikuliOutputLog.txt
Also you need to:
Have installed JRE7 or superior
Have environment variable PATH with the location of the bin folder
See installed in your “control panel > program and features> visual C++ 2010 Redistributable Package” at x86 and x64 bits according to your java JRE runtime platform. If not, then download and install the Redistributable Package form Microsoft site.
I have spent a good while trying to get this simple code to read from the command line:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
if(args.Length > 0)
{
for (int i = 0; i < args.Length; ++i)
System.Console.WriteLine(args[i]);
}
else System.Console.WriteLine("NO COMMAND INPUT DETECTED");
System.Console.ReadLine();
}
}
}
When typing the command:
ConsoleApplication3.application "pleasework"
I get the following message in the command line:
NO COMMAND INPUT DETECTED
indicating that the command line is not working properly. Any thoughts? I am very bad with Visual Studio (this is 2012) so I imagine there is some special property I need to change or something ridiculous.
Thanks!
Using this:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(args.Length);
Console.Read();
}
}
}
I was able to go to my command prompt and run:
C:\ProjectPath\ConsoleApplication1\bin\debug\ConsoleApplivation1.exe "Test" "Test2"
With a result of:
2
Edit: It looks like you are running a ClickOnce Console Application. This complicates what you want to do, but it isn't impossible. Here are several resources that discuss this particular issue:
Processing Command Line Arguments in an Offline ClickOnce Application
Harvesting ClickOnce Command Line Arguments
How to pass arguments to an offline ClickOnce application
Your code seems to be okay.
You're probably not passing the argument properly.
Take the following steps:
Right-Click on your Project => Properties => Debug => insert "Pleasework" into the command line arguments => save and debug your code step-by-step.
And you'll see:
I just open a new C# project , but when i want to compile it i give the title error . i search for this error but didn't find any result .
what am i going to do ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello world!");
}
}
}
Try cleaning the project.
Make sure that the startup item isn't set
to a non-existant ConsoleApplication1.
Whatever the main form of
your project is, right click on it in Solution Explorer and select
"Set as Start Up...".
Make sure that the Program.cs (or Program.vb)
file is not attempting to load ConsoleApplication1.