WeakEventManager class not found - c#

I'm attempting to inherit from the WeakEventManager class but the namespace can't be found in my project. I'm not sure what's going on as I have the using System.Windows; directive. I can load a project that uses this class successfully I just can't seem to implement it on my own. The project is .Net 4.5 and I'm unsure as to what's happening.
Any help is appreciated. Thanks in advanced.

The class lives in the System.Windows namespace, but is defined in the WindowsBase assembly. Make sure you have imported the WindowsBase assembly and added it as a reference to your project.

In Solution Explorer
open your project
right-click on References
click Add Reference
select .NET tab
select System.Windows
click OK

In Solution Explorer
open your project
right-click on References
click Add Reference
select .NET tab
select WindowsBase

Related

Can't find "Point" in System.Drawing

As I know, Point are exist in namespace System.Drawing, but Visual Studio can't find it.
using System.Drawing;
class Flower
{
public Point Location { get; private set; }
}
Error: Can't find name of type or namespace "Point"
Edit 1:
.Net 4.5.1
Right click in Solution Explorer on your Project's References entry and click on Add Reference...
Make sure you're looking under Assemblies --> Framework, then find and check the checkbox for System.Drawing, then click OK.
From here, you can useSystem.Drawing.Point in your code.
As others have indicated, you are missing a reference to System.Drawing in your project. The reason this works in some project types and not others is that some project types, specifically Windows Forms projects, will automatically add the reference to System.Drawing for you. While other project types like Console App, Class Library, or WPF Application do not automatically have that reference, so you have to manually add it.

Adding namespaces to Visual Studio project

I am creating a Visual Studio solution and am trying to add namespaces Kafka.Client, Kafka.Client.Producers.Parititioning, Kafka.Client.IntegrationTests, etc. to a program file I've created with a Main() method. I have Kafka.Client and Kafka.Client.IntegrationTests in the References of this program file as per Solution Explorer. The code is as follows:
using Kafka.Client;
using Kafka.Client.IntegrationTests;
using Kafka.Client.Producers.Partitioning;
using Kafka.Client.Utils;
using Kafka.Client.ZooKeeperIntegration;
namespace ConsoleApplication2 {
class Program {
static void Main(string[] args) {
//code here
}
}
}
The problem is that when I try to "Rebuild solution" or "debug solution", the aforementioned "using" lines give the error "The type or namespace name 'Kafka' could not be found (are you missing a using directive or an assembly reference?)" I've spent quite a long time on this and would appreciate some pointers about what I would need to do.
using doesn't actually "include" anything into your project. It just makes it so you don't always have to type out the full namespace. So the error is clearly in referencing the other project.
The Kafka project has to be built first. So first make sure you can successfully build the Kafka project.
if the Kafka is not in the same project, make sure you've add the the reference to the dll, and make sure "copy local" is true
to add the dll as a reference, right-click ConsoleApplication2 in the solution explorer, click add reference, then browse to and locate the actual dll output by the kafka project.
Sounds like these are separate class libraries or other projects. If that's the case, add a project reference from your main project and the using statements will then work.
The reason you want to add them as a project reference, and not a dll reference is that you'll likely switch back and forth from debug/release mode and you might end up with an outdated reference.
Thanks for trying to answer the questions. My problem was that the "Target application" was not the same for all the projects in my solution. Right-clicking on the referenced projects and selecting "Properties" enabled me to change the target application. Then I needed to rebuild the .dll files to run the program properly.

How to use BigInteger in VS 2010

I have been trying to use the BigInteger type, that is supposedly new in .NET Framework 4.0.
I don't seem to be able to get to it, and get an error when trying to reference it via Using System.Numerics.
Any idea what I'm doing wrong? Sorry if this is a stupid question...
Add a reference to the System.Numerics assembly to your project.
a. In Solution Explorer, right-click the project node and click Add Reference.
b. In the Add Reference dialog box, select the .NET tab.
c. Select System.Numerics, and then click OK.
Add a using directive importing the System.Numerics namespace:
using System.Numerics;
Use the BigInteger structure:
var i = new BigInteger(934157136952);
Did you add a reference to System.Numerics?
Right click on References -> Add Reference -> .NET tab -> System.Numerics -> OK
Add a Reference to System.Numerics assembly.
Add using System.Numerics; statement
Have you added a project reference (Project... Add Reference...) to System.Numerics?

Why one project (exe) does not see the namespace of another project (dll) in the same solution?

Why one project (exe) does not see the namespace of another project (dll) in the same solution?
You need to add a reference from the using project to the DLL first.
Select Project|Add Reference, Projects Tab.
A "solution" in Visual Studio is a collection of projects. Each project is independent of all the others. The solution is just a convenient way of organizing projects and opening them all together.
If one project is going to use the public objects defined in another project, then it must be compiled with a reference to the other project. This is true whether the projects are part of a single solution or not.
To signal to Visual Studio that the EXE must be compiled with a reference to the DLL, you must add the DLL to the EXE's list of references in the Solution Explorer.
You need to add a reference to the DLL.
Right-click the EXE project, click Add Reference, go to the Projects tab, and select the DLL.
Also, make sure that the classes in the DLL are public.
Sounds like you need to add a reference to the dll
Right click on the project --> Add Reference

Project Dependencies in Visual Studio

I have a three projects in the solution WinSync. I have WinSyncGui, WinSyncLib and Setup. WinSyncGui requires files from WinSyncLib. How can I get it to include WinSyncLib in WinSyncGui?
VS complains The type or namespace name 'WinSyncLib' could not be found (are you missing a using directive or an assembly reference?)
I've set the dependencies so that WinSyncGui depends on WinSyncLib (so Lib is built first), but it's still not working.
Right click your project (WebSyncGui) and select Add Reference, Projects tab, and then select the project you need to reference.
You need to add WinSyncLib as a reference in your WinSyncGui project.
Adding a project reference.
I've set the dependencies
That sounds wrong. Did you set the "dependencies" or did you set the "references". Dependencies just determine build order, references are used to link projects.
Are you sure all of the types are public? if you omit the modifier, it's internal by default.
Right click on solution, choose Project dependencies and set dependencies whatever you want. It's useful, for example, when you have two exe files in one solution. It's bizzare to add another exe as reference, so I use this option to firstly build depended executable, and then post-build event is copying it into target directory. Very useful toy.

Categories

Resources