1

This is my system environment

  • Windows 10 64bit
  • Office 2013 32bit
  • Visual Studio 2019, Build Only x86
  • I have no choice but to use 32bit excel.
  • I develop with C# and I already reference assembly
  • I also checked reference properties : Local copy(true), Include interop type(true)
  • Object Framework is .NET 5.0
  • Output : Console application

The error comes up this below code

Microsoft.Office.Interop.Word.Application winWord = new Microsoft.Office.Interop.Word.Application();

And Error message like below.

System.InvalidCastException: 'Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Word.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)

What is important :

  • I already tried restore, uninstall MicroSoft Office 3 times.

Also I search it on Google almost 7 days I tried like this site Error accessing COM components

But Always faild to solve the error.

Now I'm gonna crazy. Please give me any help

user13232877
  • 205
  • 1
  • 9
  • The first link leads to: [Unable to cast COM object of Office Interop Word](https://social.msdn.microsoft.com/Forums/vstudio/en-US/d34c4f78-46f3-478e-9c44-95ea8461e46f/unable-to-cast-com-object-of-office-interop-word?forum=vsto) – Luuk May 26 '22 at 14:54
  • @Luuk I tried it but it didn't work for me... – user13232877 May 26 '22 at 15:04
  • I cannot get it to work in .NET5 (but getting different errors). I get this Warning: "Warning NU1701 Package 'Microsoft.Office.Interop.Word 15.0.4797.1003' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net5.0'." – Luuk May 26 '22 at 15:35
  • Then you mean, in the net5.0 "Microsoft.Office.Interop.Word" doesn't work. right? – user13232877 May 26 '22 at 23:55
  • With my limited knowledge of C# I did draw that conclusion. I am trying to find (online) resources that confirm that, but was unsuccessfull (see: [github.com/dotnet/runtime...](https://github.com/dotnet/runtime/issues/43426), [developercommunity.visualstudio.com/...](https://developercommunity.visualstudio.com/t/make-net-5-app-support-officeinterop/1332337), [Microsoft Interop Excel with .Net5.0 is not working](https://stackoverflow.com/questions/66039601/microsoft-interop-excel-with-net5-0-is-not-working) ) – Luuk May 27 '22 at 08:18

1 Answers1

0

The Problem is : I run my program on the visual studio with administrator mode.

It seems that when I run with administrator(after I will say this as 'admin'), some privileges issue pops up internally. Therefore it seems to my computer could not load the library/dll.

Although I can't say exact mechanism even more detail because I'm not major in computer science, surely the problem is solved when I run with 'not' admin mode. And it doesn't get any error since I changed it.

user13232877
  • 205
  • 1
  • 9