visual-studio-extensions

Visual Studio Extension using external library produces "Could not load file or assembly" at runtime


I have a basic Solution as per below:

enter image description here

I have setup the Solution Properties so that VisGit depends on VisGit.Core. VisGit.Core has also been imported as a library into VisGit. It compiles fine with no errors. However, when I try to run it in the VS test environment, I get:

Could not load file or assembly 'VisGit.Core, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

I'm guessing its not building the VisGit.Core lib to the relevant test environment location? Not sure how to check that. What I've tried:

  1. Adding below to VisGit.AssemblyInfo.cs
[assembly: ProvideCodeBase(AssemblyName = "VisGit.Core")]
  1. The usual clean, delete bin/obj, restart VS stuff.

  2. Adding VisGit.Core to vsixmanifest>Assets

No joy. Any advice would be appreciated.

Github code here

UPDATE: I've also found where the temp extension is built to. VisGit.Core is clearly there:

enter image description here

UPDATE 2: Looks like VS is looking for the library in the wrong place? Ran fuslogvw.exe and got the following:

*** Assembly Binder Log Entry  (20/06/2024 @ 18:39:07) ***

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

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\devenv.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = VisGit.Core, PublicKeyToken=null
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: VisGit.Core, PublicKeyToken=null | 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/Microsoft Visual Studio/2022/Community/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\stigz\AppData\Local\Microsoft\VisualStudio\17.0_83cd348aExp\devenv.exe.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\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/Microsoft Visual Studio/2022/Community/Common7/IDE/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/VisGit.Core/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PublicAssemblies/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PublicAssemblies/VisGit.Core/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PrivateAssemblies/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PrivateAssemblies/VisGit.Core/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/TestWindow/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/TestWindow/VisGit.Core/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Platform/Debugger/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Platform/Debugger/VisGit.Core/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PrivateAssemblies/DataCollectors/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PrivateAssemblies/DataCollectors/VisGit.Core/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PrivateAssemblies/DataCollectors/x64/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PrivateAssemblies/DataCollectors/x64/VisGit.Core/VisGit.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/VisGit.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/VisGit.Core/VisGit.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PublicAssemblies/VisGit.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PublicAssemblies/VisGit.Core/VisGit.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PrivateAssemblies/VisGit.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PrivateAssemblies/VisGit.Core/VisGit.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/TestWindow/VisGit.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/TestWindow/VisGit.Core/VisGit.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Platform/Debugger/VisGit.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Platform/Debugger/VisGit.Core/VisGit.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PrivateAssemblies/DataCollectors/VisGit.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PrivateAssemblies/DataCollectors/VisGit.Core/VisGit.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PrivateAssemblies/DataCollectors/x64/VisGit.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/PrivateAssemblies/DataCollectors/x64/VisGit.Core/VisGit.Core.EXE.
LOG: All probing URLs attempted and failed.

Solution

  • From looking at your solution tree diagram, it seems that VisGit.Core.dll file is placed separately at the project VisGit's root level.

    How do you setup VisGit to reference VisGit.Core? Please check your VisGit.csproj file to see whether the VisGit.Core.dll was successfully referenced.

    <Reference>xxx\xxx\VisGit.Core.dll</Reference>
    

    If no .dll file referenced, please try to use Add Reference to use external library by right clicking VisGit project->Add->Reference.

    1.Add Project Reference

    enter image description here

    2.Add Assemblies

    enter image description here

    After doing that, you can see references from here:

    enter image description here

    For more information, please refer to doc:Add or remove references

    Hope it can help you.

    UPDATE I have found a similar error information from this ticket

    There’s another tricky thing. Because you don’t use any classes in the Material Design assemblies, your script assembly doesn’t load those assemblies. It’s the XAML parser that uses the Material Design assemblies and therefore tries to load them. The problem is that, because it’s not your assembly that loads them, .NET looks for the Material Design assemblies in the wrong place.

    Please try to modify the code like this to see if the issue persists:

    using VisGit.Core.ViewModels;
    
    namespace VisGit.Views
    {
        public partial class MainView : UserControl
        {
            public MainView()
            {
                InitializeMaterialDesign();
                InitializeComponent();
            }
            private void InitializeMaterialDesign()
            {
                
                var modelDemo = new MainViewModel();
            }