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

dea*_*dog 5 .net assemblybinding visual-studio visual-studio-2017

我正在尝试更新我的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.
Run Code Online (Sandbox Code Playgroud)

我已确认该文件存在于C:\Users\Dan.Schroeder\AppData\Local\Microsoft\VisualStudio\15.0_b920d444Exp\Extensions\DansKingdom\Diff All Files for VS2017\1.0\QuickConverter.dll并且它具有正确的名称和公钥。

我还捕获了Fusion Logs(即Assembly Binding Log Viewer)来捕获绑定错误,看来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.
Run Code Online (Sandbox Code Playgroud)

关于为什么 VS 没有在正确的位置加载该程序集的任何想法?或者还有什么我想念的吗?

I did not run into this issue when developing the extension for VS 2012, 2013, or 2015. I'm debugging the Visual Studio Extension by providing the rootsuffix Exp command line argument, just like I did for previous Visual Studio versions.

If you want, you can download the source code and reproduce the issue for yourself (it's the AddVs2017Support branch); just unload all projects except the VS.DiffAllFiles and VS.DiffAllFiles.VS2017 projects.

Any thoughts/suggestions are appreciated. Thanks.


Update 1

As per the link that Hans Passant provided, I tried adding a .pkgdef file to my project and including it as an asset in my .vsixmanifest file, but the problem still remains. When I look in the C:\Users\Dan.Schroeder\AppData\Local\Microsoft\VisualStudio\15.0_b920d444Exp\devenv.exe.config file I still do not see any reference to my assemblies, so it doesn't seem to be adding anything to that file as it should. Also, the fusion logs still report the exact same information as I provided above.

When I try to generate the .pkgdef file manually (since it should be done automatically as part of the build process), I get the following error. I'm not sure if this is to be expected or not when trying to generate it outside of Visual Studio (I was just using a regular command prompt).

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.
Run Code Online (Sandbox Code Playgroud)

Again, these latest changes have been pushed to the source code on GitHub under the AddVs2017Support branch for anyone who cares to take a look at the code to try and spot the problem.


Update 2

I also tried Resetting The Visual Studio 2017 Experimental Instance, as well as installing the vsix on my regular (non-experimental) VS 2017 instance, but it still results in the same error about not being able to find the assembly.

If I manually copy the dll file to the C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE directory then it is found and I no longer get the error. I'm just not sure why Visual Studio is not looking for it in my extensions directory, when the exact same file does indeed exist there.

Jas*_*mer 5

我遇到了类似的情况,并得到了相同的错误和融合日志结果。为了找到问题的根源,我最终所做的就是在调试时在实验实例中启用活动日志记录。因此,在 VSIX 项目的调试设置中,将启动参数更改为“/rootsuffix Exp /log”。

调试扩展并重现问题。

然后检查活动日志文件:C:\Users\%username%\AppData\Roaming\Microsoft\VisualStudio\15.0_796eceb7Exp\ActivityLog.xml

在我的特定实例中,我使用带有向导扩展的项目模板。在项目的 .vstemplate 文件中,有一个神奇的字符串,其中包含向导实现的命名空间和类名。我已重命名该类,但没有更新模板中的字符串。


小智 5

您可以尝试在 VSIX 项目的 AssemblyInfo.cs 中添加以下代码:

[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\QuickConverter.dll")]
Run Code Online (Sandbox Code Playgroud)

我尝试使用 VS 2017 更新 7 并且效果很好。


dea*_*dog 0

我始终无法确定这个问题的根本原因。我最初所做的是在 Visual Studio 中创建一个新的 VS2017 VSIX 项目,然后将 VS2015 VSIX 项目中的所有文件包含在其中,就在那时我遇到了此错误。

最终对我有用的是删除该 VS2017 项目,而只是复制粘贴现有的 VS2015 项目,然后将 .csproj 和其他文件重命名为 2017 而不是 2015。然后我在 VS 2017 中打开该项目并让它进行升级迁移,然后更新 vsixmanifest 文件以支持 VS 2017。完成后,一切都会按预期进行。