How to use class library in VsPackage

2

Following scenario. I have created in VS 2017 a new VSIX Project. There I have inserted a new Tool Window. Additionally I have created a class library. The resulting structure is as follows: Project Structure

The only thing I have change are

  • that I added two attributes to the ToolWindow1Package class so that it is loaded as soon as I load a solution

    [ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasSingleProject_string)]
    [ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasMultipleProjects_string)]
    
  • the Initialize method

    protected override void Initialize()
    {
        ToolWindow1Command.Initialize(this);
        base.Initialize();
        Class1 class1 = new Class1();
        Console.WriteLine(class1);
    }
    

When I load a solution the package cannot load with the following Entry in the ActivityLog

<entry>
   <record>1396</record>
   <time>2018/01/10 15:16:12.081</time>
   <type>Error</type>
   <source>VisualStudio</source>
   <description>LegacySitePackage failed for package [ToolWindow1Package]Source: &apos;TestExtension&apos; Description: Could not load file or assembly &apos;TestLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&apos; or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)&#x000D;&#x000A;System.IO.FileLoadException: Could not load file or assembly &apos;TestLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&apos; or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)&#x000D;&#x000A;File name: &apos;TestLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&apos;&#x000D;&#x000A;   at TestExtension.ToolWindow1Package.Initialize()&#x000D;&#x000A;   at Microsoft.VisualStudio.Shell.Package.Microsoft.VisualStudio.Shell.Interop.IVsPackage.SetSite(IServiceProvider sp)&#x000D;&#x000A;&#x000D;&#x000A;</description>
   <guid>{673860A0-BAF8-46CB-BDFD-F758C4C6EE3C}</guid>
   <hr>80131044</hr>
   <errorinfo></errorinfo>

The dll of the library is nonetheless in the folder of the extension dll:

Files

I even tried to add the library as an asset in the .vsixmanifest without a change in the situation. Does anyone know this problem and a workaround?

c#
visual-studio-2017
vs-extensibility
vspackage
fileloadexception
asked on Stack Overflow Jan 10, 2018 by Yggdrasil

1 Answer

3

You must strong sign the TestLibrary dll/project, as the error message says, by adding a key.snk file to the project. (Project properties, Signing)

answered on Stack Overflow Jan 10, 2018 by ErikEJ

User contributions licensed under CC BY-SA 3.0