ExcelDna icon indicating copy to clipboard operation
ExcelDna copied to clipboard

PackExcelAddIn error DNA-818471385

Open innominateAtWork opened this issue 1 year ago • 1 comments

After updating to the latest version of visual studio (17.10.2) I started getting the error below on build.

1>MSBUILD : PackExcelAddIn error DNA-818471385: Assembly at bin\Debug\net6.0-windows\System.Threading.Channels.dll could not be packed. Possibly a mixed assembly? (These are not supported yet.)
1>MSBUILD : PackExcelAddIn error DNA-818471385: Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Threading.Channels, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Cannot specify assembly evidence under MultiDomain after non-GAC assemblies with default evidence have been loaded in appdomain. (Exception from HRESULT: 0x8013101D)
1>MSBUILD : PackExcelAddIn error DNA-818471385: File name: 'System.Threading.Channels, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' ---> System.Runtime.InteropServices.COMException (0x8013101D): Cannot specify assembly evidence under MultiDomain after non-GAC assemblies with default evidence have been loaded in appdomain. (Exception from HRESULT: 0x8013101D)
1>MSBUILD : PackExcelAddIn error DNA-818471385:    at System.Reflection.RuntimeAssembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection, Boolean fSkipIntegrityCheck, SecurityContextSource securityContextSource)
1>MSBUILD : PackExcelAddIn error DNA-818471385:    at System.Reflection.Assembly.Load(Byte[] rawAssembly)
1>MSBUILD : PackExcelAddIn error DNA-818471385:    at ResourceHelper.ResourceUpdater.AddAssembly(String path, String source, Boolean compress, Boolean multithreading, Boolean includePdb)
1>MSBUILD : PackExcelAddIn error DNA-818471385: 
1>MSBUILD : PackExcelAddIn error DNA-818471385:

I am able to reproduce this with this minimal project file (no code needed)

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

  <PropertyGroup>
    <TargetFramework>net6.0-windows</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>    
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="ExcelDna.AddIn" Version="1.8.0" />
    <PackageReference Include="System.Threading.Channels" Version="7.0.0" />
  </ItemGroup>

</Project>

The error only happens when building with-in visual studio, not when building via dotnet build.

innominateAtWork avatar Jun 14 '24 16:06 innominateAtWork

@Sergey-Vlasov Could you confirm this problem, and maybe track down what the problem is with the System.Threading.Channels package?

govert avatar Jun 24 '24 13:06 govert

Just to confirm I also see this error. Recently updated VS now on 17.10.3 - any other version info that might be helpful to know?

adm1961 avatar Jul 31 '24 14:07 adm1961

The error occurs in following code, where path is bin\Debug\net6.0-windows\System.Threading.Channels.dll

byte[] assemblyBytes = File.ReadAllBytes(path);
// Not just into the Reflection context, because this Load is used to get the name and also to 
// check that the assembly can Load from bytes (mixed assemblies can't).
Assembly assembly = Assembly.Load(assemblyBytes);
AssemblyName assemblyName = assembly.GetName();

It is caused by System.Threading.Channels.dll v8 being already loaded in the MSBuild.exe process.

When building with-in Visual Studio 2022, our pack task is executed in MSBuild .NET Framework application. MSBuild uses and preloads System.Threading.Channels v8, also .NET Framework assembly. Our task tries to load System.Threading.Channels v7 .NET 6.0 assembly.

I don’t think checking that the assembly can Load from bytes in an MSBuild process is representative of loading in an Excel process. I’ve replaced the original code with

AssemblyName assemblyName = AssemblyName.GetAssemblyName(path);

Sergey-Vlasov avatar Aug 04 '24 09:08 Sergey-Vlasov

Hi Excel-DNA Team,

I'm seeing a similar issue with Microsoft.Bcl.AsyncInterfaces.dll .

It builds correctly the first time I build after cleaning the solution, but if I try to rebuild without cleaning the solution I get the error messages shown below.

Any thoughts if this is the same problem? Has the fix been implementing in the latest NuGet package?

Thanks for all you do! Mark

MSBUILD : PackExcelAddIn error DNA-818471385: Assembly at bin\Debug\net6.0-windows\Microsoft.Bcl.AsyncInterfaces.dll could not be packed. Possibly a mixed assembly? (These are not supported yet.) 1>MSBUILD : PackExcelAddIn error DNA-818471385: Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Cannot specify assembly evidence under MultiDomain after non-GAC assemblies with default evidence have been loaded in appdomain. (Exception from HRESULT: 0x8013101D) 1>MSBUILD : PackExcelAddIn error DNA-818471385: File name: 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' ---> System.Runtime.InteropServices.COMException (0x8013101D): Cannot specify assembly evidence under MultiDomain after non-GAC assemblies with default evidence have been loaded in appdomain. (Exception from HRESULT: 0x8013101D) 1>MSBUILD : PackExcelAddIn error DNA-818471385: at System.Reflection.RuntimeAssembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection, Boolean fSkipIntegrityCheck, SecurityContextSource securityContextSource) 1>MSBUILD : PackExcelAddIn error DNA-818471385: at System.Reflection.Assembly.Load(Byte[] rawAssembly) 1>MSBUILD : PackExcelAddIn error DNA-818471385: at ResourceHelper.ResourceUpdater.AddAssembly(String path, String source, Boolean compress, Boolean multithreading, Boolean includePdb)

mintrieri avatar Sep 20 '24 16:09 mintrieri

Hi Mark - could you try with Excel-DNA version 1.9.0-alpha2 ? I think we've addressed the problem for the upcoming version.

govert avatar Sep 20 '24 16:09 govert

Hi Govert - I gave it a quick test and its seems to have fixed the issue. I'll keep an eye on it and let you know if I see it again Many Thanks!

mintrieri avatar Sep 20 '24 20:09 mintrieri

Hi Govert, we are affected by this packing issue as well and it seems to be fixed in alpha-3. Do you have a target date for the full release of 1.9 yet?

OJonesMatthey avatar Jan 17 '25 16:01 OJonesMatthey

I am getting this issue again after another visual studio update (Version 17.14.8 ). Its now trying to load version 9.0.0.0 of System.Threading.Channels, but otherwise its the exact same issue.

1>PackExcelAddIn:   ->  Updating resource: Type: ASSEMBLY_LZMA, Name: EXCELDNATEST, Length: 1283
1>MSBUILD : PackExcelAddIn error DNA-818471385: Assembly at bin\Debug\net6.0-windows\System.Threading.Channels.dll could not be packed. Possibly a mixed assembly? (These are not supported yet.)
1>MSBUILD : PackExcelAddIn error DNA-818471385: Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Threading.Channels, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Cannot specify assembly evidence under MultiDomain after non-GAC assemblies with default evidence have been loaded in appdomain. (Exception from HRESULT: 0x8013101D)
1>MSBUILD : PackExcelAddIn error DNA-818471385: File name: 'System.Threading.Channels, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' ---> System.Runtime.InteropServices.COMException (0x8013101D): Cannot specify assembly evidence under MultiDomain after non-GAC assemblies with default evidence have been loaded in appdomain. (Exception from HRESULT: 0x8013101D)
1>MSBUILD : PackExcelAddIn error DNA-818471385:    at System.Reflection.RuntimeAssembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection, Boolean fSkipIntegrityCheck, SecurityContextSource securityContextSource)
1>MSBUILD : PackExcelAddIn error DNA-818471385:    at System.Reflection.Assembly.Load(Byte[] rawAssembly)
1>MSBUILD : PackExcelAddIn error DNA-818471385:    at ResourceHelper.ResourceUpdater.AddAssembly(String path, String source, Boolean compress, Boolean multithreading, Boolean includePdb)
1>MSBUILD : PackExcelAddIn error DNA-818471385: 
1>MSBUILD : PackExcelAddIn error DNA-818471385:

innominateAtWork avatar Jul 29 '25 19:07 innominateAtWork

@innominateAtWork What Excel-DNA package version are you referencing?

govert avatar Jul 29 '25 19:07 govert

Using version 1.8.0. It does seem to work if I update to 1.9.0-rc3.

innominateAtWork avatar Jul 29 '25 19:07 innominateAtWork

I am seeing in my original post I was also using 1.8.0. I think I had worked around this back then by removing the reference to System.Threading.Channels in my real project.

The latest visual studio seems to also load Microsoft.Bcl.AsyncInterfaces 9.0.0.0 which is the assembly now causing the issue in my real project.

So no new issue here.

innominateAtWork avatar Jul 29 '25 19:07 innominateAtWork