Where is my System.Numerics namespace? - c#

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.

Related

How do I add `System.Dynamic` to my project?

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.

Why can't I reference System.ComponentModel.DataAnnotations?

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.

C# using System.Linq error

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.

Determine Project References to mscorlib

Hey folks, I've got an ASP.NET web site project that for some reason is insisting on referencing both mscorlib 1.0.5 and mscorlib 2.0, and I can't figure out why.
I've analyzed all the referenced DLLs using NDepend, and they all appear to only reference mscorlib 2.0. I've got a couple web references, but I can't imagine why that would create an additional reference to the 1.0 dll.
Anyone have any ideas why I'd be getting this additional reference, or what I can use to find out that information? NDepend is great, but just comes back and says "found 2 references, using the newer version", so it doesn't help me figure out why I have the extra reference...
I think at this point your best bet is to use ildasm. Using ildasm on the assembly will bring up a node named "Manifest". Double click on that node and it will dump out the IL representation of assembly references including the referenced version number. Repeat this for all of your DLL's until you find the one referencing the 1.0 version.
EDIT
Another possible solution would be to enumerate the Assembly values and there associated GetReferencedAssemblies method. This will return an array of AssemblyName values which have a corresponding Version member. This should contain the actual version of the referenced assembly vs. the one that was actually loaded.
I'm not 100% sure on this matter and don't have a convenient way to test it right now.
Try removing the reference and recompiling - that will tell you what (if anything) depends on the older version.
An errant reference may be residing in your web.config file.

Finding references in Visual Studio

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.

Categories

Resources