Interop Error 80010001 Call was rejected by callee in PPTX generation

0

I am converting some images to ppt slide and downloding the ppt once its fininshed. by using Microsoft.Office.Interop.PowerPoint. while I am running the application its working as expected, but while I am deploying in the same machine IIS is giving me the below error.

PreparePPT: System.Runtime.InteropServices.COMException (0x80010001): Retrieving the COM class factory for component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} failed due to the following error: 80010001 Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)). at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType) at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType) at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj) at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at MyApp.AutoComplete.PreparePPT(List`1 ImageDetails) in D:\Project\ExporttoPPT\appWebService.asmx.cs:line 293

I have given privilages to NETWORK SERVICES for accessing Remote Launch, Activations. But still I am getting the same error. My sample code is

public string PreparePPT(List<ImageDetails> ImageDetails)
    {
        try
        {
            string path = "//FilesStorage//TempFiles//";
            string fileName = "Dashboard.pptx";
            string fullPath = Server.MapPath(path + fileName);
            Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Slides slides;
            Microsoft.Office.Interop.PowerPoint.Slide slide;
            Microsoft.Office.Interop.PowerPoint.TextRange objText;
            Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = pptApplication.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);
            int inCount = 1;
            foreach (var item in ImageDetails)
            {
                string strImgPath = Server.MapPath("Images");
                string base64 = item.Data.Split(',')[1];
                byte[] bytes = Convert.FromBase64String(base64);
                System.Drawing.Image image;
                using (MemoryStream ms = new MemoryStream(bytes))
                {
                    image = System.Drawing.Image.FromStream(ms);
                    strImgPath = Server.MapPath("//FilesStorage//TempFiles//") + "Image_" + inCount + ".png";
                    image.Save(strImgPath);
                    item.ImagePath = strImgPath;
                    ms.Close();
                }
                Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];
                // Create new Slide
                slides = pptPresentation.Slides;
                slide = slides.AddSlide(inCount, customLayout);
                // Add title
                objText = slide.Shapes[1].TextFrame.TextRange;
                objText.Text = item.Title;
                objText.Font.Name = "Arial";
                objText.Font.Size = 22;
                objText = slide.Shapes[2].TextFrame.TextRange;
                Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
                slide.Shapes.AddPicture(item.ImagePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);
                inCount++;
            }
            pptPresentation.SaveAs(fullPath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);
            pptPresentation.Close();
            pptApplication.Quit();
            foreach (var item in ImageDetails)
            {
                if (File.Exists(item.ImagePath))
                {
                    File.Delete(item.ImagePath);
                }
            }
            return fullPath;
        }
        catch (Exception ex)
        {
            return "Error Occured: PreparePPT - " + ex.Message.ToString();
        }
    }

Any help will be highly appriciated.

c#
interop
powerpoint-interop
asked on Stack Overflow Sep 26, 2018 by Jzl

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0