roslynpad icon indicating copy to clipboard operation
roslynpad copied to clipboard

Excel Interop, Could not load file or assembly

Open tsiank opened this issue 2 years ago β€’ 7 comments

Describe the bug I use Microsoft.Office.Interop.Excel.dll in RoslynPad15 DotNet 6.0 to read and write Excel, but it shows error: "Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. " But it can run normally with dotnetFrameWork To Reproduce

Expected behavior

Version

  • OS:Windows 11
  • Build (or commit ID if built from source):RoslynPad15 and RoslynPad16 20220523131611

tsiank avatar May 23 '22 05:05 tsiank

Thank you for reporting this issue πŸ‘

It seems that the problem is not with RoslynPad but with the Microsoft.Office.Interop.Excel DLL Unfortunately, this DLL has not been updated to work with .NET 6 The latest framework compatible with Microsoft.Office.Interop.Excel is .NET 4.8

As an example, if we create a console application targeting .NET 6, we will get the same error: image

jboinembalome avatar May 27 '22 13:05 jboinembalome

Thank you for reporting this issue πŸ‘

It seems that the problem is not with RoslynPad but with the Microsoft.Office.Interop.Excel DLL Unfortunately, this DLL has not been updated to work with .NET 6 The latest framework compatible with Microsoft.Office.Interop.Excel is .NET 4.8

As an example, if we create a console application targeting .NET 6, we will get the same error: image

Thank you for your reply. This Microsoft.Office.Interop.Excel DLL can be used in LinqPad7 with DotNet6.0, and it works well, so I guess there are some tricks that can fix this bug. LinqPad_20220528000413

tsiank avatar May 27 '22 16:05 tsiank

Microsoft.Office.Interop.Excel targets .NET Standard 2.0. As a result, this DLL can work with .NET 6.0. However, this DLL has not been updated to work with .NET Core by default.

If we take the example of the console application, it is necessary to import the DLL manually and to define the EmbedInteropTypes property.

Regarding LinqPad, indeed the developers have added the possibility to integrate the Office Interop COM libraries from the 6th version for .NET Core 3.1 and above.

So can we classify this issue as an enhancement?

I will try to work on it! πŸ˜‰

jboinembalome avatar May 27 '22 21:05 jboinembalome

@tsiank, I created a PR to solve this issue πŸ‘ Thank you for your feedback!

jboinembalome avatar May 28 '22 10:05 jboinembalome

@jboinembalome ,I have't thought it's fixed so quickly, thank you for your work, that's great! I will have a try.

tsiank avatar May 28 '22 14:05 tsiank

@jboinembalome ,I have tested, it works perfectly now, thank you again!

tsiank avatar May 28 '22 15:05 tsiank

Good news! You’re welcome @tsiank, it's a pleasure to help you πŸ˜‰

jboinembalome avatar May 28 '22 17:05 jboinembalome