locked
CreateObject to Office 2010 x86 from x64 process fails - should be out-of-process and thus working? RRS feed

  • Question

  • Hello everybody,

    we have .net applications compiled for AnyCPU which automate Office. When the application runs as a x64 process and, say, Excel (tested with 2010) is running already, GetObject("Excel.Application") just works fine as expected. If, however, Excel does not yet run and we try a CreateObject("Excel.Application"), it fails and cannot instantiate the object.

    I am fully aware that we cannot create or get an in-process x86 COM component in a x64 process, but Office should be out-of-process I thought. I guess it must have something to do with PIAs, but I do not understand why we can GetObject successfully, but not CreateObject.

    Regards and thanks for any tips,

    Stefan Falk


    Stefan Falk
    • Moved by eryang Tuesday, July 13, 2010 9:36 AM Move to excel forum for better support. (From:64-Bit .NET Framework Development.)
    Tuesday, June 29, 2010 11:14 AM

All replies

  • You may try this code snippet to create an excel object:

                Type excelType = Type.GetTypeFromProgID("Excel.Application");
                Application excelApp = Activator.CreateInstance(excelType) as Application;
                excelApp.Visible = true;
                excelApp.Workbooks.Open(@"E:\test.xlsx", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, June 30, 2010 9:04 AM
  • Wonderful. Just 10 Minutes ago I had this problem the first time. And your suggestion works!
    Wednesday, June 30, 2010 1:36 PM
  • Hello Eric,

    Thank you for your prompt response. Unfortunately, I still get an execption on Activator.CreateInstance:

    System.IO.FileNotFoundException was caught
      Message="Die COM-Klassenfactory für die Komponente mit CLSID {00024500-0000-0000-C000-000000000046} konnte aufgrund des folgenden Fehlers nicht abgerufen werden: 80070002."
      Source="mscorlib"
      StackTrace:
           bei System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
           bei System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(Type serverType)
           bei System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(Type serverType, Object[] props, Boolean bNewObj)
           bei System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
           bei System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
           bei System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
           bei System.Activator.CreateInstance(Type type, Boolean nonPublic)

    Do you have second tip for me?

    Best Regards,


    Stefan Falk
    Wednesday, June 30, 2010 10:26 PM
  •  

    The error is "The COM class factory for component with CLSID (00024500-0000-0000-C000-000000000046) could not be retrieved due to the following error: 80070002"

     

    Error code 80070002 means "File Not Found", Dependency Walker can tell you which dependency is lost on your machine, you can also use Process Monitor to find out the Not Found file.

     

    By the way, what kind of application it is, asp.net? what if you change the platform target to x86?


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, July 1, 2010 2:38 AM
  • Hello Eric,

    it is a WinForms application. If we change it to x86, CreateObject (and your suggestion) both work fine.

    Best Regards,


    Stefan Falk
    Thursday, July 1, 2010 6:11 AM
  •  

    Glad to see you got a solution for this issue. by the way, other community members who have similar question will benefit from this thread  if you mark useful replies as answers.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, July 1, 2010 8:08 AM
  • Hello Eric,

    just to be clear: For me, the problem is not solved. Both CreateObject and your suggestion only work if I switch the application to x86. Wenn running as x64, I still cannot create an Excel COM object.

    Best Regards,


    Stefan Falk
    Thursday, July 1, 2010 8:17 AM
  • Hi Stefan,

    Did you try Dependency Walker or Process Monitor? any hint from those tools?


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, July 1, 2010 9:56 AM
  • Hello Eric,

    I now have a Process Monitor log just of the failing CreateObject statement. If you want, I could mail the complete log file, but here is the content pasted:

    0 17:05:30,4255059 SFBuchungsplan.vshost.exe 5112 CreateFile C:\Windows\assembly\GAC_64\Microsoft.Office.Interop.Excel\14.0.0.0__71e9bce111e9429c PATH NOT FOUND Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
    1 17:05:30,5014018 SFBuchungsplan.vshost.exe 5112 RegOpenKey HKLM\System\CurrentControlSet\Control\Cryptography\Providers REPARSE Desired Access: Read
    2 17:05:30,5015989 SFBuchungsplan.vshost.exe 5112 RegOpenKey HKLM\System\CurrentControlSet\Control\Cryptography\Configuration REPARSE Desired Access: Read
    3 17:05:30,5018930 SFBuchungsplan.vshost.exe 5112 RegOpenKey HKLM\System\CurrentControlSet\Control\Cryptography\Providers REPARSE Desired Access: Read
    4 17:05:30,5020629 SFBuchungsplan.vshost.exe 5112 RegOpenKey HKLM\System\CurrentControlSet\Control\Cryptography\Configuration REPARSE Desired Access: Read
    5 17:05:30,5151143 SFBuchungsplan.vshost.exe 5112 RegCreateKey HKCU\Software\Policies\Microsoft\SystemCertificates\Disallowed ACCESS DENIED Desired Access: Read/Write, Delete
    6 17:05:30,5158072 SFBuchungsplan.vshost.exe 5112 RegCreateKey HKCU\Software\Policies\Microsoft\SystemCertificates\Disallowed ACCESS DENIED Desired Access: Read/Write, Delete
    7 17:05:30,5172433 SFBuchungsplan.vshost.exe 5112 RegCreateKey HKLM\Software\Microsoft\SystemCertificates\Disallowed ACCESS DENIED Desired Access: Read/Write, Delete
    8 17:05:30,5178808 SFBuchungsplan.vshost.exe 5112 RegCreateKey HKLM\SOFTWARE\MICROSOFT\SystemCertificates\Disallowed ACCESS DENIED Desired Access: Read/Write, Delete
    9 17:05:30,5186430 SFBuchungsplan.vshost.exe 5112 RegCreateKey HKLM\Software\Microsoft\SystemCertificates\Disallowed ACCESS DENIED Desired Access: Read/Write, Delete
    10 17:05:30,5191311 SFBuchungsplan.vshost.exe 5112 RegCreateKey HKLM\SOFTWARE\MICROSOFT\SystemCertificates\Disallowed ACCESS DENIED Desired Access: Read/Write, Delete
    11 17:05:30,5210030 SFBuchungsplan.vshost.exe 5112 RegCreateKey HKLM\Software\Policies\Microsoft\SystemCertificates\Disallowed ACCESS DENIED Desired Access: Read/Write, Delete
    12 17:05:30,5216595 SFBuchungsplan.vshost.exe 5112 RegCreateKey HKLM\SOFTWARE\Policies\Microsoft\SystemCertificates\Disallowed ACCESS DENIED Desired Access: Read/Write, Delete
    13 17:05:30,5228718 SFBuchungsplan.vshost.exe 5112 RegCreateKey HKLM\Software\Microsoft\EnterpriseCertificates\Disallowed ACCESS DENIED Desired Access: Read/Write, Delete
    14 17:05:30,5233594 SFBuchungsplan.vshost.exe 5112 RegCreateKey HKLM\SOFTWARE\MICROSOFT\EnterpriseCertificates\Disallowed ACCESS DENIED Desired Access: Read/Write, Delete
    15 17:05:30,5236674 SFBuchungsplan.vshost.exe 5112 RegCreateKey HKLM\Software\Microsoft\EnterpriseCertificates\Disallowed ACCESS DENIED Desired Access: Read/Write, Delete
    16 17:05:30,5241709 SFBuchungsplan.vshost.exe 5112 RegCreateKey HKLM\SOFTWARE\MICROSOFT\EnterpriseCertificates\Disallowed ACCESS DENIED Desired Access: Read/Write, Delete
    17 17:05:30,5362543 SFBuchungsplan.vshost.exe 5112 QueryDirectory C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\14.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.INI NO SUCH FILE Filter: Microsoft.Office.Interop.Excel.INI

    This log was created by running the x64 program in Visual Studio 2008 debug mode and setting a breakpoint just on the CreateObject statement. When the program reached that point, I started logging in Process Monitor, and stopped when the Exception got raised. Then I filtered by the process name.

    I hope this is helpful, but I am willing to provide anything you would need to find the problem.

    Best Regards


    Stefan Falk
    Thursday, July 8, 2010 3:22 PM
  •  

    For this "File not found" issue, file system activities will more useful than registry activities. However, could you please let me know your email address by sending a mail to v-eryang@microsoft.com. Then I will create a file transfer workspace where you can upload your log file. The file will be kept confidential.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, July 9, 2010 4:56 AM
  •  

    Thanks for sending me the log file.

     

    From the file system activities of the log, we can see that runtime cannot find path "C:\Windows\assembly\GAC_64\Microsoft.Office.Interop.Excel\14.0.0.0__71e9bce111e9429c", you may check whether the file (Microsoft.Office.Interop.Excel, 14.0.0.0, 71e9bce111e9429c, MSIL)  exists in folder "C:\Windows\assembly" on your 64bit machine.

     

    The Microsoft.Office.Interop.Excel.dll usually locates under "Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14", you may either install the dll into GAC, or directly add reference to the dll from your project.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, July 9, 2010 10:07 AM
  • Hello Eric,

    Thanks for your prompt answer.

    Microsoft.Office.Interop.Excel, 14.0.0.0, 71e9bce111e9429c, MSIL is in the GAC.

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Excel.dll also exists. Should I copy that to the GAC (on every customer's machine)? Also, a reference to this DLL would tie the application to that single version of Excel, wouldn't it? By using CreateObject("Excel.Application"), the application would work (tested) from Excel 2002 up to 2010.

    Best Regards,


    Stefan Falk
    Friday, July 9, 2010 3:11 PM
  •  

    It is odd, anyway, would you please try Fuslogvw.exe first, the tool can displays details for failed assembly binding.

     

    In GAC, there are some policy files which can help to redirect assembly binding to a newer version, for example Policy.12.0.Microsoft.Office.Interop.Excel will let  your application load 12.0 excel instead of 11.0 excel, even though you are referencing 11.0 excel in your project.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, July 12, 2010 2:11 AM
  • Hello Eric,

    Thank you for your posting again. I have tried fuslogvw.exe both in an x64 and an x86 version, turned on different logging targets, but never got any entry in a log.

    I tried C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64\fuslogvw.exe (Version 3.5.30729.1), for example.

    Could I have made an error?

    I know about the .net version redirection feature, but deployment of the applications using this feature (and these are 30+ apps for different customers) should be kept as easy as possible. Still, we must support Excel 2002 up to 2010. That led us to using late binding.

    Regards,


    Stefan Falk
    Monday, July 12, 2010 12:00 PM
  • Hi Stefan,

     

    Do you see Microsoft.Office.Interop.Excel.dll in C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\14.0.0.0__71e9bce111e9429c folder?  If not, can you try copying it from C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14 and see if that makes any difference?

     

    Thanks,

    Ankush

     


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Ankush Microsoft Online Community Support
    Monday, July 26, 2010 9:57 PM
  • Hello Ankush,

    Yes, this file is there (so it doesn't "make a difference"):

    PS C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\14.0.0.0__71e9bce111e9429c> gci


        Verzeichnis: C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\14.0.0.0__71e9bce111e9429c


    Mode                LastWriteTime     Length Name
    ----                -------------     ------ ----
    -a---        23.04.2010     01:24    1550200 Microsoft.Office.Interop.Excel.dll

    Best Regards


    Stefan Falk
    Tuesday, July 27, 2010 12:49 PM
  • Hi Stefan,

    I suggest to open a paid support case so that we can analyze your machine and find out the cause.  Please visit the below link to see the various paid support options that are available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

    Thanks,
    Ankush


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Ankush Microsoft Online Community Support
    Saturday, August 7, 2010 1:57 AM
  • Hi,

    I have a similar problem:

    http://social.msdn.microsoft.com/Forums/en-US/netfxsetup/thread/064696ad-3702-4cbc-b744-cb25ac385a26

    Can anyone help me?

    Monday, April 15, 2013 1:58 PM