none
Infopath, Unable to cast COM object Interface not registered (full exception in post) RRS feed

  • Question

  • Hey all! 

    I'm trying to run some infopath code in a project using the interop.dll 

    myApp = new Application();
                    myXDocs = myApp.XDocuments;
                    myXDoc = myXDocs.Open(filepath);
                    myViewInfos = myXDoc.ViewInfos;

    When I hit the third line, I get this error "{"Unable to cast COM object of type 'Microsoft.Office.Interop.InfoPath.XDocumentsCollectionClass' to interface type 'Microsoft.Office.Interop.InfoPath.XDocuments2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{096CD647-0786-11D1-95FA-0080C78EE3BB}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155)."}"

    Here's what the .dll properties looks like https://gyazo.com/656ecff7c24abb5524cf07406bb0b033

    Any clue what's up? I've tried searching for similar issues but they mostly deal with other office products.

    Thanks! 

    Sunday, October 1, 2017 11:16 PM

All replies


  • Hello,

    Please check if you could manually open the file. Please test if the code works for a new file like the following XML.

    <?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.1" productVersion="15.0.0" PIVersion="1.0.0.0" href="file:///C:\Users\v-chencl\Desktop\Form1.xsn" name="urn:schemas-microsoft-com:office:infopath:Form1:-myXSD-2017-10-02T08-40-09" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.4"?><my:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2017-10-02T08:40:09" xml:lang="en-us"></my:myFields>

    What project do you create? Please create a console application and test the code above.

    Here is my code which works for me.

    using Microsoft.Office.Interop.InfoPath;
    namespace CSPro
    {
        class Program
        {
            static void Main(string[] args)
            {
                Application app = new Application();
                // app.XDocuments.NewFromSolution(@"D:\Form1.xsn");
                XDocuments myXDocs = app.XDocuments;
                XDocument myXDoc= myXDocs.Open(@"D:\Form3.xml");
                ViewInfos myViewInfos = myXDoc.ViewInfos;
            }
        }

    Regards,

    Celeste


    Monday, October 2, 2017 9:10 AM
    Moderator