none
Problem referencing Office Interop from .Net Core 3 (preview 6) RRS feed

  • Question

  • Probably wrong forum (cannot find any forum targeting .Net Core), but I take the chance anyway:

    Using Nuget to install Microsoft.Office.Interop.Excel.dll (15.0.4795.1000) from a .Net Core 3 (preview 6) WPF application and gets an error as soon as the assembly is to be loaded:
    "Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified."

    Is office interop not meant to be working for .Net Core?
    If so, what will be the alternative after .Net  4.8?
    Workaround?


    Tuesday, June 18, 2019 9:08 AM

Answers

  • My explanation of the problem may be very bad, but I am anyway a bit surprised that not even Microsoft support was able to tell me to set "Embed Interop Types" to the value "yes" (in the Dependencies/COM reference section of the project).

    Voila and working!

    I think the error message is anyway confusing and this setting is default for .net fx projects (but seemingly not necessary).

    I wish this was better documented, but can live with it for now.

    • Marked as answer by EuroEager Monday, August 5, 2019 7:11 AM
    Monday, August 5, 2019 7:11 AM

All replies

  • Hi EuroEager, 

    Thank you for posting here.

    Based on your description, I have made a sample on my side.

    I have reproduced your problem:

    Then I found that Microsoft.Office.Interop.Excel.dll (15.0.4795.1000) is not restored using .NET Core3 (preview 6).

    When I installed the dll from .NET FrameWork v4.7.2, I got no failtures.

    Therefore, I suggest that you can use .NET FrameWork instead of .NET Core 3 (preview 6).

    Hope it can help you.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 19, 2019 9:12 AM
    Moderator
  • Thanks

    I have just worked with a work-around where I make my excel interface(very simple one) in a separate lib project using framework 4.8 and this works fine including referencing it from .Net Core 3 Preview 6 (which surprised me a little), however in the long run this is not a useful solution due to:

    This solution will possibly introduce a lot of simple dispatching calls.
    The future of .Net is .Net 5 and later which will not diffrentiate between Core and Framework anymore (ref. https://devblogs.microsoft.com/dotnet/introducing-net-5/) and I consider COM interface (including Office) as absolutely mandatory and would know if this is planned into the .Net Core 3 or .Net 5 or similar.

    Wednesday, June 19, 2019 10:39 AM
  • Hi EuroEager,

    Thank you for your sharing.

    It seems that your problem has been solved. If so, please post "Mark as answer" to the appropriate answer.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 21, 2019 9:53 AM
    Moderator
  • No, my problem is not really solved.

    My workaround is not really a problem solution, my question regarding .Net Core, .Net 5 a.s.o. remains:

    Will .Net Core 3 and later include COM interop (including Office automation)?
    (and of course by simple reference adding in Visual Studio)

    Sunday, June 23, 2019 10:09 AM
  • Hi EuroEager, 

    Thanks for the feedback.

    Based on your description, you can suggest a feature in Developer Community for better help.

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 24, 2019 7:33 AM
    Moderator
  • what a bumper... got interested in .net core 3 but no interface with Excel is a show stop

    I have many interfaces excel and I do use the Microsoft.Office.Interop.Excel.dll

    quite a lot

    Friday, July 5, 2019 7:12 PM
  • VS 16.3.0 Preview 1.0 .Net Core 3 Preview 7 and still not fixed.

    What are they thinking about? No office automation possibilities with Core (even though COM is said to be 1 class citizen, what about upcoming .Net 5.

    Insane

    Sunday, August 4, 2019 5:26 PM
  • My explanation of the problem may be very bad, but I am anyway a bit surprised that not even Microsoft support was able to tell me to set "Embed Interop Types" to the value "yes" (in the Dependencies/COM reference section of the project).

    Voila and working!

    I think the error message is anyway confusing and this setting is default for .net fx projects (but seemingly not necessary).

    I wish this was better documented, but can live with it for now.

    • Marked as answer by EuroEager Monday, August 5, 2019 7:11 AM
    Monday, August 5, 2019 7:11 AM
  • Thank you !!!!
    Monday, October 21, 2019 10:49 AM
  • If it solved your problem, could you please mark my comment as an answer?
    Monday, October 21, 2019 11:13 AM
  • In addition please be aware of .net core lack of support for dynamic (Dynamic Language Runtime) which makes it neccessary to do a lot of casting and even without knowing exactly where it is neccessary.
    Please see: https://github.com/dotnet/corefx/issues/40053

    It looks like DLR is considered to be included in .net 5 next year.

    Monday, October 21, 2019 11:26 AM
  • EuroEagar, You may also want to look another possible workaround here. The URL is: https://stackoverflow.com/a/58130770/1232087

    Saturday, October 26, 2019 4:09 AM
  • EuroEager, Your solution also matches this one: https://github.com/dotnet/samples/tree/master/core/extensions/ExcelDemo
    Saturday, October 26, 2019 4:39 AM
  • I think out a workaround solutions.

    First, create a .Net Framework library (4.5.2 or higher) , I'll call it the Lib.

    Then, using Nuget to install Microsoft.Office.Interop.Excel.dll to the Lib.

    Create some class and method that operating the excel in the Lib.

    Reference to the Lib from your .Net Core 3 WPF application, call the method 
    that you created to operate excel.

    This is NOT full TESTED, I tested it with VS 2019 16.4 and .Net core 3.0 to print Excel files.

    Wish this can help you.

    Wednesday, March 18, 2020 10:11 AM
  • That worked! Thanks!
    Saturday, March 21, 2020 10:31 PM