Can't debug VSIX project: "Expected export ITextEditorFactoryService but found 0"
Asked Answered
T

2

7

I am working in a couple of VSIX projects and suddenly, for some reason, I can't properly debug them. When I run the project, the experimental VS instance opens without issues, but as soon as I load a solution the problems begin.

To start with, if the solution I'm loading is under source control I get the following error message:

The 'GitCollaborationPackage' package did not load correctly. The problem may have been caused by a configuration change or by the installation of another extension.

There's also a link to a log file, which shows an apparently not very useful error message:

LegacySitePackage failed for package [GitCollaborationPackage] Source: "" Description: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

After that the solution loads, but as soon as I try to open a file I get this error:

Expected 1 export(s) with contract name "Microsoft.VisualStudio.Text.Editor.ITextEditorFactoryService" but found 0 after applying applicable constraints.

I didn't perform any significant change in my projects, but just in case I created a fresh new VSIX project and ran it right away, with identical results.

As suggested in MSDN I tried to delete Visual Studio's component cache and reset Visual Studio's settings, to no avail.

So what's going on here? What can I do to fix this?

UPDATE: A couple of new findings:

  • When running Visual Studio with devenv /safemode the problem persists.
  • This is happening in VS Professional edition. I have Community edition installed as well, and in that one I can debug without issues. Damn, that one got somehow corrupted too! :-(

UPDATE 2: Repairing Visual Studio didn't help.

Tweedsmuir answered 15/9, 2017 at 7:42 Comment(4)
Hey =) Hope you are enjoying the new job! Are you able to share or host the code so I could try to reproduce on my end?Reunite
@Reunite Helloooos! Nice to see that you are still a functional human being. I managed to fix that but I don't know how. I just created a new solution, moved everything there, was still not working, went back to the original solution and then it worked. "The project of Schrodinger" I guess.Tweedsmuir
I'm experiencing this same exact issue. I have not yet found a resolution. Hoping someone else out there has. If I discover something, I'll post an answer. Thanks for posting this question!Admirable
Restoring the vanilla VSIX Adornment Project Template code, I was able to debug. Then I modified the sample code to resemble my extension's method calls while maintaining the original functionality of the sample adornment extension. Everything worked just fine. But, then running my code, it still presented me with the above error. It's something with the way the extension is authored, but I still haven't nailed it down; and the error message is next to useless. Esp. since the docs for ITextEditorFactoryService say this should be [Import]ed, but VS wants an [Export].Admirable
T
0

This is not an answer, but it's been two years and the problem remains serious, so I thought it might be worthwhile to add some detail for the sake of future investigation.

On my machine the experimental instance was working earlier today, but now it fails. The initial error most often reads

The 'RoslynPackage' package did not load correctly. The problem may have been caused by a configuration change or by the installation of another extension. You can get more information by examining the file 'C:\Users...\AppData\Roaming\Microsoft\VisualStudio\15.0_b0b65856Exp\ActivityLog.xml'.

But the failing package occasionally varies, and in any case the second error (involving ITextEditorFactoryService) soon follows.

Deleting the two VisualStudio\15.0_b0b65856Exp folders in AppData doesn't help, so I tried uninstalling and reinstalling VS2017. That didn't help either.

I tried debugging a "known good" Visual Studio extension. Same error. I tried loading a simple text file. Same error.

So I moved on to Visual Studio 2019 Community (which was already installed before the failures started). VS 2019 fails too, but its behavior is slightly different: the first error message does not appear, and the second error is slightly modified (notice the "2"):

Expected 1 export(s) with contract name "Microsoft.VisualStudio.Text.Editor.ITextEditorFactoryService2" but found 0 after applying applicable constraints.

I noticed that when I reinstalled VS2017, it still picked up on settings left over from the previous installation. And when the experimental instance starts, it asks me which theme I want. I tell it to use the Blue Theme, and for a few seconds it does, but then it loads Dark Theme which is the same theme used by the main instance. This leads to a hypothesis that the failure is caused by a "zombie" configuration setting that the experimental instance is choosing to load, a setting we just don't know how to get rid of. However, I tried dragging a .cs file onto the experimental instance immediately (before the dark theme loads) and the error still occurs. Also, I tried Tools -> Import and Export Settings -> Reset all Settings (inside the experimental instance), which didn't help.

In my case the command-line arguments /rootsuffix Exp /safemode prevent the error from happening, but this is useless because it also blocks the VSIX I'm trying to debug from loading.

Here are the entries in ActivityLog.xml that mention the word "error":

  <entry>
    <record>523</record>
    <time>2020/03/11 00:20:56.182</time>
    <type>Warning</type>
    <source>VisualStudio</source>
    <description>Unexpected system error mode before loading package [ProviderPackage]</description>
    <guid>{5F2E5E42-4192-4D79-A0D8-1D881E808829}</guid>
  </entry>

  <entry>
    <record>527</record>
    <time>2020/03/11 00:20:56.494</time>
    <type>Warning</type>
    <source>VisualStudio</source>
    <description>Unexpected system error mode before loading package [Microsoft.VisualStudio.Shell.Connected.Packages.PathTrustVerifier.PathTrustVerifierPackage]</description>
    <guid>{2F6B5046-3BB0-4825-B344-3F4238921119}</guid>
  </entry>

  <entry>
    <record>531</record>
    <time>2020/03/11 00:20:56.511</time>
    <type>Warning</type>
    <source>VisualStudio</source>
    <description>Unexpected system error mode before loading package [CSharpPackage]</description>
    <guid>{13C3BBB4-F18F-4111-9F54-A0FB010D9194}</guid>
  </entry>

  <entry>
    <record>534</record>
    <time>2020/03/11 00:20:56.590</time>
    <type>Warning</type>
    <source>VisualStudio</source>
    <description>Unexpected system error mode before loading package [RoslynPackage]</description>
    <guid>{6CF2E545-6109-4730-8883-CF43D7AEC3E1}</guid>
  </entry>

  <entry>
    <record>537</record>
    <time>2020/03/11 00:20:56.811</time>
    <type>Warning</type>
    <source>VisualStudio</source>
    <description>Unexpected system error mode before loading package [ErrorListPackage]</description>
    <guid>{4A9B7E50-AA16-11D0-A8C5-00A0C921A4D2}</guid>
  </entry>

  <entry>
    <record>541</record>
    <time>2020/03/11 00:20:57.014</time>
    <type>Warning</type>
    <source>VisualStudio</source>
    <description>Unexpected system error mode before loading package [Text Management Package]</description>
    <guid>{F5E7E720-1401-11D1-883B-0000F87579D2}</guid>
  </entry>

  <entry>
    <record>545</record>
    <time>2020/03/11 00:20:57.026</time>
    <type>Warning</type>
    <source>VisualStudio</source>
    <description>Unexpected system error mode before loading package [Microsoft.VisualStudio.Editor.Implementation.EditorPackage]</description>
    <guid>{E269B994-EF71-4CE0-8BCD-581C217372E8}</guid>
  </entry>

  <entry>
    <record>548</record>
    <time>2020/03/11 00:20:57.457</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>LegacySitePackage failed for package [RoslynPackage]Source: &apos;Microsoft.VisualStudio.Composition&apos; Description: Expected 1 export(s) with contract name &quot;Microsoft.VisualStudio.LanguageServices.Implementation.TableDataSource.VisualStudioDiagnosticListTableCommandHandler&quot; but found 0 after applying applicable constraints.&#x000D;&#x000A;Microsoft.VisualStudio.Composition.CompositionFailedException: Expected 1 export(s) with contract name &quot;Microsoft.VisualStudio.LanguageServices.Implementation.TableDataSource.VisualStudioDiagnosticListTableCommandHandler&quot; but found 0 after applying applicable constraints.&#x000D;&#x000A;   at Microsoft.VisualStudio.Composition.ExportProvider.GetExports(ImportDefinition importDefinition)&#x000D;&#x000A;   at Microsoft.VisualStudio.Composition.ExportProvider.GetExports[T,TMetadataView](String contractName, ImportCardinality cardinality)&#x000D;&#x000A;   at Microsoft.VisualStudio.Composition.ExportProvider.GetExport[T,TMetadataView](String contractName)&#x000D;&#x000A;   at Microsoft.VisualStudio.Composition.ExportProvider.GetExport[T](String contractName)&#x000D;&#x000A;   at Microsoft.VisualStudio.Composition.ExportProvider.GetExport[T]()&#x000D;&#x000A;   at Microsoft.VisualStudio.Composition.ExportProvider.GetExportedValue[T]()&#x000D;&#x000A;   at Microsoft.VisualStudio.ComponentModelHost.ComponentModel.GetService[T]()&#x000D;&#x000A;   at Microsoft.VisualStudio.LanguageServices.Setup.RoslynPackage.LoadComponentsInUIContext()&#x000D;&#x000A;   at Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService.AbstractPackage.LoadComponentsInUIContextOnceSolutionFullyLoaded()&#x000D;&#x000A;   at Microsoft.VisualStudio.LanguageServices.Setup.RoslynPackage.Initialize()&#x000D;&#x000A;   at Microsoft.VisualStudio.Shell.Package.Microsoft.VisualStudio.Shell.Interop.IVsPackage.SetSite(IServiceProvider sp)</description>
    <guid>{6CF2E545-6109-4730-8883-CF43D7AEC3E1}</guid>
    <hr>80131500</hr>
    <errorinfo></errorinfo>
  </entry>

  <entry>
    <record>549</record>
    <time>2020/03/11 00:20:57.469</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>SetSite failed for package [RoslynPackage](null)</description>
    <guid>{6CF2E545-6109-4730-8883-CF43D7AEC3E1}</guid>
    <hr>80131500</hr>
    <errorinfo></errorinfo>
  </entry>

  <entry>
    <record>551</record>
    <time>2020/03/11 00:20:57.479</time>
    <type>Warning</type>
    <source>VisualStudio</source>
    <description>Unexpected system error mode before loading package [Visual Studio Component Enumerator Package]</description>
    <guid>{588205E0-66E0-11D3-8600-00C04F6123B3}</guid>
  </entry>

  <entry>
    <record>555</record>
    <time>2020/03/11 00:20:57.490</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>End package load [RoslynPackage]</description>
    <guid>{6CF2E545-6109-4730-8883-CF43D7AEC3E1}</guid>
    <hr>80131500</hr>
    <errorinfo></errorinfo>
  </entry>

Note: the above error is the final entry in ActivityLog.xml; The second error doesn't show up here.

Trike answered 11/3, 2020 at 0:25 Comment(1)
I'm experiencing this too. Damn, it is infuriating. I'll dive deeper, and I hope others have the answer too.Fade
F
0

For me, this started happening after using a IViewTaggerProvider instead of an IViewProvider. When changing it back, it works.

Not sure why though, and I really need to be able to use a IViewTaggerProvider, but I hope this lets others get more insight.

Edit: Okay, I solved it! It was due to the type in my Export attribute not matching the implemented type.

So I changed:

    [Export(typeof(ITaggerProvider))]
    [ContentType("code")]
    [TagType(typeof(ToDoTag))]
    class ToDoTaggerProvider : IViewTaggerProvider
    { ... }

Into:

    [Export(typeof(IViewTaggerProvider))]
    [ContentType("code")]
    [TagType(typeof(ToDoTag))]
    class ToDoTaggerProvider : IViewTaggerProvider
    { ... }
Fade answered 6/1, 2021 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.