I have been researching but I can't seem to find any relevant answer. I will appreciate it if someone told me the nuget package to install in asp.net webapi application for System.Web.Hosting
I need it to use Hosting.HostingEnvironment.MapPath("")
Add a reference to System.Web assembly, you will then be able to access System.Web.Hosting.HostingEnvironment
Since this is in the System namespace, its very likely part of the Framework.
Googling for that namespace brings it up on MSDN. So, open up the documentation for that namespace on MSDN. Click on any class in the list, it doesn't matter which.
You will see something like this:
Namespace: System.Web.Hosting
Assembly: System.Web (in System.Web.dll)
You now know which assembly this particular class is in, which likely also contains most of the rest of the desired namespace. Check another class on MSDN to confirm. Well, this is System.Web. That's part of the Framework.
If you do this for another namespace and can't find it on MSDN, you're probably looking for a Nuget package. But in this case, nope. Just add a reference to the assembly.
System.Web is not a nugget package.
Go to Solution explorer > References > Add References > Framework > look for System.Web.
System.Web.Hosting.HostingEnvironment.MapPath(string.Empty);
For .Net Core use
Microsoft.AspNetCore.Hosting
Related
The following line gives an error saying it doesn't exist in the current content.
Interaction.InputBox("Enter Version", "", "default");
I read other questions about this I did every possible way;
Added reference to Microsoft.VisualBasic from project add section, also included;
using Microsoft.VisualBasic;
I don't understand why it creates problem.
Probably you've got an old version of the Microsoft.VisualBasic.dll.
Click on Dependencies > Frameworks > Microsoft.NETCore.App > Microsoft.VisualBasic.
Then look in the Properties window.
There you should see ..\net5.0\Microsoft.VisualBasic.dll.
If you see ..\netcoreapp3.1\Microsoft.VisualBasic.dll - that's too old.
To get the new Microsoft.VisualBasic.dll you have to base your App on .NET 5.0.
I have the same error as yours. I solved it by adding Microsoft.VisualBasic reference through Nuget package tool instead of by myself.
Propably the dll version in our system is too old, and Nuget can install the correct one.
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 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
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.
In .net frameworks 1.1, I use
System.Configuration.ConfigurationSettings.AppSettings["name"];
for application settings. But in .Net 2.0, it says ConfigurationSettings is obsolete and to use ConfigurationManager instead. So I swapped it out with this:
System.Configuration.ConfigurationManager.AppSettings["name"];
The problem is, ConfigurationManager was not found in the System.Configuration namespace. I've been banging my head against the wall trying to figure out what I'm doing wrong. Anybody got any ideas?
You have to reference the System.configuration assembly (note the lowercase)
I don't know why this assembly is not added by default to new projects on Visual Studio, but I find myself having the same problem every time I start a new project. I always forget to add the reference.
If you're just trying to get a value from the app.config file, you might want to use:
ConfigurationSettings.AppSettings["name"];
That works for me, anyways.
/Jonas
You are missing the reference to System.Configuration.
Visual Studio doesn't make it obvious which assembly reference you need to add. One way to find out would be to look up ConfigurationManager in the MSDN Library. At the top of the "about ConfigurationManager class" page it tells you which assembly and DLL the class is in.
System.Configuration us refer to System.configuration (not the small case for configuration, in .net 2.o it reefers to System.Configuration.dll.