I used code from here and I get the following error:
Can't use HttpContext.Current.Server.MapPath()
In Visual Studio 2008 does the ContextMenuEntry "Solve" help you when you have missing references?
I already found out that HttpContext is not a member of System.Web in my IDE.
According to Help > Info I am using .NET 3.5 SP1.
How do I get that running?
How do u usually react in this situation? What stuff do u look for in msdn.com?
What I would do in that situation is look on MSDN (or Google) for HttpContext. I did that, and it says it’s in System.Web. So make sure your project has a reference to System.Web.
... and then it seems to work:
You can look in the documentation for the HttpContext class, and it tells you that it's in the System.Web namespace, in the System.Web.dll library.
So, to use it you need a reference to the System.Web.dll library, and you either need a using System.Web; statement, or use the fullly qualified name System.Web.HttpContext.Current.Server.MapPath.
However, are you sure that you want to use the MapPath method? The method gets the physical path of a web reference to a file. If the path to your CSV file is a web reference, for example "/data/items.csv" then you want to use the MapPath method, but if you have a physical path like for example "C:\mydata\items.csv" then you don't want to convert it.
Also, the MapPath only works if you actually are in a web application, where there is a HTTP context.
Timwi has it right, but for completeness. No, VS does not have the 'Solve' capability built in, however this functionality has been partially added by some add-ons. For example, Resharper will add the option to add the reference and using when needed -- but it does have to have been referenced before in the solution so it doesn't solve the initial find problem.
It was a simple case of not using the right framework, by that I mean the full fat version rather than the default 'light' version.
Right click on the Project and then Properties and make sure the full version of the latest framework is selected ie '.NET Framework 4', not '.NET Framework 4 Client Profile'
Try to add a reference to System.Web in your project.
HttpContext is a member of System.Web.
http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx
Related
output type of 'Class Library', and a target framework of '.NET Framework 4'.
According to everything I've read, I should have it available, but all I'm seeing in the System.Runtime namespace is the following:
CompilerServices
ConstrainedExecution
ExceptionServices
Hosting
InteropServices
Remoting
Serialization
Versioning
Any ideas?
You just need to add a reference to the System.Runtime.Caching assembly.
In solution explorer, right-click on "References"
Select "Add reference"
From left side menu select "Assemblies"
Look for (or filter) and add System.Runtime.Caching.dll.
It's not part of the default set of references in a class library, but you should be able to add it with no problems.
To complement Jon Skeets answer, (for those who run into this problem), if you still get red squiggly lines under Caching after having added reference to System.Runtime.Caching assembly, just restart the Visual Studio, after having saved the solution, and you should be good to go.
Having added the reference, saved the solution and ( if need may be ) restarted Visual Studio, you should be able to use the types within this namespace. In order to get my solution to work, I had to do this very way.
Edit:
While trying to recreate the problem, and solving this way, it seems that we need to set Copy Local to True in System.Runtime.Caching > Properties and then restart Visual Studio for getting it to work. At least, for my case, the problem didn't seem to solve without this. ;)
Reference System.Runtime.Caching.dll. This is another one of those rather obtuse gotchas in the .NET framework right now where there will be very similar namespaces in some things, but the actual classes you want will be referenced in different assembles. As an example, CacheItem is in this alternate DLL, whereas ApplicationActivator (in System.Runtime.Hosting) is in mscorlib.
For me the System.Runtime.Caching NuGet package is what I needed
little bit o this and all was well
dotnet add package System.Runtime.Caching --version 5.0.0
I'm new to c# and visual studio..
currently i'm developing a metro application fro windows 8 that works as a proxy switcher application..
when I using this code
System.Net.GlobalProxySelection.Select = new System.Net.WebProxy(proxyURI);
it says GlobalProxySelection does not exist in the System.Net.... I imported system.net at the begining of the code..
Edit
no problem with System.net... no errors showing at there.. But the thing is I cant use "GlobalProxySelection" and "WebProxy" classes..
Also Target framework is locked in application properties..
It is likely you haven't added a reference to the System.Net assembly. See this article from MSDN which should give you more info on adding this reference.
The System.Net namespace is in the system.dll assembly. I would be surprised if that weren't already referenced when you started the project, but to be safe, you should ensure that a reference to this dll exists. If it doesn't, then add it.
You can always find this kind of information on MSDN: GlobalProxySelection Class. In the Inheritance Hierarchy section, there is namespace/assembly info.
The only other thing I can think of is maybe you've added a reference to some other assembly that has this namespace (seems unlikely, but possible).
If you go to your project's properties, what is your target framework? It might be that is's accidentally using the "Client Profile" version of the framework, which misses quite a few bits and pieces. If so, change it to the normal version and then it might suddenly exist.
You can change your Target Framework on Application section and don't fix to Client Profile
this is my problem with VS :S
in the first project :
System.Security.Cryptography.AesCryptoServiceProvider obj;
everything is ok
in the second project:
System.Security.Cryptography.AesCryptoServiceProvider obj1;
it doesn't recognize the AesCryptoServiceProvider?!!
is VS using different packages or what ?!
updated: changed the variable name but still not working
var is a reserved keyword. Use a different identifier name or #var.
System.Security.Cryptography.AesCryptoServiceProvider #var;
This may not be the problem - you need to ensure that each project has a reference to System.Core the assembly containing System.Security.Cryptography.
You will also need to ensure that you are targeting a framework version that contains this class (.NET 3.5 and above) - this can be done in the project property pages.
Check if both projects are referencing System.Core. Probably only the first one has it. You've to add it on both to be able to use AesCryptoServiceProvider.
Moreover, as you can see here AesCryptoServiceProvider is only available since .NET 3.5. Check your project's properties, in particular the Target Framework.
Are the references the same between both project? Just open references and see. I bet you are missing one. However, you really should use a different variable name than var. Also, can you post the exact error?
You can't name a variable var because it's a reserved word, use a different name, this will not cause an error :
System.Security.Cryptography.AesCryptoServiceProvider _var;
Edit :
AesCryptoServiceProvider is only supported in .Net framework 4 and 3.5 SP1, change the target framework and it will work and be sure to have System.Security.Cryptography; in that file.
I have a string that I'd like to encode into the standard URL format. From what I've found, I should be able to do this via the httpUtility.urlEncode method, but I don't seem to have that available.
I've added "using" references to both System.Web and System.Net to no avail. I've also seen other references to server.urlEncode amongst other variants, but I don't see the method anywhere.
I'm using the latest version of C# in Visual Studio 2010. Is the method called something different in this version, hidden somewhere else, or am I completely off base?
By default, new projects in Visual Studio 2010 target the .NET Framework 4.0 Client Profile, which does not include the System.Web assembly.
You can change the version of the Framework that your project targets in your project's Properties. Under the "Application" tab, select ".NET Framework 4.0" from the combobox labeled "Target framework".
Then, make sure that you have added a reference to System.Web using the "Add Reference" dialog.
Finally, add a using directive to the top of your class for the System.Web namespace:
using System.Web;
You'll find the various overloads of the UrlEncode method in the HttpUtility class. Sample code:
HttpUtility.UrlEncode("http://www.google.com/");
In .Net 4.5 you can (should?, 'please use' says a Katana comment) use the System.Net.WebUtility.UrlEncode method.
It can't be named differently since Visual Studio doesn't supply the class or method names, the .NET framework does.
All I can tell you is that the System.Web.HttpUtility AND System.Web.HttpServerUtility classes contain a method called UrlEncode(string).
If your project target ".NET Framework X Client Profile",you cannot not use "System.Web",but you can use "Uri.EscapeUriString | Uri.UnEscapeUriString" instead.
Yes, adding the reference was my answer. But be sure you double check the project, that it is in, if you have more than 1 project in your solution. I had a solution with 3 projects. System.Web was added to 2 projects but not the 3rd project.
I spent an hour trying to figure out why I couldn't use HttpUtility since it was a Reference in the main project. But I didn't check the sub-projects of the Solution.
Hope it helps someone.
Because you only see AspNetHostingPermission, AspNetHostingPermissionAttribute, and AspNetHostingPermissionLevel, I strongly suspect (like the other guys) that you're missing a reference.
The best you can do is start a new project, because it's pretty complicated to add/remove references without ruining your entire project.
How to: Add or Remove References in Visual Studio (MSDN) shows how to add/remove references. In your case, you should check/add the System.Web reference.
I want to define some properties on a class using the [Indexable()] attribute in order to use the class with the i4o library (http://www.codeplex.com/i4o) but when I try and compile the code Visual Studio says it cannot find the Namespace for Indexable.
Is this part of the CLR and which namespace/library do I need to get this to compile?
[Indexable()] isn't an attribute included in the .NET Framework. It was removed from i4o in favor of other approaches. See this blog post for details on how to use it.
Its not a part of the standard framework. You're going to need to identify what assembly contains this IndexableAttribute and reference it in your project.
Where is it located? I don't know. Who told you you needed to do this? Is it i4o? If so, its probably within one of the binaries that comes with the i4o project.