System.Windows.Threading not working - c#

I am trying to use using System.Windows.Threading; but it gives me
The type or namespace name 'Threading' does not exist in the namespace 'System.Windows`.
I have the latest version of .NET.

It's in WindowsBase.dll, after add the reference, it works!
(if you don't know how to add reference, see this tutorial.)

Please make sure you've added a reference to WindowsBase.dll to your project and then you should be good to go. have a look at - https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer%28v=vs.110%29.aspx
If you're still having trouble please attach your .csproj file.

You have to add a reference to the assembly containing the class you want to use.
Additionally, you probably don't want to use WPF classes (from System.Windows.Threading) if you did not create the project with the WPF application wizard.
Edit: In Windows Forms applications, the obvious choice for a timer is System.Windows.Forms.Timer, and in some cases System.Threading.Timer.

It's using System.Threading; not using System.Windows.Threading. Don't know if you used that in your code and just made a mistake on the question, but there it is.

Related

Namespace Resolving Issue Visual Studio 2013

I am having some namespace issues. In my solution I have the following solutions ;
Services
Services.WebApi
Now, as an example in my WebApi controller I want to reference a sub namespace of the above Services solutions namespace, i.e.;
using Services.Data;
However, it is not resolving the Services from the project reference? Instead its trying to reference from a small namespace inside the Service.WebApi.Services of the current solution? So, it is looking like VS is automatically assuming the local namespace in stead of the referenced one? (i.e. if I hover over the Services text of Services.Data, intellisense is showing 'namespace Services.WebApi.Services'.
I've used this before with no issues, any ideas whats going on here?
To note the Services project is added as a reference and both are running .NET 4.6.
If you wish to indicate that your intention is to start at the "top" of the namespace hierarchy, you can use the global alias:
using global::Services.Data;
You can try using an alias for your Services reference. In the References List, select your Reference properties, And you'll see an Alias property. Change in to the name you want and then change your using to that name. Let's say you set the Alias to ExternalServices. You'll need to add this to your code:
extern alias ExternalServices;
using ExternalServices::Services.Data;
That would solve your problem.

How to know what assembly to add C#

I've ran into this issue a couple times and I'm wondering if anyone has a better solution than trial and error or searching stack overflow.
Lets say we are using some .net class Foo
Foo resides in the Bar.Baz namespace
The following statement
using Bar.Baz;
is not sufficient to compile the program, we are missing an assembly reference. So add a reference to System.Bar.Baz It still doesn't work so after searching the internet I find that I actually have to add a reference to Some.Other.dll and now it compiles.
My question is how do I know what namespace maps to what reference when the usual one doesn't work?
Most recent problem was
The type or namespace name 'DbContext' could not be found Instead of adding a reference to System.Data.Entity I had to install through Nuget.
If it is a .NET framework function, you can just search it on MSDN, and it will tell you in which assembly the class/function exists.
You can also use ReSharper which is a very nice plugin to Visual Studio, and it can help you add assemblies automatically.
If you're using Visual Studio 2013 or higher, one easy way to discover which namespace a class belongs to is using the Peek definition feature. You can easily find it in the right-click context menu.
In the screen below, I used it with KeyValuePair:
Also, take a look at the documentation.

Browser detection in C# (.Net)

I'm in C# land today. I'm trying to write a function which accepts a user agent string and returns an object that gives me at least the browser name and version. So I tried this answer, but apparently I don't have access to HttpBrowserCapabilities. It tells me the type or namespace name could not be found (yes, even if I add using System.Web, it still doesn't show up, or when I type using System.Web. it doesn't pop up, so it's obviously not there).
I'm using .net 3.5, but the documentation for that class shows it existed even in 3.5, so I'm not sure what's going on. I have access to the browscap files - ini or xml. Am I going to have to write this from scratch?
Edit: I've fixed the reference problem. But Chrome is being reported as AppleMAC-Safari 5.0. I'm wondering if I'm going to need a completely different approach. PHP figures it out with the same ini file fine.
Adding a using block does not automatically import the DLL. All a using does is allow you to not write:
System.Web.HttpClient //Or whatever
All over the place, and use HttpClient instead.
You need to add a reference to System.Web to the project before any of its classes will be available to you.
Did you have a using System.Web; statement in your source file?
Here's a tip: if you're using Visual Studio, and you have a reference to the System.Web.dll in your project, if you type the name of a type and press Ctrl-. it will give you a popup menu to add the namespace reference to your source file.
Do you see it in the ObjectBrowser (assuming you are using Visual Studio)? I found the namespace this morning (granted I'm on 4.5 - but documentation shows it has been around since 3.5 and earlier)

System.Drawing does not exist?

I'm trying to create a validation image using class library in asp.net, but that is not the question.
Anyway, my question is... well... system.drawing does not exist so I cant use "bitmap".
From similar questions, people tell to add reference. But I already did that, restarted my computer etc. It doesn't work.
What can I do besides adding reference? It doesn't work or am I doing it wrong ?
Here is basically what I did:
Right click to references, which is under solution,
add reference
add system.drawing
But still, it does not appear in intellisense or tells me "it does not exist, try adding reference" when I type it manually.
I suspect that you added the System.Drawing reference to the wrong project. Please verify that the Validator.cs file in the project that has the System.Drawing reference.
You can add referrence 'System.Drawing.dll' to your project.
I had the same issue and solved it, click on the project menu, then Add reference, reference manager will open, then click on the assemblies tab, search for System.Drawing and check it then press ok. it will recognize the package or name space.
I stumbled this error even referencing assembly. After thinking i realised that that error produced after adding a class file which is under 'System' folder which i produced on the project folder. That class has ##.System.## namespace as well under the folder. .Net produced error if you have any custom namespace which contains 'System' keyword. Try changing folder name and namespace if u stumbled as well.
Click on the Project tab and then on Add Reference…
Then select System.Drawing or whatever you want.
In addition to adding the reference, you will also need to import it using the using statement in the top of your code file:
using System.Drawing;
You should change .NET Framework version to .NET 4.0
I have also encountered the same problem. I found that a console/class library project cannot add a reference to System.Drawing. When I changed to use a Window Form project, I was able to add a Bitmap with a reference to System.Drawing.
The error is because you have not added any user control to your class library project. Add a user control to your class library project, and the error will vanish.
I had same problem. I was trying to add Reference to System.Drawing.dll via System Explorer, but it didn't help me. Finally, I put cursor on the varialbe of type 'Graphics', clicked Ctrl+. or 'Alt+Enter->Refactoring' and select 'using System.Drawing'. I don't understand why and how, but it solved my problem.

Namespace 'SharePoint' does not exist in the namespace 'Microsoft'

So I am starting to learn C#, like literally just started learning, and coming from a Java background, it doesn't look too bad. However, I have a question. I am following THIS tutorial on using the client-object model. And just starting from the top, I added the references, but using Microsoft.SharePoint.Client; keeps giving me the error that "the namespace 'SharePoint' does not exist in the namespace 'Microsoft', but I clearly see it on the right side panel. So looking at the instructions, the only difference I can think of is that fact that I am using Visual Studio Express and thus do not have the option to choose which framework to use when creating a new project. Other than that, I don't know what the problem might be. Does anyone have any ideas on what else I could be missing or how to correct this problem?
Make sure that the target framework is 3.5 and not 4 i.e for SP2010
Did you add the references to the Microsoft.SharePoint.Client assembly and Microsoft.SharePoint.Client.Runtime assembly as noted near the beginning of that tutorial?
Add required references to the solution.
Make sure that the target framework is 4 for SP2013(3.5 for SP2010).
Did you do this part of the tutorial you mentioned above?
To build the application, you must add references to two assemblies,
Microsoft.SharePoint.Client.dll and
Microsoft.SharePoint.Client.Runtime.dll. Installing SharePoint
Foundation installs these assemblies on the server. The two assemblies
are located in the following directory:
%ProgramFiles%\Common Files\Microsoft Shared\web server
extensions\14\ISAPI
Take a look at the references in your project and make sure you have the reference to the assembly. If it is not there try adding it, right click -->add reference and find "Microsoft.SharePoint.Client"
Thanks to those who mentioned the 4.0 framework.
Mine defaulted to .NET Framework 4 Client Profile (and I have no idea what that means), and the Namespaces looked good in Intellisense, but the build would say they weren't found! Crazy.
for anyone developing for SP2019, you need to target .net 4.5

Categories