I have a problem using System.Device and can't find a solution
I'm developing a software and want to get the position of the device. By referencing the .NET Framework I want to use the GeoCoordinateWatcher.
In my code I included System.Device.Location and added two packages to the project (GeoCoordinate and System.Device.Location.Portable). While running and debugging the code in monodevelop no error occurs, but when I compile the code with mcs the error mentioned in the title occurs:
Namespace name "Device" does not exist in the namespace
Im using a RasPi for coding and compiling.
Any idea what the problem is?
System.Device is not supported by Mono:
https://github.com/mono/mono/tree/master/mcs/class
I wanted to make a use of Mono on Ubuntu 14.04.3 LTS in order to write some client-server app using C# language.
I followed this tutorial and installed everything Mono needs to be compiling and running C# .NET apps on Ubuntu.
Then I installed MonoDevelop 5.9.6 according to this tutorial which was actually installing three packages: monodevelop, l monodevelop-nunit, monodevelop-versioncontrol (I skipped database package as I don't need it for now).
I created simple console application in MonoDevelop and now I am trying to use some code which referencen to System.Net.Sockets (and other) system library class. I added to my project's references the System.Net.dll, which is located under usr/lib/mono/4.5 after Mono installation.
Apparently I cannot compile my app as I get the errors like:
Error CS0234: The type or namespace name `Sockets' does not exist in the namespace `System.Net'. Are you missing an assembly reference? (CS0234) (Communicator.Presentation)
I completely cannot get what is going on here. I've searched through net and forums and cannot find the answer for that issue.
I am also providing the screenshot from my PC with MonoDevelop opened where you can see that System.Net reference is added to the project, but the inside classes are not visible. When I type "System.Net." it only allows me to choose "System.Net.IPEndPointCollection" and nothing else:
EDIT:
What is also weird it that if i double-click on that System.net reference in MonoDevelop in the "Assembly Browser" windows I can see the contents of this "System.net.dll" and especially System.Net.Sockets is present there...:
You don't need System.Net.dll to be included, as you are looking for System.Net.Sockets namespace which exists inside System.dll. So you need to add reference to System.dll. See this link for more details.
So you need following reference:
using System;
I am also attaching my Ubuntu with MonoDevelop snapshots. In these snapshots, you can see that I don't have any reference to System.Net.dll, inside my project references, just System.dll is needed.
Hope this helps.
I have a C# app originally written in Windows that I'm now running in Linux on MonoDevelop. It works fine but now I need to recognise symbolic links. I found this answer but when I add:
using Mono.Unix;
I get the error "The type or namespace name 'Unix' does not exist in the namespace 'Mono'. Are you missing an assembly reference (CS0234)?"
You need to do what the error message says. Unintuitively, Mono.Unix lives in Mono.Posix.dll, so you need to add that as reference.
I have taken over a project that is targeting .net4.
One of the projects within the solution is using System.Runtime.CompilerServices.CallerMemberNameAttribute from the System.Runtime.dll that is installed when you are using the Microsoft BCL Portability Pack.
I have checked and the project is currently using version 1.1.3.
When the solution is build on local dev machines, everything compliles with no problems.
I am now trying to get the solution built in teamcity, but when TeamCity attempts to compile the solution I am getting this error.
error CS0246: The type or namespace name 'CallerMemberName' could not be found (are you missing a using directive or an assembly reference?)
error CS0433: The type 'System.Runtime.CompilerServices.CallerMemberNameAttribute' exists in both 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll' and 'c:\apps\teamcity\buildAgent\work\bb8aacaa9fabeac8\packages\Microsoft.Bcl.1.1.3\lib\net40\System.Runtime.dll'
I have read Jon Skeets answer to this question: Using CallerMemberName attribute in a portable library But I am already using the BCL library.
After spending some time on this, I found another question answered by Jon Skeet that resolved this issue.
When must we use extern alias keyword in C#?
Within my project, after getting the links to the Package, for each dll I had to change the name of the alias. ie from global to newglobal
Then in the classes that where using the CallerMemberName, had to do the following
At the top of the page, above the using statements
extern alias newglobal;
And then when referencing CallerMemberName, enter the code as
[newglobal::System.Runtime.CompilerServices.CallerMemberName]
This allows the code to be successfully built on teamcity where .net 4.5 has been installed.
I am using Snarl C# API to send notifications to snarl.
Now I have saved the content of above url in a file named SnarlNetwork.cs and the content of my test.cs file are:
using SnarlNetworkProtocol;
using System;
class test
{
public static void Main(String[] args)
{
SNP snarl_object = new SNP();
string hostname = "localhost";
string hostport = "9887";
string appName = "Spotify";
bool val = snarl_object.register(hostname, hostport, appName);
if (val == true)
{
string title = "hello";
string message = "world";
string timeout = "5";
bool newval = snarl_object.notify(hostname, hostport, appName, null, title, message, timeout);
if (newval == true)
{
Console.WriteLine("sucessfull");
}
}
}
}
Now when I try to compile my test.cs file using csc test.cs I get the following error:
C:\Users\Noob\csharp>csc test.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.4926
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
test.cs(1,7): error CS0246: The type or namespace name 'SnarlNetworkProtocol' could not be found (are you missing a using directive or an assembly reference?)
So, what am I doing wrong here because according to me I am not missing any using directive.
I was using .NET Framework 4.5 but my new library had .NET Framework 4.5.2 and I got the same issue when I tried to build. I solved it by updating my project from 4.5 to 4.5.2 (same as my library).
On the Solution Explorer tab right click and select Properties
Resolve this issue by updating the Target Framework in the project application settings.
For instance, In my case the project was compiling with .net framework version 4.5.1 but the dll which were referenced were compiled with the version 4.6.1.
So have updated the my project version. I hope it works for you.
This is the problem:
C:\Users\Noob\csharp>csc test.cs
You haven't added a reference to the DLL. You need something like:
C:\Users\Noob\csharp>csc test.cs /r:SnarlNetwork.dll
(or whatever the assembly is called).
Alternatively, if you haven't got it as a separate library, just compile both files:
C:\Users\Noob\csharp>csc test.cs SnarlNetwork.cs
If you haven't compiled an assembly but want to, you can use:
csc /target:library /out:SnarlNetwork.dll SnarlNetwork.cs
csc Test.cs /r:SnarlNetwork.dll
(In fact, specifying the output file is unnecessary in this particular case, but it's still clearer...)
Edit: Oh ignore me, you're not using Visual Studio.
Have you added the reference to your project?
As in this sort of thing:
It might be due to "client profile" of the .NET Framework.
Try to use the "full version" of .NET.
This usually happens to me when I have a using statement but have forgotten to reference the assembly that defines the namespace.
But in your case, as the namespace is defined in a file in your project, you have forgotten to tell the compiler about the snarlnetwork.cs file.
See csc compiler examples
I had this error on a MVC Project. And after a long research i found out that the .cs file containing some of the classes i referenced in the main project had a Build Actions set to "Content" ...
After changing it "Content"->"Compile" the error disappeared.
most of the problems cause by .NET Framework. So just go to project properties and change .Net version same as your reference dll.
Done!!!
Hope it's help :)
I resolved this by making sure my project shared the same .Net Framework version as the projects/libraries it depended on.
It turned out the libraries (projects within the solution) used .Net 4.6.1 and my project was using 4.5.2
i also faced same problem,
Reason: why i faced this error is,
rather then creating new partial view,
i have created class and then renamed its extension from ".cs" to ".cshtml".
Solution:
Just delete that rename view and re-create proper partial/full view. it will work fine after that.
Check your Web.Config and find namespace = . you can remove or if you need it you must create new
I had the same error when used cs file was located inside project folder, but did not referenced from .csproj of parent project.
Intellisence see this file inside project folder, but compiler does not see it because of missing reference in .csproj
I have resolved this problem by adding the reference to System.Web.
I also got this error due to a missing reference.
The reason I did not notice is because Resharper offers to add a using and a reference. Adding the using succeeds (but it's highlighted grey), syntax highlighting of missing classes works (sometimes), but adding the reference fails silently.
When manually adding the reference an error pops up, explaining why adding the reference fails (circular reference). Resharper did not pass this error on to the GUI.
I had the same issue when I clone my project from Git and directly build the solution first time. Instead of that go to the local repository in file explorer and double click the solution file (.sln) solved my issue.
I had a similar problem after first pulling and starting a new solution. It was fixed in visual studio by first cleaning the project. Then restoring the packages. When I built again, there were no more type or namespace errors.
Theoretically, if the the client framework is higher than the library framework client project builds successfully. So I suggest you check the Platform Target to make sure there is no conflicts.
right mouse button project > Properties > Build and uncheck Prefer 32-bit which is available for console project only. And check both projects target the same platform.
[
In my case, just "add refence" and browser the DLL file. it works for me.
I had this issue when I first cloned my project from Git to Visual Studio. I just had to update my NuGet packages, and then I was good to go!
Project > Manage NuGet Packages... >
Then update the packages. It notified me and there was a yellow bar with a button that I pushed and it downloaded the packages!