[英]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: 我有以下项目/汇编(?)参考:
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.