c# - Shell32.dll 引用导致问题

标签 c# unzip windows-shell codedom

我正在使用 .NET Framework 3.5 在 C# 中创建一个应用程序,该应用程序具有解压缩文件的功能;但是,当我运行它时,一旦它进入解压缩方法,它就会因 Windows“停止工作”错误而崩溃。它不读取方法中的任何行,只是在输入时崩溃。

Description:
Stopped working

Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01:   test.exe
Problem Signature 02:   0.0.0.0
Problem Signature 03:   50b03509
Problem Signature 04:   Test
Problem Signature 05:   0.0.0.0
Problem Signature 06:   50b03509
Problem Signature 07:   1
Problem Signature 08:   38
Problem Signature 09:   System.IO.FileNotFoundException
OS Version: 6.1.7601.2.1.0.256.48
Locale ID:  1033

使用“已停止工作菜单”中的调试功能后,出现此错误。

Could not load file or assembly 'Interop.Shell32, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

我使用这段代码在 CodeDom 编译器中导入 Shell32.dll。

Params.ReferencedAssemblies.Add("Interop.Shell32.dll");

这是在崩溃的方法中解压缩文件的代码。

Shell32.ShellClass sc = new Shell32.ShellClass();
                Shell32.Folder SrcFlder = sc.NameSpace(source);
                Shell32.Folder DestFlder = sc.NameSpace(dest);
                Shell32.FolderItems items = SrcFlder.Items();
                DestFlder.CopyHere(items, 20); 

我不确定为什么会这样。它在原始应用程序中完美运行,但是当我使用 CodeDom 编译它(不产生任何错误)并运行它时,就会发生这种情况。我没有正确引用 COM 吗?

最佳答案

Could not load file or assembly 'Interop.Shell32, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

引用已加载到您的程序集中。但是您的应用程序找不到您的 COM 依赖项。

您需要在主可执行文件的根目录中安装“Interop.Shell32.dll”。

为此,在 Visual Studio 上我们有一个选项,当单击引用时,是“复制本地”- 仅将其设置为 true,并且依赖项将在下一次构建时复制到应用程序文件夹。

然后您可以使用构建文件夹中存在的库文件运行您的应用程序。

关于c# - Shell32.dll 引用导致问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13537850/

相关文章:

c# - WP7 : Styling ListBox items

C# 如何将虚拟键码转换为字符?

c# - 如何在 .net 标准项目中通过 nuget 获取 stylecop 规则集

java - 文件下载代码下载比原始文件大的文件

node.js - nodejs从url下载并解压文件,错误No END header found

c++ - 具有特定语言本地化的 SHBrowseForFolder

c++ - 如何使用 C++ 在 Windows 中添加虚拟文件夹

c# - 使用 EntityFramework 源项目而不是其程序集的解决方案无法成功启动

linux - 如何在linux和windows下实现相同的压缩

c++ - 让 explorer.exe 从启动时加载我的扩展