In the following code:
for (int line = 0; line < CHUNKSTOBEFOUND; line++) {
nvc.Add ("search", System.Web.HttpUtility.UrlEncode (stringsToSearchFor[line]));
}
I get told namespace name HttpUtility does not exist.
http://msdn.microsoft.com/en-us/library/system.web.httputility.aspx seems to indicate I should use System.Web. I've tried using that, but I STILL get the error. Is there something else I'm supposed to include or use?
As competent_said, you are probably targeting the Client Profile in your project, in which System.Web.dll is not available. You can target the full framework in Project Properties to get it back working.
Another possible cause could be that you are not referencing System.Web library. To do so:
Right click the "Reference" in the Solution Explorer.
Choose "Add Reference"
Check the ".NET" tab is selected.
Search for, and add "System.Web".
Maybe you are just missing an using directive using System.Web; on the top of your source file.
You are most likely using the Client Profile version of the .Net framework. You need to open your project properties and change the framework version to the full version.
Related
I have received a .dll file from a partner firm with an API that will be used for database logging. I have added it to the references and can see it in the Solution Explorer. The documentation provided gave me a code snippet which references the file with a different namespace than the file name. I am using Visual Studio 2013 Express.
using com.XXXXX.XXX.microsites.api;
When I want to use the EntityFramework, it is simply the name of the reference.
using Microsoft.AspNet.Identity.EntityFramework;
The reference is not even showing up with a different name when using IntelliSense.
I am using the recommend framework ASP.NET 4 in the documentation.
I am using the code snippet they provided.
I would personally use dotPeek (https://www.jetbrains.com/decompiler/) to decompile the assembly and see what the defined namespaces are. Not sure if there's anything build in to Visual Studio.
If you added the dll reference in your solution then try opening the dll in object browser and see if you see the namespaces listed there and then use the one needed.
I have been trying to include DirectX in C sharp project (Visual Studio 2010).
I installed DirectX SDK and included the components as:
using Microsoft.DirectX;
using Microsoft.DirextX.Direct3D;
When I try to compile, I get the error: the type or namespace name 'directx' does not exist in the namespace 'microsoft'
Some blogs mentioned that I need to add 'reference' - Microsoft.DirectX under '.NET' tab. But I couldn't find it over there. Neither was any facility to add it to the tab.
Any suggestion will be highly appreciated.
This was deprecated a long time ago. The last Direct SDK that still has the managed wrappers is February 2010. The download is available here. You'll get to pick the references you are looking for after you install that one.
Better not to use it, no future, look at something like the open source SlimDX or SharpDX projects.
There are various reasons why a dll would not appear on the .Net tab.There is specific registry configuration that makes certain dlls to appear on the .Net tab.
Alternatively use the browse option to add the dll reference manually to your project.
Project >> Add Reference
This is the way to add reference for Directx in C# Program :
Go to the solution explorer
Click references
Click add reference
Click Browse
Go to : "C:\WINDOWS\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\"
*usually this is the place of Directx Files located. This can be change with the installation of .net.
Select your DirectX package.
example :
(C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.dll)
Here is one way i have find. First you need to install DXSDK (i have June2010 and SDK for Windows 7). Go to "Add refference" dialog press "Browse" , go to something like this "C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0" or "C:\Windows\Microsoft.NET\Managed DirectX\v9.02.2904" then choose proper dll for example - Microsoft.DirectX.dll. So you can add "using Microsoft.DirectX" directive to your project.
I'm trying to use DataAnnotations in my WPF project to specify a maximum length of strings, with the following:
using System.ComponentModel.DataAnnotations;
However, I get the error
The type or namespace name 'DataAnnotations' does not exist in the
namespace 'System.ComponentModel' (are you missing an assembly
reference?)
I've seen other examples where DataAnnotations does exist in this namespace. I'm using C#4. Is there any reason why I can't use this? What can I do to fix it?
You have to reference the assembly in which this namespace is defined (it is not referenced by default in the visual studio templates). Open your reference manager and add a reference to the System.ComponentModel.DataAnnotations assembly (Solution explorer -> Add reference -> Select .Net tab -> select System.ComponentModel.DataAnnotations from the list)
If using .NET Core or .NET Standard
use:
Manage NuGet Packages..
instead of:
Add Reference...
To Reference System.ComponentModel.DataAnnotations
In a code file to have Using System.ComponentModel.DataAnnotations; at the top of the file such as:
using System.ComponentModel.DataAnnotations;
Add a .NET reference to your project by right clicking the project in solution explorer:
Hope this helps! This question helped me.
If you don't have it in references (like I did not) you can also add the NuGet System.ComponentModel.Annotations to get the assemblies and resolve the errors. (Adding it here as this answer still top of Google for the error)
I also had the same problem and I resolved by adding the reference in one of my projects which didn't had the mentioned reference. If you have 2-3 projects in your solution, then check by adding this reference to the other projects.
I found that I cannot reference System.ComponentModel.DataAnnotations from Silverlight 5 with the below version at (1). I found that Silverlight 5 assemblies cannot use .NET assemblies, it gives the error "You can't add a reference to System.ComponentModel.DataAnnotations as it was not built against the Silverlight runtime. ..." I plan to workaround this by hopefully installing the Silverlight 5 package found at (2) below. If this fails I will update this post.
[UPDATE: it failed. I installed everything relating to Silverlight 5 and I don't have the Silverlight version of the .dll assembly System.ComponentModel.DataAnnotations . Too bad. UPDATE II: I found an old .dll having this name from a previous installation of Silverlight developer's kit for Visual Studio 2008 or 2010. I added this file and it seems to 'work', in that IntelliSense is now recognizing attributes on class members, such as [Display(Name = "My Property Name")]. Whether or not this works for everything else in this .dll I don't know.]
(1)
Microsoft Visual Studio Professional 2013
Version 12.0.21005.1 REL
Microsoft .NET Framework
Version 4.5.51641
Installed Version: Professional
(2)
http://go.microsoft.com/fwlink/?LinkId=229318
I searched for help on this topic as I came across the same issue.
Although the following may not be the Answer to the question asked originally in 2012 it may be a solution for those who come across this thread.
A way to solve this is to check where your project is within the solution. It turns out for my instance (I was trying to install a NuGet package but it wouldn't and the listed error came up) that my project file was not included within the solution directory although showing in the solution explorer. I deleted the project from the directory out of scope and re-added the project but this time within the correct location.
Use the FrameWork version 4.5 and above for your project then problem solved.Because this namespace is under 4.5 and above.
System.ComponentModel.DataAnnotations is contained in its own assembly so you need to make sure you have it refernced. Just simply:
1). Right click on Soloution and choose add.
2). Choose reference from the list.
3). Search " System.ComponentModel.DataAnnotation " and tick the check box on its left hand side and press ok.
Job done, shouldnt have any refernce errors.
If you tried to update visual studio from vs2008 to vs2010. And your app uses framework 3.5 (and you don't want to upgrade it), and also used WCF RIA Services BETA... I have bad news... you MUST upgrade to WCF RIA Services v1 (BETA does not work on vs2010)... and due to this... you also have to install Silverlight 4 + upgrade to framework 4.0
See this:
http://blog.nappisite.com/2010/05/updating-visual-studio-2008net-35-ria.html
I upgraded from Silverlight 4 to Silverlight 5 and then I was having this issue. Although I had a reference to "System.ComponentModel.DataAnnotations" under "References" in my project, it had a yellow yield sign by it that indicated the previously referenced assembly could not be found. It turned out that the properties of the "System.ComponentModel.DataAnnotations" reference indicated "Specific Version = True", when I changed this to "Specific Version = False" it fixed the issue. Right click on the "System.ComponentModel.DataAnnotations" assembly under "References" and select "Properties" from the context menu. Check that the property value for "Specific Version = False".
It must have been referencing the old Silverlight 4 assembly which was no longer available after the upgrade to Silverlight 5.
I also have this problem.
That is very stupid when i add a namespace the same with System. I try to remove all references, but it is not resolved. I use "global::System.ComponentModel", it is working as well.
When i remove my namespace, this problem has been resolved.
For .Net Core in Visual Studio 2019 try this.
see VS suggestion
It worked for me, hope it'll work for you as well.
I was moving from .Net Framework 4.7.2 to .Net Standard 2.0.
In my case, I had to change DataAnnotations's reference from an Assembly reference to a Nuget package.
This error occurs when the reference to the "System.dll" got removed.Solution to the problem is very simple add the reference to "System.dll".The dll is normally available in the following location
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727" .Add the reference your problem will get solved .
There was a problem using System.ComponentModel.DataAnnotation in net40 so I just did:
#if !NET40
using System.ComponentModel.DataAnnotations;
#endif
#if !NET40
[StringLength(256)]
#endif
The NET40 must be a predefined macro definition for .Net Framework 4.0
I had same problem, I solved this problem by following way.
Right click on page, select Property. in build action select Content.
Hope that this solution may help you.
Why might "using System.Linq" cause the following error?
The type or namespace name 'Linq' does
not exist in the namespace 'System'
Reference System.Core
And then there are others that merge this namespace too - but that's the primary one on .Net 3.5 and above.
If you're project is currently .Net 2.0, say, and you're using the right version of VS (2005 and above) - you can simply right-click on the proejct properties; and change the 'Target Framework Version' to 3.5. System.Core will then become available.
If you don't see that in the options - then I guess you're using an older VS
The most probable reason is that you are using wrong version of .NET Framework.
Try to add System.Core assembly to your project
You'll get this error if you don't have "System.Core.dll" referenced (the assembly which contains the core LINQ APIs).
System.Linq is available in .Net 3.5 and above version.
Maybe you're targeting an older framework, Linq came in with 3.5 IIRC.
You are using lower version of .NET Framework than 3.5 to compile the source code or you don't have added the System.Core assembly to your project.
Manually type using System.Linq in the starting of the project, you will not be able to find this namespace in add reference dialogue box.
If you are still getting error then try to Add Reference System.Core.
If you are getting an error that it has been already referred then you can unload your project and then edit your csproject file, manually copy reference to System tag and paste and change the name to System.Core and reload the project.
In my case the only thing that worked was:
Adding a new Razor item (e.g. MVC 5 View Page)
That automatically pulls in some NuGet packages
The package that makes System.Linq available to Razor Views IntelliSense seems to be Microsoft.AspNet.WebPages.
In a different question (How to split a number into individual digits?), they call the Select method on a string. This site also suggests that it is possible.
However, when I try to do this using the code samples found in either of those places, I get a compile error. What could be causing this, and how can I use the Select method on a string?
This is a LINQ method.
To use it, you need to be using .Net 3.5 or later, have referenced System.Core.dll, and have using System.Linq.
Are you sure you have included the System.Linq reference?
using System.Linq;
Just Add a reference system.core.dll
1.In Solution Explorer, right-click on the project node and click Add Reference.
2.In the Add Reference dialog box, select the tab indicating the type of component you want to reference.
3.On .NET tab Select System.Core, then click OK.
And add using System.Linq on what the example you provided;
and make sure that youre project framework is 3.5 because it will not work on lower versions.
Regards