DLL Packing Issue

408 views
Skip to first unread message

Tom Ivy

unread,
Aug 24, 2024, 2:12:28 PM8/24/24
to Excel-DNA
Hello, I am facing a weird issue, or definitely doing something wrong!

I am using .Net framework 4.8 and ExcelDNA 1.8.

So the problem starts from the external DLLs which i have to pack with my XLL in order to work.

At first i tried via referencing my dlls to my .dna file but i have an issue there in which it requires metadata package 6.0.0.0! I install the package and the specific version via nuget but still receive the same error.

So after some digging and search i stumbled upon a conversation with similar problem and Govert replied with the solution below but it seems that whatever i do, the dlls are not get packed.

  <!-- Add the new target here -->
  <Target Name="PackedReferences" AfterTargets="AfterBuild" BeforeTargets="ExcelDnaBuild">
    <ItemGroup>
      <References Include="$(OutDir)*.dll" Exclude="$(OutDir)$(TargetFileName)"/>
    </ItemGroup>
    <PropertyGroup>
      <ExcelAddInInclude>@(References)</ExcelAddInInclude>
    </PropertyGroup>
  </Target>


I have also tried to modified it in various ways but does not seem to get the gist of it.


<Target Name="PackedReferences" AfterTargets="AfterBuild" BeforeTargets="ExcelDnaBuild">
  <ItemGroup>
    <References Include="$(OutputPath)Microsoft.Bcl.AsyncInterfaces.dll;
                          $(OutputPath)System.Buffers.dll;
                          $(OutputPath)System.Collections.Immutable.dll;
                          $(OutputPath)System.Memory.dll;
                          $(OutputPath)System.Numerics.Vectors.dll;
                          $(OutputPath)System.Runtime.CompilerServices.Unsafe.dll;
                          $(OutputPath)System.Text.Encodings.Web.dll;
                          $(OutputPath)System.Text.Json.dll;
                          $(OutputPath)System.Threading.Tasks.Extensions.dll;
                          $(OutputPath)System.ValueTuple.dll" />
  </ItemGroup>
  <PropertyGroup>
    <ExcelAddInInclude>@(References)</ExcelAddInInclude>
  </PropertyGroup>
</Target>


Furthermore i added the Message Text which i can see in my build log, but the dlls are not being packed.

<Target Name="PackedReferences" AfterTargets="AfterBuild" BeforeTargets="ExcelDnaBuild">
  <Message Text="PackedReferences target is running." Importance="high" />
  <PropertyGroup>
    <ExcelAddInInclude>
      ..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll;
      ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll;
      ..\packages\System.Collections.Immutable.1.7.1\lib\net461\System.Collections.Immutable.dll;
      ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll;
      ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll;
      ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll;
      ..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll;
      ..\packages\System.Text.Json.8.0.4\lib\net462\System.Text.Json.dll;
      ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll;
      ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll
    </ExcelAddInInclude>
  </PropertyGroup>
</Target>


What am i doing wrong here?

Govert van Drimmelen

unread,
Aug 24, 2024, 3:14:24 PM8/24/24
to exce...@googlegroups.com

Hi Tom,

 

Using the ExcelAddInInclude project property only works if you don’t have a .dna file in your project.

In that case, the Excel-DNA creates the .dna file in the output directory at build time, and applies the project properties.

If you have your own .dna file, that one is copied to the output directory unchanged.

When the build task runs, it uses the .dna file in the output directory.

In either case, you can check the .dna file in the output directory to see list of libraries we expect to pack.

Then the build output from the ExcelDnaPack task gives detailed information on what is actually packed into the .xll.

 

After sorting this out, you might still have the problem related to “metadata package 6.0.0.0”.

If so, maybe you can post a bit more details on how this fails.

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/70f84602-5ce2-4eb3-8ec0-7c8a60e096b8n%40googlegroups.com.

Tom

unread,
Aug 24, 2024, 4:14:39 PM8/24/24
to Excel-DNA
Hi Govert,

First of all thank you creating and publishing this library and the effort and time you put on this. :)

Okay now it makes sense why it would never include them.

Please find below more details and logs

DNA file:

<?xml version="1.0" encoding="utf-8"?>
<DnaLibrary Name="HVA_XLL Add-In" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2020/07/dnalibrary">
<!-- Main external library for your add-in -->
<ExternalLibrary Path="HVA_XLL.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" />

<!-- Added the necessary references -->
<Reference Path="Microsoft.Bcl.AsyncInterfaces.dll" Pack="true" />
<Reference Path="System.Buffers.dll" Pack="true" />
<Reference Path="System.Collections.Immutable.dll" Pack="true" />
<Reference Path="System.Memory.dll" Pack="true" />
<Reference Path="System.Numerics.Vectors.dll" Pack="true" />
<Reference Path="System.Runtime.CompilerServices.Unsafe.dll" Pack="true" />
<Reference Path="System.Text.Encodings.Web.dll" Pack="true" />
<Reference Path="System.Text.Json.dll" Pack="true" />
<Reference Path="System.Threading.Tasks.Extensions.dll" Pack="true" />
<Reference Path="System.ValueTuple.dll" Pack="true" />
<Reference Path="System.Reflection.Metadata.dll" Pack="true" />

</DnaLibrary>



Also among the things i tried was to also edited the app.config to include the metadata, the specified version

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup></configuration>


Nevertheless, whatever i try I always end up with the same error:

Build Log:

1>  ExcelDnaPack: bin\Debug\HVA_XLL-AddIn.dna -> bin\Debug\HVA_XLL-AddIn-packed.xll
1>  PackExcelAddIn: Using base add-in bin\Debug\HVA_XLL-AddIn.xll
1>  PackExcelAddIn:   ->  Updating resource: Type: CONFIG, Name: __MAIN__, Length: 4232
1>  PackExcelAddIn:   ~~> ExternalLibrary path HVA_XLL.dll resolved to bin\Debug\HVA_XLL.dll.
1>  PackExcelAddIn:   ~~> Assembly path Microsoft.Bcl.AsyncInterfaces.dll resolved to bin\Debug\Microsoft.Bcl.AsyncInterfaces.dll.
1>MSBUILD : PackExcelAddIn error DNA964120249: Could not load file or assembly 'System.Reflection.Metadata, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
1>MSBUILD : PackExcelAddIn error DNA964120249: System.IO.FileNotFoundException: Could not load file or assembly 'System.Reflection.Metadata, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.


Error Log:

Severity Code Description Project File Line Suppression State
Error Could not load file or assembly 'System.Reflection.Metadata, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. HVA_XLL
Error System.IO.FileNotFoundException: Could not load file or assembly 'System.Reflection.Metadata, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Reflection.Metadata, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at ExcelDna.PackedResources.ExcelDnaPack.IsAssembly(String path, Boolean& isPE)
   at ExcelDna.PackedResources.ExcelDnaPack.IsNativeLibrary(String path)
   at ExcelDna.PackedResources.ExcelDnaPack.PackDnaLibrary(String dnaPath, Byte[] dnaContent, String dnaDirectory, ResourceUpdater ru, Boolean compress, Boolean multithreading, List`1 filesToPublish, Boolean packManagedDependencies, String[] dependenciesToExcludeParam, String outputBitness, IBuildLogger buildLogger)
   at ExcelDna.PackedResources.ExcelDnaPack.Pack(String dnaPath, String xllOutputPathParam, Boolean compress, Boolean multithreading, Boolean overwrite, String usageInfo, List`1 filesToPublish, Boolean packNativeLibraryDependencies, Boolean packManagedDependencies, String excludeDependencies, Boolean useManagedResourceResolver, String outputBitness, IBuildLogger buildLogger)
   at ExcelDna.AddIn.Tasks.PackExcelAddIn.Execute()

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. HVA_XLL


I can confirm 100% that i have System.Reflection.Metadata, Version=6.0.0.0 installed from Nuget, and i have cleaned the solution multiple times and reinstalled all packages.

Govert van Drimmelen

unread,
Aug 24, 2024, 4:20:19 PM8/24/24
to exce...@googlegroups.com

Hi Tom,

 

Can you try to build the project from the command line (so that it doesn’t build in the Visual Studio build process)?

I think you can just go to the project directory, and do “dotnet build”.

 

I’m hoping it will build that way, indicating that you might be in the same situation as described in this issue

PackExcelAddIn error DNA-818471385 · Issue #700 · Excel-DNA/ExcelDna (github.com)

Tom

unread,
Aug 24, 2024, 6:13:33 PM8/24/24
to Excel-DNA
Hey Govert apologies for the delay, I had to install VS22 and all dependencies.

So the very good news is that without even converting my project to .net6 i have managed to have a successful build only by using a fresh VS22

The only issue i found is that whatever it would not accept any version lower than 8 for SYSTEM.TEXT.JSON, so i updated it to the latest 8.0.4 and I confirm that all dependencies are successfully packed.

Now it is working, i started playing a bit with the packages.

I am not sure why but in VS19 it needed SYSTEM.REFLECTION.METADATA in order to even pack everything else, in VS22 i have completely removed it and the xll works  perfectly!

I will break it a bit in case i stumble up why exactly was having the previous issue.

In the meantime if you want me to check something specific to find more about this issue please let me know.
Reply all
Reply to author
Forward
0 new messages