Could not load file or assembly 'System.Runtime.InteropServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

Darren Simpson 0 Reputation points
2023-10-05T16:24:56.1333333+00:00

Hi Guys,

Hope all's good!

I just installed the latest version of System.Runtime.InteropServices from nuget and I'm getting the above error which makes very little sense to me. Does anyone know how to resolve this?

Thanks

Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Tianyu Sun-MSFT 34,686 Reputation points Microsoft External Staff
    2023-10-06T09:00:12.3266667+00:00

    Hello @Darren Simpson,

    Welcome to Microsoft Q&A forum.

    Perhaps the corresponding version of the assembly was not installed correctly, but other projects/files which referred to it failed to try to load/find it.

    If you are using .NET Framework based project, please try to add <bindingRedirect> to the App.config file and check if it works. See this document: <bindingRedirect> Element for an example.

    If it doesn’t work, try following methods:

    1. Click Tools > NuGet Package Manager > Package Manager Settings > Clear All NuGet Storage > reinstall the corresponding version(4.0.0) of "System.Runtime.InteropServices" nuget package.
    2. Try to download the "System.Runtime.InteropServices" nuget package manually from here: System.Runtime.InteropServices, rename the downloaded .nupkg file to .zip. Unzip it and open it > open ref > dotnet folder > find the System.Runtime.InteropServices.dll file. Open Developer Command Prompt for Visual Studio > run cd xxxx to enter the folder which stores the .dll file(for example cd C:\system.runtime.interopservices.4.0.0\ref\dotnet), then run gacutil -i System.Runtime.InteropServices to install it into GAC(global assembly cache). Refer to this doc: How to: Install an assembly into the global assembly cache.
    3. Try to repair VS from VS Installer > More > Repair.
    4. If all above don’t work, I suggest considering reinstalling VS.

    Best Regards,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Darren Simpson 0 Reputation points
    2023-10-06T18:26:57.4166667+00:00

    Hi Tianyu,

    Hope all's well!

    Thanks for getting back to me. In the end I managed to fix this by

    1. Uninstalling System.Runtime.InteropServices 4.3 nuget package
    2. remove the binding redirect that was present in the web.config
    3. rebuild

    I did use Clear All Nuget Storage prior to all this - so thank you for that suggestion as I wasn't aware that was possible...whether it was pertinent to the above fix is unknown.

    Regards


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.