2

I have a program using WPF in C# that uses the .NET 4 Framework (Not Client Profile), and it compiles a source file called "Source.txt". However, whenever it compiles it I get this error "Error CS02345: The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)". No file is created.

When I checked the lines from the Source.txt file, these are the ones that are giving the error:

using System.Windows.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Forms;
using System.Management;

This is the code I'm using to compile it from the main program:

CompilerParameters Params = new CompilerParameters();
            Params.GenerateExecutable = true;
            Params.ReferencedAssemblies.Add("System.dll");
            Params.OutputAssembly = ServerNameBox.Text;
            Params.CompilerOptions = " /target:winexe";    

            string Source = compileSource;
            CompilerResults Results = new CSharpCodeProvider().CompileAssemblyFromSource(Params, Source);

            if (Results.Errors.Count > 0)
            {
                foreach (CompilerError err in Results.Errors)
                    System.Windows.Forms.MessageBox.Show(err.ToString());
            }
            else System.Windows.Forms.MessageBox.Show("Sucessfully Compiled Program!");

As indicated in the code, I want this program to be compiled as a Windows Form / GUI Application (" /target:winexe");

If this information is not sufficient, please ask.

2 Answers 2

3

As the error clearly hints, you need to add System.Windows.Forms.dll to ReferencedAssemblies.

Sign up to request clarification or add additional context in comments.

3 Comments

Oh, I see. Thanks, that cleared that part up but now I am getting an error saying I need a static entry point. When I make my main method static, it's forcing me to make the rest of the variables and methods static as well. Is there any other way to do this?
@Hexo: The same way you write any other application
I'm sorry, could you clarify on your statement?
1

You need to add at least the following references:

Params.ReferencedAssemblies.Add("PresentationFramework.dll");
Params.ReferencedAssemblies.Add("System.Windows.Forms.dll");
Params.ReferencedAssemblies.Add("System.Management.dll");
Params.ReferencedAssemblies.Add("PresentationCore.dll");

Also I don't believe System.Windows.Linq is an actual namespace. If you need LINQ it should be System.Linq and that is in System.Core.dll

1 Comment

PresentationFramework.dll & PresentationCore.dll could not be found. I believe in the compiled application I don't use System.Windows.Input so I just removed it. Thanks though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.