I have a console Application and I need to occasionally launch a WPF form depending on the parameters. I and trying the following:
if (arg == "/C")
{
System.Windows.Application application = new System.Windows.Application();
application.Run(new EJConfig.MainWindow());
}
The problem is that when I go to add a reference to System.Windows, it doesn't show up in the list of .NET components, and without it I get the following error:
The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)
Have you tried adding:
using System.Windows;
To the top of the c# file? You may also need these assemblies:
Assembly: PresentationFramework (in PresentationFramework.dll)
Assembly: PresentationCore (in PresentationCore.dll
Check it out here
you need to add the PresentationFramework and PresentationCore assemblies to your project.
The System.Windows.Application class is located in the PresentationFramework assembly, but you'll also need PresentationCore for it to work.
source:
http://msdn.microsoft.com/en-us/library/system.windows.application.aspx
You are probably missing additional references besides System.Windows. I don't know which are required. You could find out by creating a default application and check the references listed.
Related
I can't get to use GZipStream class in my C# ASP.NET 4.5 application.
I get the error:
The type or namespace name 'GZipStream' could not be found (are you missing a using directive or an assembly reference?)
I tried using using System.IO; but the System.IO.Compression is not available in the "Reference Manager" in visual studio. I right click on the object name to see if Visual Studio finds the relevant reference but it does not.
Any suggestions?
Need to add reference to System.dll assembly and using System.IO.Compression namespace.
MSDN: GZipStream Class
The namespace is not the same as the dll name,You need to add a dll reference to the assembly, System.IO.Compression.FileSystem.dll
I'm getting the error:
Error 1 The type 'System.Windows.Markup.IQueryAmbient' is defined in
an assembly that is not referenced. You must add a reference to
assembly 'System.Xaml, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.
When doing the following:
public void ExitApplication()
{
Application.Current.Shutdown();
}
The project is targeted to .NET 4.0, my Visual Studio is 2010, I tried adding
using System.Windows.Markup; with no succes, and
using System.Xaml; where Xaml doesn't exist in namespace System.
What should I do to fix this?
Well ok, I guess your issue is solved when you add System.Xaml.dll as reference to your project. The interface is declared there. Here is the doc.
Add System.Xaml.dll to project references.
You need to add a reference to System.Xaml in your main application project. Using System.Xaml is not needed to be in your code.
I downloaded a project that has a reference to Microsoft.Windows.Design.dll, but it's not on my system. Where can I get this package?
using Microsoft.Windows.Design.PropertyEditing;
That namespace is typically found in the Microsoft.Windows.Design.Interaction.dll assembly, not Microsoft.Windows.Design.dll.
For example, the NewItemFactory class:
Namespace: Microsoft.Windows.Design.PropertyEditing
Assembly: Microsoft.Windows.Design.Interaction (in Microsoft.Windows.Design.Interaction.dll)
I am trying to check a service in C#, I have added the System.ServiceProcess.dll
Although I get the error:
Error 2 The type or namespace name 'ServiceController' could not be found (are you missing a using directive or an assembly reference?) D:\App\Form1.cs 247 13 App
My code is as follows:
private void button13_Click(object sender, EventArgs e)
{
ServiceController sc = new ServiceController("Spooler");
if (sc.Status == ServiceControllerStatus.Running)
{
MessageBox.Show("The service is running.");
}
}
Do I perhaps need a "using" statement?
You need to add a reference to the System.ServiceProcess.dll
After that, you will be able to see it in Visual Studio, as one of the using statements you can add to your project:
Pro Tip: When you are trying to use a class from the .NET Framework and you get a message like:
The type or namespace name '...' could
not be found (are you missing a using
directive or an assembly reference?)
Lookup the type in the MSDN Library and look under the Inheritance Hierarchy section to find the Namespace and Assembly you need.
Inheritance Hierarchy
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.ServiceProcess.ServiceController
Namespace: System.ServiceProcess
Assembly: System.ServiceProcess (in System.ServiceProcess.dll)
Then ensure that you have a reference to the assembly and a using directive for the namespace (assuming you don't want to fully qualify the name).
Yes, at the top.
using System.ServiceProcess;
For me (Visual Studio 2012) it was not a default addition when typing in "using"
I had to add a reference and search through the assemblies for System.ServiceProcess. (I believe it is located in the .NET tab in older versions of Studio).
Hope this helps any future viewers!
Hi I'm having a problem implementing this method.
I have added using System.Management but the class still doesn't work.
The error is:
Error 7 The type or namespace name 'ManagementBaseObject' could not be found (are you missing a using directive or an assembly reference?)
You are probably missing the assembly reference to System.Management.dll. The using statement just brings names into scope, to save you typing the prefix: it doesn't actually add a DLL reference.
Right-click your project's References folder and choose Add Reference. Go to the .NET tab of the resulting dialog, select System.Management and click OK.
did you add System.Management.dll as a reference?
msdn tells us more about where to find ManagementBaseObject:
Namespace: System.Management
Assembly: System.Management (in
System.Management.dll)
Don't Forget to write using System.Management; after adding the reference some time this happens even after adding the respective assembly it shows the error.