Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gigi81 opened this issue May 10, 2023 · 1 comment
Open

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

gigi81 opened this issue May 10, 2023 · 1 comment

Comments

@gigi81
Copy link

gigi81 commented May 10, 2023

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>
@altso
Copy link
Owner

altso commented May 10, 2023

I haven't tested with ExcelDna 1.6 yet, so it's possible that some things may not work as expected.

I can confirm the issue related to SYSTEM.RUNTIME.COMPILERSERVICES.UNSAFE. As a workaround I am using packed version for debugging, but I never encountered LoaderLock errors before. Does it happen with 1.5.x as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants