Error when rendering

Discussions related to custom development with Select.
Post Reply
MattW
Posts: 46
Joined: Tue May 26, 2015 5:17 pm

Error when rendering

Post by MattW »

Currently we have a bug that occurs intermittently when rendering a document through the API. We have not been able to replicate it in our test environments but it still happens on occasion when live.

I'm hoping somebody could shed some light on what can be done for this.

Here is the offending code:

Code: Select all

public void PrintDocument(string documentName, dynamic context, PrinterSettings printerSettings = null)
        {
            try
            {
                if (_cursor != null)
                    _cursor = Cursors.WaitCursor;

                var docMgr = _spServer.GetService<IDocumentManager>();
                var docInfo = docMgr.Documents.Where(x => x.Identifier.Name == documentName || x.Title == documentName).First();

                var renderFactory = _spServer.GetService<IRendererFactory>();
                var renderer = renderFactory.Create();


                var rendering = (IRendering)renderer.Render(docInfo, context, null); // <----------Line where error gets thrown!!!


                var pdfTools = _spServer.GetService<IPdfToolsProvider>();

                if (printerSettings != null)
                {
                    using (var pdfStream = rendering.Export(DocumentFormat.PortableDocumentFormat))
                        pdfTools.Print(printerSettings, pdfStream);
                }
                else
                {
                    using (var printDialog = new PrintDialog())
                    {
                        if (_cursor != null)
                            _cursor = Cursors.Default;

                        if (printDialog.ShowDialog() == DialogResult.OK)
                        {
                            using (var pdfStream = rendering.Export(DocumentFormat.PortableDocumentFormat))
                                pdfTools.Print(printDialog.PrinterSettings, pdfStream);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.WriteLog();
                ExceptionExtensions.Show(ex);
            }
            finally
            {
                if (_cursor != null)
                    _cursor = Cursors.Default;
            }
        }
        private dynamic GetPrintingContext(IOrder order, string document)
        {
            switch (document)
            {
                case "PGP_150065_natInternalSearchWorksheet##":
                    return SoftProExtensions.GetFirstOrDefault(order, "Properties");
                default:
                    return order;                    
            }
        }
And the associated error it throws:
The TXTextControl components are built with framework v2.0.50727. To load a component in the 4.0 runtime add an application configuration file to the project.
at ?..ctor()
at TXTextControl.ServerTextControl.Create()
at SoftPro.Documents.Rendering.TextControl.ServerFactory.Create()
at SoftPro.Documents.Rendering.TextControl.TXTextRendererImpl.SoftPro.Documents.Client.Rendering.IRendererImpl.Render(IRenderable renderable, Object context, IPrompt`1 prompt, IProgress`1 progress, CancellationToken cancellationToken)
at SoftPro.Documents.Client.Rendering.Renderer.InternalRender(IRenderable renderable, Object context, IPrompt`1 prompt, IProgress`1 progress, CancellationToken cancellationToken)
at SoftPro.Documents.Client.Rendering.Renderer.InternalRender(IDocumentInfo document, Object context, IPrompt`1 prompt, IProgress`1 progress, CancellationToken cancellationToken)
at SoftPro.Documents.Client.Rendering.Renderer.Render(IDocumentInfo document, Object context, IPrompt`1 prompt)
at WorkBenchLibrary.Utilities.SoftProCommands.PrintDocument(String documentName, Object context, PrinterSettings printerSettings) in C:\TFS\PGPTitle\SoftPro Shell Packages\EditorFactory\WorkBench\Utilities\SoftProCommands.cs:line 150
Any insight would be appreciated, thanks in advance.
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: Error when rendering

Post by John Morris »

Can you provide the entire call stack for the error? The one you posted appears to be incomplete.
John Morris
Sr. Software Architect
SoftPro
MattW
Posts: 46
Joined: Tue May 26, 2015 5:17 pm

Re: Error when rendering

Post by MattW »

I double checked, but that is the entire stack trace that we have.
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: Error when rendering

Post by John Morris »

I'm afraid that's not possible. We should be able to see all the way back in the callstack to the launching point of the application (or thread). Make sure you have disabled the VS setting for "Show My Code". It could be hiding things from you in the IDE.
John Morris
Sr. Software Architect
SoftPro
Post Reply