c# namespace name cannot be found - c#

I am trying to make an asynchronous client for Windows Phone using this code http://msdn.microsoft.com/en-us/library/bew39x2a.aspx in Visual Studio 2010 but I get 22 errors for using things like IPHostEntry and BeginConnect although I copied the code exactly. Any ideas?
Thanks
Edit
The three different types of errors I'm getting are below. most of them are the third one with sockets.socket
Error 1 The type or namespace name 'IPHostEntry' could not be found (are you missing a using directive or an assembly reference?)
Error 2 The name 'Dns' does not exist in the current context
Error 3 System.Net.Sockets.Socket' does not contain a definition for 'BeginConnect' and no extension method 'BeginConnect' accepting a first argument of type 'System.Net.Sockets.Socket' could be found (are you missing a using directive or an assembly reference?)

You may be missing a reference. Verify that the appropriate DLLs have been identified as project references.

You should check to see if your project is using the correct version of .Net. In .net 4.0 there is both a "client" and "full" version. Typically when you create a new .Net project in Visual Studio the project is created and referencing the "client profile" .net. Honestly, this gets me every time.
You can change this by doing the following (Visual Studio 2010):
Right click the project in Visual Studio Solution Explorer and select "Properties"
Make sure the "Application" tab is selected
View / Change the "Target Framework:" from ".NET Framework _ Client Profile" to ".NET Framework _"
rebuild your project :-)
Here's a good link explaining the difference between the client profile and the full profile: Differences between Microsoft .NET 4.0 full Framework and Client Profile

The code is missing a namespace before it is declaring classes.
namespace YourNamespace
{
// State object for receiving data from remote device.
public class StateObject { ...
Also you may be missing namespaces for stuff the code is using. Click on the classes that are highlighted with red squigglies and press ctrl + . and it should give suggestions for namespaces.

I encountered the same issue today. I think it's because VS2010 Express WP created my project using 2.0 .NET framework, I don't know why, I want to use 7.8, but I have only choice between 7.0 and 7.1. I can't change .Net framework version for use the 4.0/4.5, I have only one choice and it's windows phone 7.1, I can't choose the version of the framework separately...

Related

IntelliSense complains about missing Microsoft.AspNetCore packages despite being there

In my Blazor application, on the client side, IntelliSense complains about a lot of Microsoft.AspNetCore packages although the project compiles and runs fine.
I get a lot of things like
The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?)
The type or namespace name 'Razor' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?)
...
Things like
#inject HttpClient Http
are also underlined with red squigglies.
The project builds and runs perfectly.
What is wrong here?
Followup 1
Because I was asked for all versions:
Visual Studio 2019, 16.0.2
Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview4-19216-03
In my project:
Id Versions ProjectName
-- -------- -----------
Microsoft.AspNetCore.Blazor.Build {3.0.0-preview4-19216-03} MyBlazorApp.Client
Microsoft.AspNetCore.Blazor {3.0.0-preview4-19216-03} MyBlazorApp.Client
NETStandard.Library {2.0.3} MyBlazorApp.Client
You need Visual Studio Preview version 16.1 or higher to work with 3.0.0-preview4 Blazor.
If that alone doesn't help, verify that you dont have any .cshtml files in your client project - they all have a .razor extension since 3.0.0-preview4. The presence of .cshtml file triggers a different SDK's behavior, requiring AspNetCore.Mvc namespace. Though Microsoft guys see it as a bug and probably will fix it.
https://github.com/aspnet/AspNetCore/issues/9640
Shut down VS
Delete the .vs folder or the .suo file
Restart VS
uninstalling x86 version of .NET Core 3.0 Preview SDK
https://dotnet.microsoft.com/download/dotnet-core/3.0
Then installing the x64 again on Windows10 64bit fixed that issue for me

.NET Code setup in Visual studio 2010

I am new to .NET development and I am setting up a project in Visual studio 2010 with DevExpress 12.2.6 version.
When I build the project, I get this error:
Error 25 'DevExpress.XtraRichEdit.FieldOptions' does not contain a definition for 'UseCurrentCultureDateTimeFormat' and no extension method 'UseCurrentCultureDateTimeFormat' accepting a first argument of type 'DevExpress.XtraRichEdit.FieldOptions' could be found (are you missing a using directive or an assembly reference?) C:\Users\Development\Support\SecurityMasterMonitor\SuppWikiSearchProcessInfoForm.Designer.cs 145 50 SecurityMasterMonitor
I have added DevExpress.XtraRichEdit.dll in my project refernece as well. I am not sure what is missing here.. Can you please help me?
From DevExpress support forum concerning version 2012 vol 2.7 (i.e. 12.2.7)
The DevExpress.XtraRichEdit.FieldOptions.UseCurrentCultureDateTimeFormat property is implemented. It is accessible using RichEditControl.Options.Fields.UseCurrentCultureDateTimeFormat notation.
So, as you can see - you need either upgrade to 12.2.7 or don't use UseCurrentCultureDateTimeFormat in your code since it was implemented in version 12.2.7.

Why am I getting error CS0246: The type or namespace name could not be found?

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!

nettiers data class library not recognized

I needed to make a console application using nettiers class libraries. I created a new Console Application project, added references to all the libraries from NetTiers and created an app.config file with all the necessary configurations. I get intellisense and no errors and everything when I am doing the coding, but when I go to compile the application, I'm getting an error that PPGEDI.Data doesn't exist.
I only have 1 line in the program.cs Main method:
PPGEDI.Entities.VansEntity van
= DataRepository.VansEntityProvider.GetById(16);
I'm getting the following error:
Error 93
The type or namespace name 'Data'
does not exist in the namespace 'PPGEDI'
(are you missing an assembly reference?)
It's frustrating, because I know I've added the assembly reference:
I'm using Visual Studio 2010, with C# and .NET 4.0. Can anyone give me an idea as to what I need to do to get this to work.
As a note, this works if I use the same statement in a method on an ASPX page in the web application generated by nettiers.
#BrokenGlass, you were absolutely correct. I double checked and it was
set to ".NET Framework Client Profile", I changed it to .NET 4 and
it's working now, can you put that as an answer?
You are using the .NET client profile in your console app which is a "minified" version that doesn’t contain all assemblies.
The problem is that when your app adds a reference to a class library that is targeting the full framework, references to the "full" framework assembly will not resolve. This results in the rather non-forthcoming error message that you see. Switching to the the full .NET 4 as target framework will resolve the issue.
For a more in depth overview of the problem and the .NET 4 Client Profile in general also see "What’s new in .NET Framework 4 Client Profile RTM"

VS2010 Reference Resolves in Windows Application but not in Class Library

I have a class library project that references another class library. The project fails to build and I get the error 'The type or namespace name 'ReportLibrary' does not exist in the namespace 'MSF' (are you missing an assembly reference?)'
The weird part is that I have other projects referencing the same class library that build fine. The only difference is that they are Windows Application projects. If I change the project type to a Windows Application and add a Program.cs with a [STAThread] and it builds.
So WTF? Anybody know what I'm doing wrong?
Edit (More Details): All projects in the solution are set to the same Target Framework: .NET Framework 3.5
EDIT (Unobfuscated the error message per Hans)
Is the class library (with the error) targeting the Client Profile, and the applications (as well as the reference library) targeting the full framework? If so, this could cause the reference to be invalid, and cause that message.

Categories