如何解决此问题:-RPC服务器不可用。 (来自HRESULT的异常:0x800706BA)错误导致了getxception。 [英] How to resolve this issue :-RPC server is unavailable. (Exception from HRESULT: 0x800706BA) error is causing comexception .

查看:141
本文介绍了如何解决此问题:-RPC服务器不可用。 (来自HRESULT的异常:0x800706BA)错误导致了getxception。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am splitting the powerpoint presentation into multiple slides at that time this rpc error is coming , i already googled but not able to understand the cause of the problem. please help...!!
 <pre lang="c#">private void splitpptintomultipleslide(string path)
        {
            string realfilename = Path.GetFileNameWithoutExtension(path);
            Microsoft.Office.Interop.PowerPoint.Application pptapp = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentation ppt1 = pptapp.Presentations.Open(path, Microsoft.Office.Core.MsoTriState.msoFalse,
            Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
            
            int j = ppt1.Slides.Count;
            x = 1;            
            try
            {              
                   string path1 = @"D:\practice\"; // or whatever 
                   if (!Directory.Exists(path1))
                   {
                       Directory.CreateDirectory(path1);
                       for (int i = 1; i <= j; i++)
                       {
                           string s = i.ToString();                           
                           string fullpath = path1 + realfilename + s + ".ppt";
                           string fullpathofimage = path1 + realfilename + s + ".png";
                           while (x == i)
                           {                               
                               <big>ppt1.Slides[x].Export(fullpath, "ppt");</big>
                                                    
                               <big>ppt1.Slides[x].Export(fullpathofimage, "png", 320, 620); </big>                                                           
                               x++;                               
                               ppt.Add(fullpath);                               
                              png.Add(fullpathofimage);                              
                           }
                       }
                   }
                   else
                   {
                       for (int i = 1; i <= j; i++)
                       {                          
                           string s = i.ToString();
                           string fullpath = path1 + realfilename + s + ".ppt";
                           string fullpathofimage = path1 + realfilename + s + ".png";
                           while (x == i)
                           {                               
                               <big>ppt1.Slides[x].Export(fullpath, "ppt"); </big>                                                                                      
                               <big>ppt1.Slides[x].Export(fullpathofimage, "png", 320, 620);</big>                                                              
                               x++;
                               ppt.Add(fullpath);                               
                              png.Add(fullpathofimage);                               
                           }
                       }
                   }                
            }
            finally
            {
                ppt1.Close();
                pptapp.Quit();
            }
        }

推荐答案

首先我在一个系统中安装了两个不同系统的这些代码MS Office 2013安装和其他MS 2010: -



2013年我遇到了这个问题所以我尝试在2010年的其他系统中问题不在那里,但我的代码不是很好,所以我重构代码现在我的解决方案工作正常。



有一点需要注意: -

我们正在使用MS Office appliaction所有的MS Office都是单线程的所以我们必须明智地思考它们使用它。假设你使用它然后你必须立即释放它,当它的工作完成时我们可以通过两种方式做到这一点: -



1): - 首先发布所有您在命名变量中没有引用的次要对象。您可以通过cal到GC.collect()并在调用GC.WaitForPendingFinalizers()之后执行此操作。



注意: - 如果您使用的是VSTO,那么您需要调用此对2次才能使Com对象成功释放。否则1就够了。



2): - 然后使用对每个变量调用Marshal.FinalReleaseComObject()通过命名变量显式释放你持有的对象有。



请记住明确释放您在com组件中使用的所有变量。如果你错过了一个,那么你的MS Office应用程序将会挂起。





例如: -

GC。收集();

GC.WaitForPendingFinalizers();



ppt1.Close();

Marshal。 FinalReleaseComObject(ppt1);



pptApp.Quit();

Marshal.FinalReleaseComObject(pptApp);







即使这个解决方案在2010环境下运行良好,但它在2013环境中无法工作,所以你必须看看它在哪里使用,如果你们有更好的解决方案,请在这里发布。



这篇文章是从网上复制的,不是我的。
First of all i used these code in two different system in one system had installed MS office 2013 installed and in other MS 2010 :-

in 2013 i am having this issue So i try with in other system with 2010 the issue was not there but my code was not in good shape so i refactored the code now my solution is working fine.

one thing to note:-
we are using MS Office appliaction all the MS Office are single threaded so we have to think wisely whethet to use it. Suppose if you are using it then you have to immediate release it when its work is done we can do this by two ways :-

1) :- First release all the minor objects to which you don't hold a reference within a named variable . You do this via a cal to GC.collect() and after that Call GC.WaitForPendingFinalizers() .

Note :- if you are using VSTO then You need to call this pair 2 times in order to get the Com objects to succefully release . otherwise 1 is enough.

2) :- Then explicitly release the objects which you hold via a named variable using a call to Marshal.FinalReleaseComObject() on each variable you have.

Remember to explicitly release all variables that you had use in com components . if you miss even one then your MS Office Application will hang.


example:-
GC.Collect();
GC.WaitForPendingFinalizers();

ppt1.Close();
Marshal.FinalReleaseComObject(ppt1);

pptApp.Quit();
Marshal.FinalReleaseComObject(pptApp);



Even this solution is working fine 2010 environment but its not working in 2013 environment so you have to see where to use it , if you guys have any better solution then please post it here .

this article is copied from internet , it was not mine .


这篇关于如何解决此问题:-RPC服务器不可用。 (来自HRESULT的异常:0x800706BA)错误导致了getxception。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆