Skip to content

Unpacked XLL throws Assembly could not be loaded from resources #22

@gigi81

Description

@gigi81

I'm getting this error when running the sample project.
I upgraded to ExcelDna 1.6.0 as well with no luck.
When running the packed version it seems to work fine.
However, while debugging, launching the unpacked version I get the error below.

ExcelDna.Integration Warning: 1 : Assembly SYSTEM.RUNTIME.COMPILERSERVICES.UNSAFE could not be loaded from resources.
ExcelDna.Integration Error: 1 : DnaLibrary AutoOpen Error : TargetInvocationException - Exception has been thrown by the target of an invocation.

Also, when running the packed version, I get this error when closing excel:

Managed Debugging Assistant 'LoaderLock' 
Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

To be honest I'm not really sure if this is an ExcelDna issue or an issue that is caused by this package.

This is my csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <ExcelAddInExplicitRegistration>true</ExcelAddInExplicitRegistration>
    <ExcelDnaAllowPackageReferenceProjectStyle>true</ExcelDnaAllowPackageReferenceProjectStyle>
    <!-- We don't need the extra 'ref' directory and reference assemblies for the Excel add-in -->
    <ProduceReferenceAssembly>false</ProduceReferenceAssembly>

    <!-- We need all dependencies to be copied to the output directory, as-if we are an 'application' and not a 'library'.
         This property also sets the CopyLockFileAssemblies property to true. -->
    <EnableDynamicLoading>true</EnableDynamicLoading>

    <!-- Enables cross-platform resource packing implementation when executing on Windows. -->
    <!-- Default value: false -->
    <ExcelDnaPackManagedResourcePackingOnWindows>true</ExcelDnaPackManagedResourcePackingOnWindows>

    <!-- Enables packing native libraries from .deps.json. -->
    <!-- Default value: true -->
    <ExcelDnaPackNativeLibraryDependencies>true</ExcelDnaPackNativeLibraryDependencies>

    <!-- Enables packing managed assemblies from .deps.json. -->
    <!-- Default value: true -->
    <ExcelDnaPackManagedDependencies>true</ExcelDnaPackManagedDependencies>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="ExcelDna.AddIn" Version="1.6.0" />
    <PackageReference Include="ExcelDna.Integration" Version="1.6.0" />
    <PackageReference Include="ExcelDna.IntelliSense" Version="1.6.0" />
    <PackageReference Include="ExcelRna.Extensions.Hosting" Version="1.0.5" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.TraceSource" Version="7.0.0" />
    <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="System.Windows.Forms" />
  </ItemGroup>

  <Target Name="ExcelDnaIncludeReferences" DependsOnTargets="ExcelDnaBuild" BeforeTargets="ExcelDnaPack">
    <!-- read existing content -->
    <XmlPeek XmlInputPath="%(ExcelDnaFilesToPack.OutputDnaFileName)" Query="//*[local-name()=&quot;DnaLibrary&quot;]/*">
      <Output TaskParameter="Result" PropertyName="Peeked" />
    </XmlPeek>

    <!-- find all dependencies -->
    <ItemGroup>
      <ExcelDnaReferences Include="@(ReferenceCopyLocalPaths->'&lt;Reference Path=&quot;%(Filename)%(Extension)&quot; Pack=&quot;true&quot; /&gt;')" Condition="'%(Extension)' == '.dll'" />
    </ItemGroup>

    <!-- combine existing content with the required dependencies -->
    <PropertyGroup>
      <ExcelDnaReferencesXml>@(ExcelDnaReferences)</ExcelDnaReferencesXml>
      <ConcatenatedNodes>$(Peeked.Replace(";",""))$(ExcelDnaReferencesXml.Replace(";",""))</ConcatenatedNodes>
    </PropertyGroup>

    <!-- update .dna file -->
    <XmlPoke Value="$(ConcatenatedNodes)" XmlInputPath="%(ExcelDnaFilesToPack.OutputDnaFileName)" Query="//*[local-name()=&quot;DnaLibrary&quot;]">
    </XmlPoke>

    <Message Text="Patched %(ExcelDnaFilesToPack.OutputDnaFileName)." Importance="High" />
  </Target>

</Project>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions