NetOfficeFw / NetOffice

🌌 Create add-ins and automation code for Microsoft Office applications.
MIT License
697 stars 143 forks source link

Failed to proceed PropertySet on PowerPoint.ParagraphFormat=>Alignment. #317

Closed kevin-vanderwende closed 3 years ago

kevin-vanderwende commented 3 years ago

I have an app that takes multiple PowerPoint files into one presentation. I have experienced issues with "Failed to proceed..." on several things. The way I have mitigated this was I put in a sleep function with a configurable duration to slow things down. I had noticed that I was having slides added in the wrong place which meant my merging was going too fast and I needed to control that. I recently added code to add text to the bottom of a slide. If I set my delay high enough I don't run into the PropertySet error but it is inconsistent. Sometimes it works with a delay of 250ms. Sometimes it fails with 2500ms. The code causing the issue is below: var txtBox = slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, txtBoxLeft, txtBoxTop, txtBoxSize.Width, txtBoxSize.Height); var textRange = txtBox.TextFrame.TextRange; textRange.ParagraphFormat.Alignment = (PpParagraphAlignment)configSettings.SongSlideFooterTextAlign;

I tried modifying the DCOM settings I read about in another issue but that didn't change the behavior.

jozefizso commented 3 years ago

Is you app using automation to run PowerPoint code, or do you have an Add-in which is running inside PowerPoint?

kevin-vanderwende commented 3 years ago

Is you app using automation to run PowerPoint code, or do you have an Add-in which is running inside PowerPoint?

Automation. Create a new presentation with window then Copy/Paste with Formatting.

jozefizso commented 3 years ago

It is normal for the Office apps to be unresponsive when using automation. As the automation cannot be in sync with the main thread of the Office app, the code will fail more often and you must write a lot of retry logic to make sure the code will get eventually executed.

Adding delays to the code may help, but there is no way to sync the automation code to the main thread of the Office app.

kevin-vanderwende commented 3 years ago

Thanks for the information. I will try the retry logic.

On Mon, Mar 22, 2021 at 7:36 AM Jozef Izso @.***> wrote:

It is normal for the Office apps to be unresponsive when using automation. As the automation cannot be in sync with the main thread of the Office app, the code will fail more often and you must write a lot of retry logic to make sure the code will get eventually executed.

Adding delays to the code may help, but there is no way to sync the automation code to the main thread of the Office app.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/NetOfficeFw/NetOffice/issues/317#issuecomment-803995143, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL44X2PHNNV5H7VYMWLOUNTTE4TUZANCNFSM4ZS4PAPA .

kevin-vanderwende commented 3 years ago

Turned out I was never initializing my align option that I store in app.config so when I tried to set TextRange.ParagraphFormat.Alignment I was using in invalid value. The enum PpParagraphAlignment has -2 and 1-7. I was attempting to set it to 0. The reason it seemed intermittent is I would change the setting then run and it would work. Close the app and reopen and it reset to 0.

kevin-vanderwende commented 3 years ago

I've been meaning to close the loop on this. I've just recently updated my code. jozefizso was correct about retry logic. I added Polly to my project and implemented WaitAndRetry to only alert the user that something went wrong after a configured number of retries. I have not had any transient exceptions thrown as a message box since.

Thanks so much.