I am new to C# 4, especially the dynamic keyword. I have seen quite a number of tutorials and wish to try it out myself using VS 2012 Ultimate (MSDN).
Unfortunately I cannot seem to find System.Dynamic and cannot add a reference to it either. May I know where I can find the DLL for System.Dynamic and what I might have done wrong?
By default, VS 2012 already targets Fx 4.5, and System.Core is added as a reference.
The dynamic keyword is so common that when searching in Google yield a lot of un-related results.
Make sure you are targeting the .NET Framework version 4 or later.
Ensure your project references the System.Core assembly.
You will find the types and functionality of System.Dynamic in that assembly. Add the following line to your code files:
using System.Dynamic;
P.S.: In C#, in order for the dynamic keyword to work properly, you also need to reference the Microsoft.CSharp assembly. This assembly contains the late-binding functionality necessary for dynamic.
Whenever you want to search for documentation add msdn. Like msdn system.dynamic
You will find all the documentation you need.
System.Dynamic at MSDN
Namespace: System.Dynamic
Assembly: System.Core (in System.Core.dll)
The DLL is System.Core. Adding a reference to it will allow you to use the namespace System.Dynamic.
Related
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
To much fanfare it was announced that there was now a Roslyn powered index for the .NET Reference Source and that
The version of the framework that we currently have indexed is .NET framework
version 4.5.1.
Yet when I go there to look at HttpClient code all I get are stubs and I cannot find any code for the bits that make it run like System.Net.Http.WebRequestHandler.
Where can I find this code and why hasn't it been included already?
I found the solution on blogs.msdn.com:
"The WebRequestHandler is not included in the System.Net.Http DLL but rather in System.Net.Http.WebRequest DLL so you have to explicitly include that as a reference in order to see it."
add assembly System.Net.Http.WebRequest
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.
I'm using Visual Studio 2010 and trying to use the BigInteger type in a C# program. This type is supposed to be available in System.Numerics namespace, but I don't seem to have that installed in the .Net 4.0 framework. When I type "using System.Numerics;" in VS2010, a red underline appears under the "Numerics". Has anyone else ever had this problem?
If so, how do you resolve it? I just re-downloaded and re-installed (repaired) the .Net 4.0 framework, but that didn't help. I've never had any problems with other C# programs that I've written, so I'm wondering what I'm missing.
You need to add an assembly reference to System.Numerics.dll
The MSDN entry on BigInteger states:
BigInteger Structure
...
Namespace: System.Numerics
Assembly: System.Numerics (in System.Numerics.dll)
Though most assemblies are the part of the installation, VS does add only some core elements to the reference list of a project (Core, Data, XML etc.). One needs to add other references by hand using Reference Manager.
Right-click your project, then select Add Reference (or Add->Reference). System.Numerics resides in Assemblies. Then you can use using System.Numerics; in project files.
PS: this answer is not intended to get any vote. It is only for future reference if someone needs how to do it, just as I needed before this answer.
I'm using Visual Studio and COM with C# for the first time and there's something I don't quite understand about the 'references'. How do you know what to reference with a given 'using something.something'? The .Net references seem fairly simple, but COM is less obvious. I'm running Visual Studio 2005 and have the latest VSTO installed, but for the life of me, I can't figure out what I need to reference to satisfy:
using Microsoft.VisualStudio.Tools.Applications.Runtime;
There are a few Microsoft.VisualStudio things in the .Net tab, but none that continue with .Tools or anything like it. I feel like I'm missing a key concept here.
There are two issues here -
First, a reference doesn't necessarily correspond to a namespace. A single reference can contain multiple namespaces, and a single namespace can be shared by multiple assemblies which would need to be referenced. Needing to include a reference allows you to use specific types, not entire namespaces.
Second, this is something you'll need to know in advance. If you're using Microsoft's classes, such as the ones in the namespace you listed, MSDN can be a great help.
For example, take Microsoft.VisualStudio.Tools.Applications.Runtime.ServerDocument
If you look at the MSDN page for this class (in that namespace), near the top it includes:
Namespace: Microsoft.VisualStudio.Tools.Applications.Runtime
Assembly: Microsoft.VisualStudio.Tools.Applications.Runtime (in microsoft.visualstudio.tools.applications.runtime.dll)
This specifically tells you which assembly is required.
That reference is part of the Visual Studio SDK. I am currently using VS 2008, but the assemblies should be the same for VS 2005. The link for the SDK is here.
Going the other way is pretty easy. If you're given a reference, you can open that reference in the object browser to see what namespaces it contains, and from that, determine what usings to add. Its not trivial to determine what to reference for a given using, as there's no guarantee that there exists exactly one DLL for each namespace. How is it that you arrived at a
using Microsoft.VisualStudio.Tools.Applications.Runtime;
Without knowing what to reference? If its a code sample somewhere, they ought to mention what the external references and dependencies of the project are.