调试Visual Studio 2017扩展时找不到程序集

5
我正在尝试更新我的Diff All Files Visual Studio扩展程序以支持VS 2017。在调试我的扩展程序时,它抱怨找不到所需的程序集:
System.Windows.Markup.XamlParseException occurred
  HResult=0x80131501
  Message=Could not load file or assembly 'QuickConverter, PublicKeyToken=9c892aa7bc2af2cf' or one of its dependencies. The system cannot find the file specified.
  Source=PresentationFramework
  StackTrace:
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at VS_DiffAllFiles.Sections.DiffAllFilesSectionControl.InitializeComponent() in D:\dev\Git\VS.DiffAllFiles\VS.DiffAllFiles.VS2017\obj\Debug\DiffAllFilesSectionControl.xaml:line 1
   at VS_DiffAllFiles.Sections.DiffAllFilesSectionControl..ctor(DiffAllFilesSectionBase parentSection) in D:\dev\Git\VS.DiffAllFiles\VS.DiffAllFiles\Sections\DiffAllFilesSectionControl.xaml.cs:line 18
   at VS_DiffAllFiles.DiffAllFilesBaseClasses.DiffAllFilesSectionBase..ctor() in D:\dev\Git\VS.DiffAllFiles\VS.DiffAllFiles\DiffAllFilesBaseClasses\DiffAllFilesSectionBase.cs:line 82
   at VS_DiffAllFiles.DiffAllFilesBaseClasses.TfsDiffAllFilesSectionBase..ctor()
   at VS_DiffAllFiles.DiffAllFilesBaseClasses.SupportsIncludedAndExcludedChangesTfsSectionBase..ctor()
   at VS_DiffAllFiles.Sections.PendingChangesSection..ctor() in D:\dev\Git\VS.DiffAllFiles\VS.DiffAllFiles\Sections\PendingChangesSection.cs:line 27

Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'QuickConverter, PublicKeyToken=9c892aa7bc2af2cf' or one of its dependencies. The system cannot find the file specified.

我已确认文件位于C:\Users\Dan.Schroeder\AppData\Local\Microsoft\VisualStudio\15.0_b920d444Exp\Extensions\DansKingdom\Diff All Files for VS2017\1.0\QuickConverter.dll,并且它具有正确的名称和公钥。
我还捕获了Fusion日志(即程序集绑定日志查看器)以捕获绑定错误,似乎VS没有在其所在目录中查找dll文件;而是在实际的VS 2017目录中查找。我捕获了这个错误,还有另一个包含版本的完全限定名称的错误,这是程序集的正确版本:
*** Assembly Binder Log Entry  (4/13/2017 @ 1:18:51 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = QuickConverter, PublicKeyToken=9c892aa7bc2af2cf
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: QuickConverter, PublicKeyToken=9c892aa7bc2af2cf | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = devenv.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Dan.Schroeder\AppData\Local\Microsoft\VisualStudio\15.0_b920d444Exp\devenv.exe.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PublicAssemblies/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PublicAssemblies/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/Debugger/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/Debugger/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/x86/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/x86/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PublicAssemblies/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PublicAssemblies/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/Debugger/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/Debugger/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/x86/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/x86/QuickConverter/QuickConverter.EXE.
LOG: All probing URLs attempted and failed.

有什么想法,为什么VS没有在正确的位置查找加载那个程序集?还是我漏掉了什么?在开发VS 2012、2013或2015扩展时,我没有遇到这个问题。我通过提供rootsuffix Exp命令行参数来调试Visual Studio Extension,就像我为以前的Visual Studio版本所做的一样。
如果你想要的话,你可以下载源代码并自己重现这个问题(它是AddVs2017Support分支);只需卸载除VS.DiffAllFiles和VS.DiffAllFiles.VS2017项目之外的所有项目即可。
任何想法/建议都将不胜感激。谢谢。

更新1

根据Hans Passant提供的链接,我尝试向我的项目中添加.pkgdef文件,并将其包含为我的.vsixmanifest文件中的资源,但问题仍然存在。当我查看 C:\Users\Dan.Schroeder\AppData\Local\Microsoft\VisualStudio\15.0_b920d444Exp\devenv.exe.config 文件时,仍然没有看到任何对我的程序集的引用,因此它似乎没有像应该那样向该文件添加任何内容。此外,融合日志仍然报告与我上面提供的完全相同的信息。

当我尝试手动生成.pkgdef文件(因为它应该作为构建过程的一部分自动生成),我会收到以下错误信息。我不确定在Visual Studio之外尝试生成时是否应该出现这种情况(我只是使用普通命令提示符)。

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VSSDK\VisualStudioIntegration\Tools\Bin>CreatePkgDef.exe /out="C:\Temp\Def.pkgdef" "C:\Users\Dan.Schroeder\AppData\Local\Microsoft\VisualStudio\15.0_b920d444Exp\Extensions\DansKingdom\Diff All Files for VS2017\1.0\VS.DiffAllFiles.VS2017.dll"
Visual Studio (R) PkgDef Creation Utility.
Copyright (c) Microsoft Corporation. All rights reserved.

Assembly: VS.DiffAllFiles.VS2017 1.0.0.0
Output file: C:\Temp\Def.pkgdef

CreatePkgDef : error : ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at Microsoft.VisualStudio.Tools.CreatePkgDef.ProcessAssembly(String fileName, Hive hive, PkgDefContext context, Boolean register, RegistrationMode mode) in F:\dd\src\vssdk\VSIntegration\Tools\src\CreatePkgDef\CreatePkgDef.cs:line 261
   at Microsoft.VisualStudio.Tools.CreatePkgDef.DoCreatePkgDef(InputArguments inputArguments) in F:\dd\src\vssdk\VSIntegration\Tools\src\CreatePkgDef\CreatePkgDef.cs:line 164
   at Microsoft.VisualStudio.Tools.CreatePkgDef.Main(String[] arguments) in F:\dd\src\vssdk\VSIntegration\Tools\src\CreatePkgDef\CreatePkgDef.cs:line 85
Could not load file or assembly 'Microsoft.VisualStudio.Shell.15.0, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.VisualStudio.Shell.15.0, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.VisualStudio.Shell.15.0, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

再次强调,最新更改已在GitHub上的源代码中推送到AddVs2017Support分支,供任何想查看代码并尝试发现问题的人参考。


更新2

我也尝试了重置Visual Studio 2017实验实例,以及在我的常规(非实验性)VS 2017实例上安装vsix,但仍然会出现找不到程序集的相同错误。

如果我手动将dll文件复制到C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE目录中,则可以找到它,并且不再出现错误。 我只是不确定为什么Visual Studio没有在我的扩展目录中查找它,当确实存在完全相同的文件时。


https://learn.microsoft.com/en-us/visualstudio/extensibility/breaking-changes-2017#change-global-assembly-cache-gac - Hans Passant
感谢@HansPassant提供的链接。我尝试按照建议添加.pkgdef文件,但仍然存在问题。我已经更新了我的帖子,并提供了更多来自该过程的信息。 - deadlydog
4个回答

5
你可以尝试在你的VSIX项目的AssemblyInfo.cs中添加以下代码:
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\QuickConverter.dll")]

我尝试并成功地使用了VS 2017更新7。


这应该是首选答案,至少对于VS 2017而言。手动添加到.pkgdef文件中的等效数据也可以起作用。感谢您消除了所有错误信息。 - mcurland
这适用于VS 2019,由于某种原因,其他开发者的机器需要这个,但我的机器不需要,唯一的区别是我有VS企业版,而他们只有专业版。 - Jack_2060

5
我遇到了类似的情况,并且遇到了相同的错误和融合日志结果。为了找到问题的根源,我最终在实验性实例中启用了活动日志记录,同时进行调试。因此,在VSIX项目的调试设置中,将启动参数更改为“/rootsuffix Exp /log”。
调试扩展并重现问题。
然后检查活动日志文件:C:\Users\%username%\AppData\Roaming\Microsoft\VisualStudio\15.0_796eceb7Exp\ActivityLog.xml
在我的特定情况下,我正在使用具有向导扩展的项目模板。在项目的 .vstemplate 文件中,有一个魔术字符串,其中包含向导实现的命名空间和类名。我已经重命名了类,但没有更新模板中的字符串。

谢谢你的提示。我已经这样做了,它确实导致了一些错误被记录下来,但是没有一个与我的Diff All Files扩展相关,所以我不确定它们是否与我的问题有关。我在MSDN上找到了一篇帖子,提到了与我看到的ActivityLog.xml文件中相同的错误 https://social.msdn.microsoft.com/Forums/vstudio/en-US/94e7a537-12d6-470b-92e4-b370063f28df/error-input-string-is-not-in-correct-format-when-trying-to-create-cloud-service-in-visual-studio?forum=vssetup 不幸的是,我仍然不确定如何解决我的问题。 - deadlydog

0
经过几天的研究,我最终在VS 2017上解决了它。 总体问题实际上是Visual Studio在错误的位置寻找程序集。之前我怀疑签名有问题,但签名并不是问题所在。 我的VSIX/Wizard程序集已包含在VSIX中,但安装后,VS并未找到它。如果你查看C:\Users\Username\AppData\Local\Microsoft\VisualStudio\15.0_ff857330Exp\Extensions文件夹,你会发现程序集就在那里。 看起来VS只是没有在那里搜索。
因此解决方案是设置“安装根目录”属性。
1. 在Visual Studio中选择你的VSIX项目,进入属性窗口。 2. 在“VSIX”选项卡下,将“Install root”从“Default”更改为例如“PublicAssemblies”(你也可以选择其他选项,但PublicAssemblies效果很好)。 3. 然后你需要编辑source.extension.vsixmanifest,并设置“This VSIX is installed for all users”。否则,你将无法使用更改的安装目录构建。

清单中引用的程序集将在 VSIX 安装时复制到位置 C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\PublicAssemblies,这样当使用已安装的模板时,它们就可以轻松地被找到。据我所知,没有其他方法可以更改默认安装路径或在没有提升权限的情况下执行此操作。

希望这个答案能为您节省数天的研究和尝试。


0

我从未能确定这个问题的根本原因。我最初所做的是在Visual Studio中创建一个新的VS2017 VSIX项目,然后将我的所有文件从VS2015 VSIX项目中包含进去,这就是我遇到这个错误的时候。

最终对我有用的方法是删除那个VS2017项目,而是只复制粘贴我现有的VS2015项目,然后将.csproj和其他文件重命名为2017而不是2015。然后我在VS 2017中打开了该项目,并让它进行升级迁移,然后更新了vsixmanifest文件以支持VS 2017。一旦完成了这些操作,事情就像预期的那样工作了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接