[C#] aaApi_OpenDocument And aaApi_CheckOutDocument not releasing object to excel

I have spent the past two days trouble shooting my application trying to pin point the problem.

here is the issue

I have a MicroStation C# Addin. this application will write things to an excel file. this excel file is within projectwise.

if the use already has the excel file checked out and opened then it will find and attach to the running instance.

if the file is not open it will check it out and open it then it will find and attach to the running instance of excel.

when its done writing to excel I leave the excel file checked out, unsaved, and opened. I allow the end use to decide what to do with the excel file.

When the end user goes to close the file and they get prompted to check it back in. when they select check in they get another message box saying that the file is still in use..

So I thought  at first it was my code not property releasing the excel COM object. Well after trying several things I found that I was releasing it properly. So I continued on to see what else it could be.

Well I found it..

when I call the aaApi_OpenDocument call it will open the excel file. if all I do in my code is open the document and then stop (so that's not connecting to the COM object or adding data to excel or anything). So really all I did was call an Api call to open the document. Now if the use try's to check in the file they get the message imaged above.

So I'm thinking this API call has something wrong with it. don't know if its not property releasing the COM object or leaking that memory... it might be limited to a problem with just excel not sure.

Anyone have any ideas how to fix this problem. Am I doing something wrong? I don't know how I can go wrong with one api call that just opens a file. wasted two days on this to find out the problem is the api call, pretty frustrated at this point.

Parents Reply
  • Thanks Robert!

    IT WORKS!!!!

    for people doing this in c# the mcm.user.cfg file has the example of what to do but not in C#...it would look something like this..

    using BD = Bentley.DgnPlatformNET;
    ...
    
                        string strValFetchedDocsVar = "";
                        if (BD.ConfigurationManager.IsVariableDefined("PW_ADD_FETCHED_DOCS_TO_IN_USE_LIST"))
                        {
                            strValFetchedDocsVar = BD.ConfigurationManager.GetVariable("PW_ADD_FETCHED_DOCS_TO_IN_USE_LIST");
                        }
                        
                        BD.ConfigurationManager.DefineVariable("PW_ADD_FETCHED_DOCS_TO_IN_USE_LIST", "0");
    
                        //open selected file
                        bool isOpen = PWWrappers.aaApi_OpenDocument(projectID, DocID, false);
                        if(isOpen == true)
                        {
                            MessageBox.Show("Successfully opened selected document");
                        }
                        else
                        {
                            string errormsg = PWWrappers.aaApi_GetLastErrorMessage() + " \n " + PWWrappers.aaApi_GetLastErrorDetail();
                            MessageBox.Show("Failed to open selected document \n " + errormsg);
                        }
                        if (strValFetchedDocsVar == "")
                        {
                            BD.ConfigurationManager.UndefineVariable("PW_ADD_FETCHED_DOCS_TO_IN_USE_LIST");
                        }
                        else
                        {
                            BD.ConfigurationManager.DefineVariable("PW_ADD_FETCHED_DOCS_TO_IN_USE_LIST", strValFetchedDocsVar);
                        }

Children
No Data