ExcelDna: System.Drawing.Common and LogDisplay load errors
Under .NET 6 add-ins, the LogDisplay may fail to load with an error complaining about a set_Font method not found. This relates to a newer version of the assembly System.Drawing.Common being present in the output directory. There is a deep .NET 6 mess related to this file, and why it might be present after referencing some packages. See for example https://github.com/dotnet/runtime/issues/64592
If using the System.Configuration.ConfigurationManager it might help to reference version 6.0.0 instead of 6.0.1.
Otherwise, the file can be explicitly deleted in the build:
<Target Name="RemoveSystemDrawingCommon" AfterTargets="ResolveAssemblyReferences">
<ItemGroup>
<ReferencePath Remove="@(ReferencePath)" Condition="%(ReferencePath.NuGetPackageId) == 'System.Drawing.Common'" />
</ItemGroup>
</Target>
Is this safe? Presumably not always.
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 17 (8 by maintainers)
I’ve run into this issue today and just in case more people have it, here is what was happening
I was working on a dotnet 7 project and there was an idea to reuse some of the logic within an Excel add-in. After making everything backwards-compatible with dotnet 6, I’ve run into this issue. This only showed up when trying to initialise Intellisense and not without it
The source of the problem was a Microsoft.Data.SqlClient dependency on Microsoft.Configuration.ConfigurationManager (as described above). I’ve tinkered around with various solutions, but what ultimately helped is using System.Data.SqlClient for dotnet 6 build and Microsoft.Data.SqlClient for dotnet 7. The difference in the interface is very minor and other additions/fixes are not significant enough to warrant being needed by an Excel plugin. And there were only a few changes that had to be implemented for the downgrade to compile
Hope this helps someone aswell
Yay!