brutaldev / StrongNameSigner

Strong-name sign third party .NET assemblies without the source code.
https://brutaldev.com/post/net-assembly-strong-name-signer
Other
327 stars 68 forks source link

Assembly reference not rewritten in XAML/BAML #31

Closed JVimes closed 2 years ago

JVimes commented 7 years ago

I think I found an assembly reference that's not being rewritten by StrongNameSigner, and I may know where it is.

Repro steps:

  1. Create a new "WPF Custom Control Library" project (not to be confused with "WPF User Control Library").
  2. Build it.
  3. Close the solution.
  4. Create a new "WPF Application" project.
  5. Configure the project for strong name signing (project settings > signing > etc.)
  6. Add a project reference to the custom control library DLL, built above.
  7. Add the Strong Name Signer nuget package to the project.
  8. In MainWindow.xaml, replace the grid tag with this (the xmlns value assumes the above DLL and it's .NET namespace are WpfCustomControlLibrary1, so doctor it if necessary):
    <Grid xmlns:mylib="clr-namespace:WpfCustomControlLibrary1;assembly=WpfCustomControlLibrary1">
        <mylib:CustomControl1/>
    </Grid>
  9. Build and run.

Expected: The application runs. Actual: It throws an exception, "FileLoadException: Could not load file or assembly 'WpfCustomControlLibrary1, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)".

I may know where the un-rewritten reference is. I think it's an assembly self-reference in WpfCustomControlLibrary1.dll. That DLL contains a "generic.baml" resource (compiled from themes\generic.xaml in the project), and when I view it with dnSpy, there is a reference to the baml's own DLL, but with a null PublicKeyToken. I had to enable dnSpy's option: "View > Options > BAML decompiler > Disassemble BAML" to see the PublicKeyToken.

image

Edit: Looks like normal references (across assemblies) also aren't rewritten in XAML/BAML. Guessing XAML isn't yet supported.

pp111 commented 7 years ago

Hello, I am having the same problem. Did you find a solution for this?

brutaldev commented 7 years ago

Not yet, no time for this project at the moment.

C1rdec commented 6 years ago

Any news on this issue? Here is a simple repo: https://github.com/C1rdec/MaterialDesignStrongName

brutaldev commented 2 years ago

Official release: https://www.nuget.org/packages/Brutal.Dev.StrongNameSigner/3.1.0