I'm working on a little project in VS2015 for the company I work for, and as a company policy, all assemblies we produce must be signed.
I found a little odd behavior when I added a dependency to a nuget package that contained an unsigned assembly. When building the project with vs2015, I get the warning:
CSC : warning CS8002: Referenced assembly 'XXX, Version=A.B.C.D, Culture=neutral, PublicKeyToken=null' does not have a strong name.
That seemed strange when I first saw it, because I remembered that it didn't compile in VS2013 or earlier. In fact, I get the following error when building the same project in vs2013:
CSC : error CS1577: Assembly generation failed -- Referenced assembly 'XXX' does not have a strong name.
I thought that maybe something had changed in the runtime, and this was now supported. I couldn't be more wrong. When running my code built with warnings in VS2015, I now get a runtime error. The exact exception I get is a FileLoadException
with message
Could not load file or assembly 'XXX, Version=A.B.C.D, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)
I'm aware that there are some nuget packages out there that sign any unsigned dependency before build (like this one, or this other, or this last one).
My questions here are: Is there any way that referencing an unsigned assembly from a signed one could work, and I'm missing something? If not, why then this is now a compiler warning, if it's going to give a runtime error later?
Thanks in advance
Referencing unsigned assembly from signed is ok on some platforms (like CoreCLR). The compiler doesn't know what platform are you going to run on hence it no longer reports an error. We still report a warning since you might run into problems as you did on Desktop CLR.
User contributions licensed under CC BY-SA 3.0