简体   繁体   中英

Create video from powerpoint slides via C# throws The remote procedure call failed. (Exception from HRESULT: 0x800706BE)

I have a Windows desktop C# app which is to export user's pptx to mp4 programmatically.

I have code here:

try
{
    Application application = new Microsoft.Office.Interop.PowerPoint.Application();

    Presentation ppt = application.Presentations.Open("myppt.pptx", MsoTriState.msoFalse,  
    MsoTriState.msoFalse, MsoTriState.msoFalse);

    ppt.CreateVideo("myppt.mp4");

}
catch (Exception ex)
{
    logger.Error(ex.Message);
}

Everything works fine and video is created successfully with Powerpoint 2016 and older version Office 365 powerpoint. However after I upgraded Office 365 to latest version 2203 (15028.20160), CreateVideo() always failed and throws exception: "The remote procedure call failed"

System.Runtime.InteropServices.COMException (0x800706BE): 遠端程序呼叫失敗。 (發生例外狀況於 HRESULT: 0x800706BE)
於 Microsoft.Office.Interop.PowerPoint._Presentation.CreateVideo(String FileName, Boolean UseTimingsAndNarrations, Int32 DefaultSlideDuration, Int32 VertResolution, Int32 FramesPerSecond, Int32 Quality) 

I have also tried Presentation.SaveCopyAs(...) and Presentation.Slides[x].Export(...) and these functions work fine.

Any help would be appreciated.

Update:

CreateVideo() works if set "WithWindow" parameter to true in Presentation ppt = application.Presentations.Open("myppt.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState. msoTrue )

But I don't know the reason...

Use the Office Deployment Tool to roll back to a prior version of Office where the long-established behavior you're depending on worked. They broke it in release 2203, so rolling back to 2202 or earlier will fix it.

This config.xml file works:

<Configuration>
  <Updates Enabled="TRUE" TargetVersion="16.0.14931.20132"/>
</Configuration>

System.Runtime.InteropServices.COMException (0x800706BE)

This exception typically indicates that you trying to automate PowerPoint from a web service or ASP.NET application.

The Considerations for server-side Automation of Office article states the following for that scenario:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

You may consider using the Open XML SDK if you deal with open XML documents or consider using third-party components designed for the server-side execution.

It would be better if your app did not depend on MS Office. Aspose.Slides Cloud SDK for .NET can provide such a requirement. It does not require PowerPoint installed. This product provides a REST-based API for presentation processing. It is a paid product, but you can make 150 free API calls per month for experimentation, learning, and any other purpose.

The following code example shows you how to convert a presentation to a video file using Aspose.Slides Cloud SDK for .NET:

var slidesApi = new SlidesApi("my_client_id", "my_client_secret");

// Set options for the output video.
var videoOptions = new VideoExportOptions
{
    VideoResolutionType = VideoExportOptions.VideoResolutionTypeEnum.FullHD
};

// Convert a presentation file to a video file.
using var presentationStream = File.OpenRead("example.pptx");
using var videoStream = slidesApi.Convert(presentationStream, ExportFormat.Mpeg4, options: videoOptions);

// Save the result to a file.
using var outputStream = File.Create("output.mp4");
videoStream.CopyTo(outputStream);

Sometimes it is necessary to convert presentations to videos without any code. For such cases, you can use a free PowerPoint to Video Converter .

I work as a Support Developer at Aspose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM