Git Product home page Git Product logo

Comments (5)

brutaldev avatar brutaldev commented on July 17, 2024 1

I think you'll have a lot more luck with v3.3.0.

In your project file you need to remove the target imports and use your own custom one to just sign DYMO.Connect.SDK.

  1. Install the latest NuGet package (https://www.nuget.org/packages/Brutal.Dev.StrongNameSigner/3.3.0).
  2. Remove the following lines from your .csproj file:
<Error Condition="!Exists('..\packages\Brutal.Dev.StrongNameSigner.X.Y.Z\build\Brutal.Dev.StrongNameSigner.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Brutal.Dev.StrongNameSigner.X.Y.Z\build\Brutal.Dev.StrongNameSigner.targets'))" />
...
<Import Project="..\packages\Brutal.Dev.StrongNameSigner.X.Y.Z\build\Brutal.Dev.StrongNameSigner.targets" Condition="Exists('..\packages\Brutal.Dev.StrongNameSigner.X.Y.Z\build\Brutal.Dev.StrongNameSigner.targets')" />
  1. Add the following into your .csproj file inside the <Project> element:
  <Target Name="BeforeCompile">
    <Exec ContinueOnError="false"
          Command="&quot;..\packages\Brutal.Dev.StrongNameSigner.3.3.0\build\StrongNameSigner.Console.exe&quot; -in &quot;..\packages\DYMO.Connect.SDK.1.4.3.37&quot; -k UnprotectedKey.snk" />
  </Target>
  1. Reload your project and build.

In your test project this builds just fine with no errors/warnings:

  Rebuild started...
1>------ Rebuild All started: Project: DYMOSDKSampleForSNS, Configuration: Debug Any CPU ------
1>  -------------------------------------------------------------------
1>  ---- Brutal Developer .NET Assembly Strong-Name Signer 3.3.0.0 ----
1>  -------------------------------------------------------------------
1>  Console application to sign .NET assemblies with a strong-name key and fix assembly references.
1>  1. Loading assemblies...
1>     Unsupported assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x64\libdymobarcode.dll': Format of the executable (.exe) or library (.dll) is invalid.
1>     Unsupported assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x64\usps4cb.dll': Format of the executable (.exe) or library (.dll) is invalid.
1>     Unsupported assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x86\libdymobarcode.dll': Format of the executable (.exe) or library (.dll) is invalid.
1>     Unsupported assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x86\usps4cb.dll': Format of the executable (.exe) or library (.dll) is invalid.
1>  2. Checking assembly references...
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\DYMO.Common.dll'.
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\DYMO.CrossPlatform.Common.dll'.
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\DYMO.LabelAPI.dll'.
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\OSX\platspec\DYMO.CrossPlatform.Common.PlatformSpecific.dll'.
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\OSX\platspec\DYMO.LabelAPI.PlatformSpecific.dll'.
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\Win\DYMO.CrossPlatform.Common.PlatformSpecific.dll'.
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\Win\DYMO.LabelAPI.PlatformSpecific.dll'.
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x64\DYMOPrinting.dll'.
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x64\LW5xxCommunicationLibrary.dll'.
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x64\PrintingSupportLibrary.dll'.
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x86\DYMOPrinting.dll'.
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x86\LW5xxCommunicationLibrary.dll'.
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x86\PrintingSupportLibrary.dll'.
1>     Checking assembly references in 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\lib\netstandard2.0\DymoSDK.dll'.
1>  3. Strong-name unsigned assemblies...
1>     Signing assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\DYMO.CrossPlatform.Common.dll'.
1>     Signing assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\DYMO.LabelAPI.dll'.
1>     Signing assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\OSX\platspec\DYMO.CrossPlatform.Common.PlatformSpecific.dll'.
1>     Signing assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\OSX\platspec\DYMO.LabelAPI.PlatformSpecific.dll'.
1>     Signing assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\Win\DYMO.CrossPlatform.Common.PlatformSpecific.dll'.
1>     Signing assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\Win\DYMO.LabelAPI.PlatformSpecific.dll'.
1>     Signing assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x64\DYMOPrinting.dll'.
1>     Signing assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x86\DYMOPrinting.dll'.
1>     Signing assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\lib\netstandard2.0\DymoSDK.dll'.
1>  4. Fix InternalVisibleToAttribute references...
1>     Fixing DYMO.LabelAPI.PlatformSpecific friend reference in assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\DYMO.LabelAPI.dll'.
1>  5. Fix BAML references...
1>     Replacing BAML entry in assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\Win\DYMO.LabelAPI.PlatformSpecific.dll'.
1>  6. Save assembly changes...
1>     Saving changes to assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\DYMO.CrossPlatform.Common.dll'.
1>     Saving changes to assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\DYMO.LabelAPI.dll'.
1>     Saving changes to assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\OSX\platspec\DYMO.CrossPlatform.Common.PlatformSpecific.dll'.
1>     Saving changes to assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\OSX\platspec\DYMO.LabelAPI.PlatformSpecific.dll'.
1>     Saving changes to assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\Win\DYMO.CrossPlatform.Common.PlatformSpecific.dll'.
1>     Saving changes to assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\Win\DYMO.LabelAPI.PlatformSpecific.dll'.
1>     Saving changes to assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x64\DYMOPrinting.dll'.
1>     Failed to save assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x64\DYMOPrinting.dll': Writing mixed-mode assemblies is not supported
1>     Saving changes to assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x86\DYMOPrinting.dll'.
1>     Failed to save assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\Build\DYMOLib\x86\DYMOPrinting.dll': Writing mixed-mode assemblies is not supported
1>     Saving changes to assembly 'C:\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\lib\netstandard2.0\DymoSDK.dll'.
1>  7. Cleanup...
1>  DYMOSDKSampleForSNS -> C:\DYMOSDKSampleForSNS\DYMOSDKSampleForSNS\bin\Debug\DYMOSDKSampleForSNS.dll
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
========== Elapsed 00:02.623 ==========

You can note the mixed-mode assemblies that are not supported, those are likely the ones being dynamically loaded. You can test this out in your real project and see if it works.

from strongnamesigner.

brutaldev avatar brutaldev commented on July 17, 2024

Please provide the log output from the signing process. You can also provide the log output when using the user interface/console application for the assemblies that get ignored (mixed-mode or native I suspect).

Do you have a sample project or is it just a basic project that brings in the DYMO.Connect.SDK NuGet package?

I've mostly already worked around my problem by not signing my class library project

Why not just leave things unsigned, is there is a specific reason you need to actually strong-name sign your project?
Unsigned assemblies can use signed assemblies but not the other way around (which is what this tool was created for). If you do not need to sign your own stuff then don't worry about trying to sign others.

from strongnamesigner.

HiddenDude avatar HiddenDude commented on July 17, 2024

I have made a quick VS2022 sample project for it and attached it.
(but I had to exclude the actual packages from the zip because of upload size limitations, but they are fresh from the store)

DYMOSDKSampleForSNS.zip

Just a basic .NET Framework class library targeting .NET Framework 4.7.2 with the "DYMO.Connect.SDK" (+ dependencies) and "Brutal.Dev.StrongNameSigner" NuGet packages added, and maybe some short code to initialize the SDK.

The output directory looks complete like that and reproduces the error in my application.

The log from the build process (including SNS notifications) is this - is this log sufficient or did I miss anything?:

------ Build started: Project: DYMOSDKSampleForSNS, Configuration: Debug Any CPU ------
  -- Starting Brutal Developer .NET Assembly Strong-Name Signer Task --
  Adding 'C:\Users\user\Desktop\Projects\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\lib\netstandard2.0\DymoSDK.dll' for processing.
  Adding 'C:\Users\user\Desktop\Projects\DYMOSDKSampleForSNS\packages\SkiaSharp.1.68.0\lib\net45\SkiaSharp.dll' for processing.
  Checking assembly references in 'C:\Users\user\Desktop\Projects\DYMOSDKSampleForSNS\packages\DYMO.Connect.SDK.1.4.3.37\lib\netstandard2.0\DymoSDK.dll'.
  Checking assembly references in 'C:\Users\user\Desktop\Projects\DYMOSDKSampleForSNS\packages\SkiaSharp.1.68.0\lib\net45\SkiaSharp.dll'.
  -- Finished Brutal Developer .NET Assembly Strong-Name Signer Task in 00:00:00.7031904 -- 
  DYMOSDKSampleForSNS -> C:\Users\user\Desktop\Projects\DYMOSDKSampleForSNS\DYMOSDKSampleForSNS\bin\Debug\DYMOSDKSampleForSNS.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Elapsed 00:01,503 ==========

It looks like the StrongNameSigner is not even doing that much there.
(the 2 DLLs that it checks are already signed by default if the SDK NuGet package is left unmodified)

But the problematic DLLs seem to be in the "Build" directory of the "DYMO.Connect.SDK" package.
(and those DLLs also are part of the dependency tree of the SDK DLLs. And they also flow into the output directory)
E.g. "DYMO.CrossPlatform.Common.dll".
(DYMO.CrossPlatform.Common, Version=1.4.3.37, Culture=neutral, PublicKeyToken=null)
As far as I can see (with ILspy), the signed "DymoSDK.dll" references it.
(DymoSDK, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8cbe8a3c50c5633e)
Thats what actually is inside the Build directory, but we would need to sign it and fix the reference inside DymoSDK.dll to also point at that signed assembly for my application to not complain because my signed DLL is using unsigned dependencies.

I'm not sure how you could reproduce the actual error with this sample project as I'm actually using the class library as an interop "addin" inside Microsoft Dynamics NAV and talk to the DLL using C/AL code.. Not sure if the same error would appear when trying anything (e.g. call GetPrinters()) from a e.g. WinForms app thats using the DLL.

In my opinion it would be OK to "re-sign" DymoSDK.dll with a new key if necessary to fix the unsigned references.
(but the tool would first have to try to do something with DYMO.CrossPlatform.Common.dll?)

Let me know if you need more information.

Edit
Added code block around the log to make it more readable.

from strongnamesigner.

HiddenDude avatar HiddenDude commented on July 17, 2024

I've overlooked your additional response in the quote box:

Why not just leave things unsigned, is there is a specific reason you need to actually strong-name sign your project?
Unsigned assemblies can use signed assemblies but not the other way around (which is what this tool was created for). If you do not need to sign your own stuff then don't worry about trying to sign others.

Thats what I'm doing as a workaround for now. Not sign my library = no errors.
Its just usually best practise for NAV DLLs to strong name sign them.
(otherwise there may be issues with deployment later on)
And I never had to not do it because of a 3rd party library. The DYMO SDK may be the first one.

Edit
Added a reason to adhere to the best practises in my case in brackets. But that would require using the signed dependency in my signed wrapper DLL. And it's dependencies also all need to be signed, but the SDK doesn't come like that from the vendor.
Somehow their signed main assembly is referencing some unsigned assemblies and no one ever noticed the error internally..
(if I just sign the unsigned assemblies - if it works - my app would no longer find the signed assembly at run time, so the references need to be correct as well)
Thats how I come across StrongNameSigner after reading a post with ildasm/ilasm commands to manually fix stuff like this.
It might not be a bug, but rather 1-2 new features to catch more of those DLLs (also in the VS build task as I'm not using the tools manually?) and also rewrite signed assemblies to fix references to previously unsigned assemblies after signing them - but you now have an example of a bad SDK to possibly harden the tool on. Its not critical for now. But I really like the idea of one automated tool to fix all DLL strong name signing related problems ;)

from strongnamesigner.

brutaldev avatar brutaldev commented on July 17, 2024

Somehow their signed main assembly is referencing some unsigned assemblies

They are probably dynamically loading them and not referencing them.
SNS can fix all of this, but if there is no hard reference then there is no way for it to know it also needs to sign these extra assemblies. You will need to specify the list of assemblies you want to sign and will not be able to easily use the automatic build task.

I'll look into this a bit later, I'm still on vacation.

from strongnamesigner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.