The compiler won't find namespace 'System.Windows.Interop'

c#, winforms

Solution

It is a WPF namespace. One assembly you could reference (which contributes classes to that namespace) is `PresentationCore.dll`. But what classes from `System.Windows.Interop` do you actually need since you have that `using` directive? What you need to reference is the assemblies where those classes are.

Maybe the solution is to remove the `using`?

If you make a WinForm application, possibly you don't need any WPF namespaces?

Problem

Help!!**The compiler won't find namespace **'System.Windows.Interop'**** recently I built a winform project,and want to use a dll (do some d3d rendering work) generated by another c++ project; ``` OS: win7 x64 IDE: vs2013 Language:C# current framework used in the winform project is ".net framework 4.5" ``` And in the winform project,I created a class file named MCDllOpt.cs The code is as follow. ``` using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Interop; // Error occured here! namespace WorldEditor { class MCDllOpt { } } ``` And here's part of what the compiler tells. ``` 1>CoreCompile: 1> C:\Program Files (x86)\MSBuild\12.0\bin\Csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /platform:anycpu32bitpreferred /errorreport:prompt /warn:4 /define:TRACE /errorendlocation /preferreduilang:en-US /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Deployment.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Drawing.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Windows.Forms.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Xml.Linq.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\WorldEditor.exe /subsystemversion:6.00 /resource:obj\Release\WorldEditor.Form1.resources /resource:obj\Release\WorldEditor.Properties.Resources.resources /target:winexe /utf8output Form1.cs Form1.Designer.cs MCDllOpt.cs Program.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs "C:\Users\Think\AppData\Local\Temp\.NETFramework,Version=v4.5.1.AssemblyAttributes.cs" obj\Release\\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs obj\Release\\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs obj\Release\\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs 1>F:\WorldEditor\WorldEditor\WorldEditor\MCDllOpt.cs(6,22,6,29): error CS0234: The type or namespace name 'Interop' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) 1> 1>Build FAILED. 1> 1>Time Elapsed 00:00:00.78 ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== ``` After several minutes' searching.I found out that I need to add references specified. But after I add all the references whose prefix is 'System.Windows',the problem's still not fixed! Does anyone have this problem before? Please help me.

Original source