interactive icon indicating copy to clipboard operation
interactive copied to clipboard

Unable to use Microsoft.office.interop packages

Open zz415 opened this issue 9 months ago • 4 comments

A great addition to dotnet scripts, interactive and notebooks would be the ability to use the Microsoft.office.interop packages like outlook, excel etc . This would make dotnet scripts an even better go to for small automation jobs and not always have to revert to Python .

zz415 avatar Mar 28 '25 17:03 zz415

What are you seeing when you try to use these? Can you give an example of what you're trying to do?

jonsequitur avatar Mar 28 '25 18:03 jonsequitur

#r "nuget: Microsoft.Office.Interop.Excel"

Using Excel = Microsoft.Office.Interop.Excel;

var excelapp = new Excel.Application();

//if you try and run this in a c# polyglot notebook it will error out, researching online it says this will work in a visual studio compiled project , but this seems like great use case in dotnet interactive . Outlook interop works similar to the excel one , where you need to make new Application(); to use.

zz415 avatar Mar 28 '25 19:03 zz415

Here's the error I get when I try to run this:

Error: System.IO.FileNotFoundException: Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified.
File name: 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
at Submission#1.<<Initialize>>d__0.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at Submission#1.<Initialize>()
at Submission#1.<Factory>(Object[] submissionArray)
at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)

jonsequitur avatar Mar 31 '25 22:03 jonsequitur

This looks like a bug in the package to me. I didn't realize that the package isn't Microsoft owned. You might consider reaching out to the package owner as the fix would have to be in the package in any case.

Image

jonsequitur avatar Mar 31 '25 22:03 jonsequitur