I am using System.Device.Location in .Net.
It works well in my Windows system but when I use the same code in my MacBook version of visual studio, it's not compiling:
The type or namespace name 'Device' does not exist in the namespace 'System' (are you missing an assembly reference?) (CS0234)
Here is my code:
using Toonbank.Vendor.Entity.DashBoard;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Device.Location;
namespace Toonbank.Vendor.Bal
{
public class CalculateDistance
{
public double CalculateDistanceBetweenTwoPoints(CalculateDistanceClass obj)
{
//double latA = -31.997976f;
// double longA = 115.762877f;
// double latB = -31.99212f;
// double longB = 115.763228f;
var locA = new GeoCoordinate(obj.lat1, obj.lon1);
var locB = new GeoCoordinate(obj.lat2, obj.lon2);
double distance = locA.GetDistanceTo(locB); // me
double distanceToKm = distance / 1000;
return distanceToKm;
}
}
}
System.Device is not an installed package built into the framework, it's a public package on Nuget you can reference at will. This is important because different systems have a different "device" inputs and outputs, like GPIO on a Raspberry Pi.
You seem to want the System.Device.Location.Portable package.
Related
I’m running Visual Studio 2015 and Windows 8.1. I am struggling with a console application project.
The solution works fine in Visual Studio 2015, but when I try to compile it with mcs-compiler I get two errors (Kattis codetest use mcs-kompiler). Two external classes can not be found.
I'm getting the following error:
Program.cs(28,13): error CS0246: The type or namespace name Graph'
could not be found. Are you missing an assembly reference?
Program.cs(58,34): error CS0246: The type or namespace nameSolver'
could not b e found. Are you missing an assembly reference?
Compilation failed: 2 error(s), 0 warnings
The code is large so a I have pasted in just parts of it:
The Program class, where main is and the calls to ”Graph” and ”Solver” are made from:
Call in Program.cs:
-----------------------------------------------------------------------------
// first call:
var edges = CliquesToEdges(cliques);
sudokuColour.Graph graph = new Graph(81, edges);
string line = "";
string storeLine = "";
string puzzle = "";
.
.
.
// second call:
for (int i = 0; i < store.Count(); i++)
{
puzzle = store.ElementAt(i);
sudokuColour.Solver solver = new Solver(graph, 9);
int node = -1;
foreach (char c in puzzle)
{
----------------------------------------------------------------------------
//Beginning of "Graph" class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using sudokuColour;
namespace sudokuColour
{
public class Graph
{
.
.
----------------------------------------------------------------------------
//Beginning of "Solver" class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using sudokuColour;
namespace sudokuColour
{
public class Solver
{
private enum Result { Solved, Unsolved, Busted }
private readonly Graph graph;
----------------------------------------------------------------------------
What can the error be?
sudokuColour.Solver solver = new Solver(graph, 9);
The fact that you had to namespace-qualify it on the left probably means you should namespace-qualify it on the right too:
sudokuColour.Solver solver = new sudokuColour.Solver(graph, 9);
Alternatively, add a using directive at the top of the code file:
using sudokuColour;
or:
using Solver = sudokuColour.Solver;
likewise for:
sudokuColour.Graph graph = new Graph(81, edges);
If that still doesn't work: you're probably missing a project reference (or package reference, or assembly reference - but a project reference seems the most appropriate) between the two projects.
I am new in C#, and I have spent the entire night just trying to compile my code. I am not asking for a logic, but rather some help with compiling using csc.
I have an app that uses System.Net.Http, and I am trying to get it compiled into an executable using csc, but I always get the following result:
C:\Users\farao\Documents\Visual Studio 2017\source\repos\SimpleWebCrawlerApp\SimpleWebCrawlerApp>csc Program.cs
Microsoft (R) Visual C# Compiler version 2.6.0.62329 (5429b35d)
Copyright (C) Microsoft Corporation. All rights reserved.
Program.cs(4,18): error CS0234: The type or namespace name 'Http' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)
C:\Users\farao\Documents\Visual Studio 2017\source\repos\SimpleWebCrawlerApp\SimpleWebCrawlerApp>
However, I can compile in Visual Studio 2017, but I do need to compile it using csc for quick distribution.
I tried almost everything from this link
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Collections;
using System.Text.RegularExpressions;
namespace SimpleWebCrawlerApp
{
class Program
{
internal static int SUCCESS = 0;
internal static int FAIL = -1;
static void Main(string[] args)
{
TextWriter errorWriter = Console.Error;
if (args.Length != 2)
{
errorWriter.WriteLine("usage: <program_name>.exe <http/https url> <number of hops>");
}
else
{
if (IsValidUrl(args[0]))
{
int hops;
if (int.TryParse(args[1], out hops))
{
new HTTPCrawler(args[0], hops).Crawl();
Environment.Exit(SUCCESS);
}
errorWriter.WriteLine("not a valid integer for number of hops");
}
else
{
errorWriter.WriteLine("observe proper http/https protocol");
}
}
Environment.Exit(FAIL);
}
I solved my problem thanks to UnholySheep.
csc /r:System.Net.Http.dll Program.cs
References:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/reference-compiler-option
https://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.118).aspx
I'm trying to write a program that sorts images in specific folder by ther dimensions and moves little images to another folder via simple .NET console application. I decided to use System.Drawing.Image class to get the image dimentions from an image file. But I face following error:
The type or namespace name 'Image' could not be found (are you missing
a using directive or an assembly referrence?)
What exactly did I do wrong and why it doesn't see this class?
Here are the complete code of my program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Drawing;
namespace ImageSort
{
class Program
{
static void Main(string[] args)
{
string targetPath = #"d:\SmallImages";
string[] files = Directory.GetFiles(#"d:\Images");
foreach (string path in files)
{
if (File.Exists(path))
{
Image newImage = Image.FromFile(path);
var Width = (int)(newImage.Width);
var Height = (int)(newImage.Height);
if (Width * Height < 660000) {
System.IO.File.Move(path, targetPath);
}
}
}
}
}
}
You need to add a reference : System.Drawing.dll.
In Solution Explorer, right-click on the References node and choose Add Reference and find System.Drawing.dll.
The answer to this issue for .NET Core 3.1 is to simply install System.Drawing.Common from NuGet.
I'm attempting to grab a device handle on the Synaptics Touchpad using the Synaptics SDK, specifically using methods in the SYNCTRLLib.
However, the SYNCTRL method failed to find it, returning -1.
Syn.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SYNCOMLib;
using SYNCTRLLib;
namespace TP_Test1
{
class Syn
{
SynAPICtrl SynTP_API = new SynAPICtrl();
SynDeviceCtrl SynTP_Dev = new SynDeviceCtrl();
SynPacketCtrl SynTP_Pack = new SynPacketCtrl();
int DeviceHandle;
//Constructor
public Syn ()
{
SynTP_API.Initialize();
SynTP_API.Activate();
//DeviceHandle == -1 ? Can't find device?
DeviceHandle = SynTP_API.FindDevice(new SynConnectionType(), new SynDeviceType(), 0);
//Below line causing Unhandled Exception
SynTP_Dev.Select(DeviceHandle);
SynTP_Dev.Activate();
SynTP_Dev.OnPacket += SynTP_Dev_OnPacket;
}
public void SynTP_Dev_OnPacket()
{
Console.WriteLine(SynTP_Pack.FingerState);
Console.WriteLine(SynTP_Pack.X);
Console.WriteLine(SynTP_Pack.Y);
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SYNCOMLib;
using SYNCTRLLib;
namespace TP_Test1
{
class Program
{
static void Main(string[] args)
{
Syn mySyn = new Syn();
mySyn.SynTP_Dev_OnPacket();
}
}
}
I see that you are using the C# wrappers for Synaptics SDK. Even though CPP code might be not trivial to you, you might want to take a look at the file Samples/ComTest.cpp. It contains some example logic in order to find devices, more specifically at lines 66-76:
// Find a device, preferentially a TouchPad or Styk.
ISynDevice *pDevice = 0;
long lHandle = -1;
if ((pAPI->FindDevice(SE_ConnectionAny, SE_DeviceTouchPad, &lHandle) &&
pAPI->FindDevice(SE_ConnectionAny, SE_DeviceStyk, &lHandle) &&
pAPI->FindDevice(SE_ConnectionAny, SE_DeviceAny, &lHandle)) ||
pAPI->CreateDevice(lHandle, &pDevice))
{
printf("Unable to find a Synaptics Device.\n");
exit(-1);
}
Also, make sure you have registered the dlls. According to the ReadSynSDK.txt file:
For certain purposes it may be necessary to register the dlls
that are provided with the SDK. This can be done with the windows regsvr32
utility.
I'm new to C# and I'm new to Speech.Recognition.
I searched very long for tutorials but didn't find that much, I'm even not quiet sure whether I included everything correctly.
I downloaded:
SDK
Runtime
Languages
I'm programming local, I have Windows XP, .net framework 3.5.
Now I just want to get started with some simple lines of code, like to say "hello world" or say one or two words as input.
I tried following, and of course it doesn't work :>
error:
"The Typ- or Namespacename "SpeechSynthesizer" couldn't be found (Is a Using-Direktive or a Assemblyverweis missing?)"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SpeechSynthesizer foo = new SpeechSynthesizer();
foo.Speak("Test");
}
}
}
edit:
hello,
i tried you code,but
using SpeechLib;
couldn't be found :>
well now i wrote:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.SpeechLib;
namespace System.SpeechLib { }
namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }
but I get an error with:
numericUpDown1,SpVoice,SpeechVoiceSpeakFlags,textBox1 and Timeout
Project + Add Reference, .NET tab, select "System.Speech".
A project template pre-selects several .NET assemblies. But only common ones, like System.dll, System.Core.dll, etcetera. You have to add the 'unusual' ones yourself.
you can try this:
get Interop.SpeechLib.dll
using SpeechLib;
private void ReadText(string readText)
{
int iCounter = 0;
while (Convert.ToInt32(numericUpDown1.Value) > iCounter)
{
SpVoice spVoice = new SpVoice();
spVoice.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
spVoice.WaitUntilDone(Timeout.Infinite);
iCounter = iCounter + 1;
}
}