Why would I see “Unable to emit assembly: Referenc

2019-06-22 08:32发布

I'm wanting to include a system tray icon in my WPF project, and found this resource:

http://www.hardcodet.net/projects/wpf-notifyicon

which looks like it will work beautifully, but it's written for C# and I'm using VB.net for this project. I downloaded his project and built the notifyicon as a DLL, then added as a reference to my project.

It throws up an error:

Unable to emit assembly: Referenced assembly 'Hardcodet.Wpf.TaskbarNotification' does not have a strong name

So I'm trying to figure out the best way to proceed. Do I need to strong name it, or is there a better way to do this?

3条回答
\"骚年 ilove
2楼-- · 2019-06-22 09:17

This is a security constraint. Put simply, if you strongly-name your assembly, you are providing a guarantee to consumers of your assembly that only your assembly and its dependencies will be loaded at runtime. Malicious parties will not be able to replace your assembly with an impostor (unless they have your key, of course).

If your strongly-named assembly references weakly-named assemblies, that guarantee cannot be met because its dependencies could be substituted for impostors. That is why you're getting the compile error.

Your options are:

  1. Remove the strong name from your assembly.
  2. Strongly-name the third party code at compile-time. This is easy in your case because you're building from source.
  3. Strongly-name the third party binaries using ILMerge. This is an attractive option if you aren't building from source and the third party neglected to sign their assembly.
查看更多
混吃等死
3楼-- · 2019-06-22 09:18

In plain words, this means that you have a project named AssemblyA which references AssemblyB. AssemblyA is signed, AssemblyB is not.

You will have to decide either to also sign AssemblyB, or not sign AssemblyA.

查看更多
【Aperson】
4楼-- · 2019-06-22 09:24

You will need to add a strong name to the other assembly, or make your project not include a strong name.

Since you're already building it, you can just add a strong name in the project properties, and rebuild. Once you do that, it should work (without changing the code at all).

查看更多
登录 后发表回答