Open Word Document in .Net

zequion 446 Reputation points
2024-05-24T02:04:11.6966667+00:00

I'm trying to convert a C# Framework 4,.8 application to .Net 8.

If I include the line: dynamic MyWordApplication = new Microsoft.Office.Interop.Word.Application();

An error occurs: {"Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the specified file.":"office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"}

I have added the Nuget package "Microsoft.Office.Interop.Word 15" but the error persists.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,013 questions
0 comments No comments
{count} votes

Accepted answer
  1. Hongrui Yu-MSFT 2,540 Reputation points Microsoft Vendor
    2024-05-24T07:24:09.18+00:00

    Hi,@zequion. Welcome to Microsoft Q&A. 

    VSTO (Visual Studio Tools for Office) relies on the .NET Framework. COM add-ins can also be written with the .NET Framework. Office Add-ins cannot be created with .NET Core and .NET 5+, the latest versions of .NET. This is because .NET Core/.NET 5+ cannot work together with .NET Framework in the same process and may lead to add-in load failures. You can continue to use .NET Framework to write VSTO and COM add-ins for Office. Microsoft will not be updating VSTO or the COM add-in platform to use .NET Core or .NET 5+. You can take advantage of .NET Core and .NET 5+, including ASP.NET Core, to create the server side of Office Web Add-ins.

    For more detailed explanation and usage, please refer to the official documentation(How to access Office interop objects - C# | Microsoft Learn)

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.