locked
How to solve “Unable to cast COM object of type Microsoft.Office.Interop.Excel.ApplicationClass’ to interface type ‘Microsoft.Office.Interop.Excel._Application’” RRS feed

  • Question

  • “Unable to cast COM object of type Microsoft.Office.Interop.Excel.ApplicationClass’ to interface type ‘Microsoft.Office.Interop.Excel._Application’”this operation failed because the QueryInterface call on the com component for interface with IID '{000208D5-0000-0000-c000-00000000046}' failed due to the followinf error:Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).

    Not working in the follwing scenareo:

    windows 10 64 bit os ,office 16 64 bit ,vb.net code compiled as 32, referenced the Microsoft.office.Interop.dll from Gac and 15 version suitable for office 16.

    working in following scenareo :

    windows 7 32 bit os , office 16 of 32 bit , vb.net code compiled as 32 bit.

    tried solutions from google:

    1)checked the registry key and fine it contains 1.9

    2)repaired the office 16

    3)compiled as ANY CPU ->excel working but app need to be run as 32 bit.

    Is it problem with dll mapping , i didnt find separate dll for 32 bit or 64 bit microsoft.office.interop.dll

    please suggest how to load proper dll so that export to excel  should work on windows 10 , 64 bit os ,office 16 of 64 bit.code runs as 32 bit.


    Friday, May 18, 2018 7:16 PM

Answers

  • thanks for the reply .

    In Specific to my case :

    issue is resolved by deleting the existing configuration properties ->platform options (previously while creating soltion platforms x64 and anycpu  ,settings are copied from x86 ).so even if i run as 64 or any cpu it  behaves as 32 internally.so 

    all the target platform solution options were deleted and added freshly and for the setup ->changed the target from x86 to x64

    1)right click on solution->configuration propertie->configuration manager->active solution platform->

    x86 deletd 
    any cpu deleted
    x64 deleted

    2)again created fresh x86,x64, any cpu and compiled with all options.

    3)select appname.setup->view->properties window->Target platform->x64 

    now working fine as expected .


    Monday, May 21, 2018 5:15 PM

All replies

  • Are you sure you have installed Office 2016 64bit?

    Just takes a click to give thanks for a helpful post or answer.
    Please vote “Helpful” or Mark as “Answer” as appropriate.
    Chris Ward
    Microsoft Community Contributor 2012

    Friday, May 18, 2018 8:11 PM
  • yes , just now i had checked again and office is 2016 MSO and 64 bit .

    and visual studio is 32  bit.

    I didn't find 64 bit dlls anywhere.

    thanks for the reply ,do i need to install visual studio also 64 bit , so that it will contin 64 bit dlll


    • Edited by babji v Saturday, May 19, 2018 7:24 PM
    Saturday, May 19, 2018 7:58 AM
  • .Net framework of the project is 4.5.

    In windows application ,export to excel functionality is not working in 64 bit windows10 , 64 bit office .

    error is like not able to load library.Is it really dll problem?

    currently using interop.excel and microsoft.office.interop.excel tried all versions in com.

    please help me ,to identify issue root cause.

     

    Saturday, May 19, 2018 8:03 AM
  • Well, you could just use CreateObject("Excel. Application") not use the interop library.

    However, if your using office x64, then you need to force your .net project as x64.

    VS is always x32, but it can well create both x32 and x64 applications (so that is a non-issue).

    So as a general rule, you will have to build both an x32 and x64 bit version of your application depending on what version of office they have.

    I would get your project working as x64. Once working, you can try “any cpu”, but as a general rule you have to match the CPU with the intended target office bit size.

    While .net code is happy as x32/x64 with “any cpu”, the problem is that office is NOT managed code, so it can’t respect the “any” cpu setting.

    Last but not least?

    Well, to be fair, I had my x64 .net applications freely consume x32 office (my assuming is that a set of “stubs” is installed by office for this magic to work – but for non-office code, then you must force the cpu to the intended target. So I have had good luck – but in this case, I had the .net project ALWAYS set to x64.

    So on your test machine, force the project to the same bit size as office. Get that working. You can then try on a machine with x32 office, but some risk is involved, and it is a bridge you can attempt to cross once you get the application working with your current setup.

    Regards,

    Albert D. Kallal (Access MVP, 2003-2017)

    Edmonton, Alberta Canada

    Sunday, May 20, 2018 6:39 PM
  • Hi babji v,

    I also suggest you to post your code.

    So that we can try to make a test with it.

    Only error will not give enough information to find the actual cause.

    We will try to check your code on our side and try to find the issue in it.

    It will be helpful for us to find the solution.

    Regards

    Deepak


    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, May 21, 2018 4:52 AM
  • thanks for the reply .

    issue is resolved by deleting the compiles as options (previously while creating x64 and anycpu  compiles settings are copied from x86 ).so even if i run as 64 or any cpu it  behaves as 32 internally.so 

    x86 deletd 
    any cpu deleted
    x64 deleted

    again created fresh x86,x64, any cpu and compiled with all options.
    now working fine as expected and set the compile option as 64.

    Monday, May 21, 2018 5:15 PM
  • thanks for the reply .

    In Specific to my case :

    issue is resolved by deleting the existing configuration properties ->platform options (previously while creating soltion platforms x64 and anycpu  ,settings are copied from x86 ).so even if i run as 64 or any cpu it  behaves as 32 internally.so 

    all the target platform solution options were deleted and added freshly and for the setup ->changed the target from x86 to x64

    1)right click on solution->configuration propertie->configuration manager->active solution platform->

    x86 deletd 
    any cpu deleted
    x64 deleted

    2)again created fresh x86,x64, any cpu and compiled with all options.

    3)select appname.setup->view->properties window->Target platform->x64 

    now working fine as expected .


    Monday, May 21, 2018 5:15 PM
  • Interesting. Don't think I've seen that happen in a VS project before.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Monday, May 21, 2018 5:59 PM
  • Hi babji v,

    From your last post, I can see that you issue is solved now.

    But you did not mark the answer.

    So this thread is still open and will remain open until you mark the answer.

    I suggest you to mark your own last post as an answer.

    It will help us to close this thread on our side.

    It will also helpful for other community members who will have same kind of issue in future.

    Thanks for your understanding.

    Regards

    Deepak


    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.

    Tuesday, May 22, 2018 8:57 AM
  • yes , thanks for your suggestion.

     i did the same

    I set the target of the code as 64(which was previously set to 32).working fine now.

    Wednesday, May 23, 2018 6:12 PM