[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
  • You are opening the document from a session of Microstation using ProjectWise Explorer which launches Excel, then leaving it up to the end user to do something. That seems to be a lot of handles on the document.  It becomes more complex if the Microstation document was opened from ProjectWise.

  • well yes it is a microstation addin. im integrating it with ProjectWise. So yes the user opens the microstation dgn file from ProjectWise (we have a managed workspace). now within microstation the user launches the addin. this addin will already have the session of ProjectWise since microstation was opened from ProjectWise (so no need to log in).

    Now this addin does things like pull info from the dgn file, then when the user is ready they hit a button to output this info to an excel file. the excel file already exists in PW (its a template that gets filled out for every project).

    I have limited my code to only open the document and do nothing else. all I do is use the aaApi_OpenDocument() api call. that should not be holding onto anything but it is.

    I don't think that's a lot of handles on the document. and its not that out of the question to want to open a document.

    I defiantly seems like its not releasing the excel COM object property.

    not ruling out its something in my code but I removed everything except opening the file.

  • I ran that handle but I just passed part of the excel file name as the parameter and it only returned that excel.exe was using it. assuming the way I did it is okay.

    I made a stand alone app and logged into ProjectWise and simply called the aaApi_opendocument() api call and I have no problem closing the excel file with the application still running.

    I did another test in my addin where after the dialog loads I have a button and when clicked the only code I have to the aaApi_OpenDocument(). now when I close the excel file I get the dialog imaged in my original post.

    Again once I close out of microstation completely I can close the excel file no problem. so closing microstation completely will release the object.

    Im at a loss, I don't think there is anything on my end I can do to fix this problem. I cant not use the opendocument api call.

    hopefully we can get this resolved I cant be the only person who wants to open a file from ProjectWise from a microstation addin.

  • Hi John,

    I did not mention to run handle -a when all your conditions are aligned and in the bad state just prior to attempting to close Excel.exe.

    Can you test and confirm your code works or does not, having no ProjectWise MCM being loaded and open a local Excel file (to eliminate ProjectWise and aaApi_OpenDocument as factors)?

    Also after providing the outcome of the test above and if the problem persists please consider posting your project source code in simplest form as a "test case" to ensure using the same code and allow reproduction of the issue to further accelerate reproduction and/or resolution.

    Thank you in advance,
    Bob



  • I ran the handle again with the -a and it only comes back with EXCEL.EXE is using that file. I don't know the inner workins of ProjectWise. But hopefully Bentley developers can look at the code to see what checks are being done to prompt the user that the file is still in use and go from there.

    When the excel file is outside of ProjectWise versus inside project wise is not a directly comparison. When the file is outside of ProjectWise it does several things. first it looks to see if the file is already open, if its already open then I attach to that. if its not open I see if there is a running instance of excel and if so ill attach to that then open the file. if no instance of excel if running then I will start one and open the file and attach to it.

    I have testing this side of the code and the COM objects are all being properly released. this has been verified.

    I spent two days going through all that code before posting this because that was my first thought.

    so I'm pretty confident that I narrowed the problem down to the open document api call I have also found that using the aaApi_CheckOutDocument() call causing the same problem. maybe the problem is with that call since the opendocument call checks out the file as well.

    I made a really basic microstation wpf c# addin so others can reproduce the problem. the addin is one window that has one button.

    select the button and a ProjectWise document select dialog comes up. select an excel fileand the code simply calls the OpenDocument api call and that's it.

    here is the zip file of the entire source code

    ExcelProblem.zip

    STEPS TO REPRODUCE

    1. download and unzip the attached file

    2. open the solution (ExcelProblem) from microstation developer command shell.

    3. build solution via developer shell (bmake -a -ddebug ExcelProblem)

    4. copy everything inside the bin/debug folder to the mdlapps folder (C:\Program Files\Bentley\MicroStation CONNECT Edition\MicroStation\Mdlapps)

    5. open a dgn from ProjectWise to MicroStation connect.

    6. in visual studio for the ExcelProblem solution select Debug > Attach to Process. and then select the microstation connect instance.

    7. now in microstation connect use the following key ins to load and open the addin

           mdl load ExcelProblem

           ExcelProblem open

    8. make sure you have an excel file inside ProjectWise

    9. hit the only button in the excel problem addin, select the excel file, and the excel file should be opened.

    10. now try to close excel an you should get the box to checkin/free.. if you select check in you will then get the file in use messagebox.

    Hopefully this is clear if not let me know.

  • Hi ,

    Thank you for providing the test case to help ensure we could accurately reproduce the issue.  After further review our development team has verified this behavior is not working properly and Defect 1086379 has been filed to address the issue.  Please note this issue has been reviewed and prioritized by product management for inclusion in a future release.

    In the interim until a fix becomes available one proposed work-around could be:

    • Check out the file
    • Copy it to a temp folder
    • Open it with Process.Start()
    • Modify the copy of the checked out document
    • Replace the original document with the modified
    • Check in the modified document

    HTH,
    Bob



    Answer Verified By: John Drsek 

  • thanks for looking into that. 

    I did test your work around and it does work. but for my needs i cant really do that.

    i have a couple apps that need this fix. but in general the application will open and interact with the excel file doing various things. but i dont plan on having the application save or check in the file. Im leaving that for the user to decide what they want to do. maybe they get half way though and they dont like the results they can decide to close and free the file. Or maybe they use the app and it does alot of stuff to the excel file but then they are done with the ORD/microstation app and will keep working with the excel file to do other things and might close the app. 

    So since it is so interactive i cant really save and check in the file on close or during the process. So the work around isnt applicable. ill just have to wait for the fix to be released.

Reply
  • thanks for looking into that. 

    I did test your work around and it does work. but for my needs i cant really do that.

    i have a couple apps that need this fix. but in general the application will open and interact with the excel file doing various things. but i dont plan on having the application save or check in the file. Im leaving that for the user to decide what they want to do. maybe they get half way though and they dont like the results they can decide to close and free the file. Or maybe they use the app and it does alot of stuff to the excel file but then they are done with the ORD/microstation app and will keep working with the excel file to do other things and might close the app. 

    So since it is so interactive i cant really save and check in the file on close or during the process. So the work around isnt applicable. ill just have to wait for the fix to be released.

Children
No Data