简体   繁体   English

找不到Microsoft.Win32

[英]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 directives”:

using System;
using Microsoft.Win32;

I believe those are all that are required (actually, using Microsoft.Win32 is probably not even required). 我相信这些都是必需的(实际上,甚至可能不需要using Microsoft.Win32 )。

I've got the following project/assembly(?) references: 我有以下项目/汇编(?)参考:

  • Microsoft.CSharp Microsoft.CSharp
  • Microsoft.Kinect Microsoft.Kinect
  • PresentationCore PresentationCore
  • PresentationFramework PresentationFramework
  • System 系统
  • System.Core System.Core程序
  • System.Data System.Data
  • System.Data.DataSetExtensions System.Data.DataSetExtensions
  • System.Xaml System.Xaml
  • System.Xml 的System.Xml
  • System.Xml.Linq System.Xml.Linq的
  • WindowsBase 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). 我尝试重建解决方案,清理它,关闭并打开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. 不幸的是,我对VS或C#并不是很了解,但我想我在那里尝试了大部分合理的解决方案。

Remove and add again PresentationFramework.dll reference in your project. 在项目中删除并再次添加PresentationFramework.dll引用。

Namespace: Microsoft.Win32 命名空间:Microsoft.Win32
Assembly: PresentationFramework (in PresentationFramework.dll) 汇编:PresentationFramework(在PresentationFramework.dll中)

MSDN link to SaveFileDialog Class MSDN链接到SaveFileDialog类

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. 在部分信任下执行的应用程序不能使用SaveFileDialog。

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 : 由于您使用Microsoft.Win32并尝试直接使用Win32 ,我相信您还需要添加以下指令才能直接访问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. 我在VS2015中重新编辑的旧代码遇到了同样的问题。

I just removed the Microsoft.Win32 and left just SaveFileDialog (in both lines: directive and object creation) and it worked for me. 我刚删除了Microsoft.Win32并且只保留了SaveFileDialog (在两行中:指令和对象创建),它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到命名空间Microsoft.Win32 - Namespace Microsoft.Win32 could not be found 为什么OpenFileDialog需要Microsoft.Win32? - Why OpenFileDialog requires Microsoft.Win32? 不使用 Microsoft.Win32 的 Openfiledailog 框 - Openfiledailog box without using Microsoft.Win32 .Net Standard Microsoft.Win32 不包含 OpenFileDialog() 方法 - .Net Standard Microsoft.Win32 does not contain OpenFileDialog() Method 是否可以直接使用Microsoft.Win32命名空间中的Win32Native类? - Is it possible to directly use the Win32Native class from the Microsoft.Win32 namespace? 即使使用Microsoft.Win32也找不到RegistryKey-Class - Can't find RegistryKey-Class even when Microsoft.Win32 is used Microsoft.Win32中的OpenFileDialog.FileName返回空字符串 - OpenFileDialog.FileName from Microsoft.Win32 returning empty strings 找不到类型'Microsoft.Win32.SafeHandles.SafeRegistryHandle'的构造方法 - Constructor on type 'Microsoft.Win32.SafeHandles.SafeRegistryHandle' not found Docker 构建:“ContainerBuildAndLaunch”任务意外失败。 无法加载文件或程序集“Microsoft.Win32.Registry - Docker Build : The "ContainerBuildAndLaunch" task failed unexpectedly. Could not load file or assembly 'Microsoft.Win32.Registry 无法加载文件或程序集Microsoft.Win32.Primitives,Version = 4.0.0.0 - Could not load file or assembly Microsoft.Win32.Primitives, Version=4.0.0.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM