Strongly naming a 3rd party assembly - Could not load file or assembly

让人想犯罪 __ 提交于 2019-12-03 03:15:26

I wrote a NuGet solution level package to help with strong naming 3rd party assemblies with your own key.

This is targeted for signing the contents of NuGet packages that are using unsigned assemblies, in order to be able to link to these packages where the consuming project is strongly named. Access to the original source code is not required, and you may sign any assembly with your own strong naming key. You may also delay-sign if desired.

https://nuget.org/packages/Nivot.StrongNaming

You can read more about it on my blog:

http://www.nivot.org/blog/post/2013/04/30/Signing-unsigned-assemblies-in-NuGet-packages

I tried to use RestSharp from VSPackage and it works. My steps to add RestSharp:

  1. Add RestSharp by NuGet in a project where I will use it. To do this, right-click on the project in Solution Explorer and selecting the “Manage NuGet Packages…”, find RestSharp and press Install button.

  2. Write test code in this project:

    
    var test = new RestSharp.RestClient("http://test.com");
    Logger.Log(Category.Info, "Test {0}", test.BaseUrl);
    
  3. Add RestSharp by NuGet in the installer project. Similarly paragraph 1. I use the VSIX Deployment Package. To set the necessary assembly just need to add a reference to assembly in the VSIX Deployment Package. This makes the “Manage NuGet Packages…” command. When you create a VSPackage by VS Wizard, the main project of VSPackage is VSIX Deployment Package.

    If you use another method of installation your VS extension (for example, MSI installer), you need to explicitly add RestSharp.dll to our installation package.

As a result, I got line "Test http://test.com" in the log.

Most likely in your case, that RestSharp.dll been not installed and therefore VS is not finding RestSharp.dll when loading your module. Or the fully qualified name of installed RestSharp assembly is different from the fully qualified name assembly in References of project. To see this check out whether RestSharp.dll file in folder of your extension (for VSPackage by default patch is "%LOCALAPPDATA%\MICROSOFT\VISUALSTUDIO\11.0EXP\EXTENSIONS\{YourCompanyName}\{YourProductName}\{YourProductVersion}\"). You can see the absolute path to your extension in the Modules window if run the extension under the debugger.

Edit: I just now noticed that the RestSharp assembly from NuGet has not a strong name. So the directory of installed extension and References of projects should contain the exact same assembly with a strong name, and everything will work fine.

A few things you can check:

It seems you project refrence is still to the unsigned dll .\RestSharp.dll. You should compile your project against the signed .\Signed\RestSharp.dll dll. Remove the current refrences and add the again.

Also check the dll in the bin directory of your project. It's possible the old RestSharp.dll is still there. Remove it and check all build directories.

You can also check if the restsharp.dll is in you GAC. If so remove the dll from your gac.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!