简体   繁体   中英

Microsoft.Win32 could not be found

I have a project which uses the following line of code to give users the option to select file locations etc.

Win32.SaveFileDialog dialog = new Win32.SaveFileDialog();

Using this however I get the following error:

the type or namespace name 'Win32' could not be found (are you missing a using directive or an assembly reference?)

I'm using the following "using directives" at the top of the file:

using System;
using Microsoft.Win32;

I believe those are all that are required (actually, using Microsoft.Win32 is probably not even required).

I've got the following project/assembly(?) references:

  • Microsoft.CSharp
  • Microsoft.Kinect
  • PresentationCore
  • PresentationFramework
  • System
  • System.Core
  • System.Data
  • System.Data.DataSetExtensions
  • System.Xaml
  • System.Xml
  • System.Xml.Linq
  • WindowsBase

I know there are a million questions around with these kind of problems but non of them seemed to help me out. I tried rebuilding the solution, cleaning it, closing and opening VS (2013). Unfortunately I'm not very well known with VS or C#, but I'd like to think that I tried most of the reasonable solutions out there.

Remove and add again PresentationFramework.dll reference in your project.

Namespace: Microsoft.Win32
Assembly: PresentationFramework (in PresentationFramework.dll)

MSDN link to SaveFileDialog Class

Represents a common dialog that allows the user to specify a filename to save a file as. SaveFileDialog cannot be used by an application that is executing under partial trust.

Since your using Microsoft.Win32 and trying to use the Win32 directly, I believe you also need to add the following directive to have access directly to Win32 :

using Microsoft;

You instead needed this directive.

using Microsoft.Win32.SaveFileDialog; 

Or can use the following line of code for the same functionality:

Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog();

使用命名空间System.Windows.Forms来使用SaveFileDialog的功能。

I had the same issue with an old code I was re-editing in VS2015.

I just removed the Microsoft.Win32 and left just SaveFileDialog (in both lines: directive and object creation) and it worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM