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

Fix #433 - Excel Interop, Could not load file or assembly #435

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jboinembalome
Copy link
Contributor

Fix #433 - Excel Interop, Could not load file or assembly

When we use Microsoft.Office.Interop.Excel.dll (or Word, PowerPoint, Outlook) with .Net Core, we get this error:
"Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. "

To resolve this error in a console application targeting .Net Core, we need:

  • Copy the DLL locally
  • Go into the DLL properties
  • Set the Embed Interop Types property to true

On the LinqPad side, the MS Office Interop DLLs work with .NET Core with LinqPad 6.5 and above

On our side, we only need:

  • Set the Embed Interop Types property to true when there is a reference to an MS Office Interop DLL.

This is possible with the MetadataReferenceProperties struct that I added as a parameter to IRoslynHost (previously we used the default value)

MetadataReferences = references
.Where(r => !string.IsNullOrWhiteSpace(r))
.Select(r => _roslynHost.CreateMetadataReference(r))
.Select(r => Platform.IsCore && r.Contains(@"net20\Microsoft.Office.Interop")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that this solution is so specific to a version of office interop assemblies. A better option would be to add this to the #r directive, e.g.

#r "Intertop.dll, EmbedInteropTypes"

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

Successfully merging this pull request may close these issues.

Excel Interop, Could not load file or assembly
2 participants