2 posts, 0 answers
  1. Serhat
    Serhat avatar
    2 posts
    Member since:
    Sep 2012

    Posted 28 Apr 2014 Link to this post

    We are getting System.ComponentModel.Win32Exception error while  converting XAML to PDF at WCF WebSevice. Interestingly WCF Service sometimes getting this error, sometimes not. Also this code working inside a Thread otherwise it gives a STA Thread Exception . 

    Telerik dll version : 2013.1.527.45  AND .Net 4.5

    Code and detailed error is shown below. Please immediate help.

    byte[] XAMDataToBeConverted;

     var xamlProvider = new Telerik.Windows.Documents.FormatProviders.Xaml.XamlFormatProvider();
     radDocument = xamlProvider.Import(XAMDataToBeConverted); //Getting Error on this line
     xamlProvider = null;

    The Error detail is 

    'The invocation of the constructor on type 'Telerik.Windows.Documents.Model.RadDocument' that matches the specified binding constraints threw an exception.' Line number '1' and line position '569'. System.Windows.Markup.XamlParseException Seneka.Ebdys.Server.Services.HelperClasses.RadRichTextBoxHelperServer CreatePdfSimple "System.Windows.Markup.XamlParseException: 'The invocation of the constructor on type 'Telerik.Windows.Documents.Model.RadDocument' that matches the specified binding constraints threw an exception.' Line number '1' and line position '569'. ---> System.ComponentModel.Win32Exception: The operation completed successfully
       at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
       at System.Windows.Threading.Dispatcher..ctor()
       at Telerik.Windows.Documents.Model.MailMergeDataSource..ctor()
       at Telerik.Windows.Documents.Model.RadDocument..ctor()
       at System.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments)
       at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)
       --- End of inner exception stack trace ---
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       at System.Windows.Markup.XamlReader.Load(XamlReader xamlReader, ParserContext parserContext)
       at System.Windows.Markup.XamlReader.Load(XmlReader reader, ParserContext parserContext, XamlParseMode parseMode)
       at Telerik.Windows.Documents.FormatProviders.Xaml.XamlFormatProvider.Import(Stream input)
       at Telerik.Windows.Documents.FormatProviders.DocumentFormatProviderBase.Import(Byte[] input)
       at Seneka.Ebdys.Server.Services.HelperClasses.RadRichTextBoxHelperServer.CreatePdfSimple()"

  2. Boby
    Boby avatar
    588 posts

    Posted 30 Apr 2014 Link to this post

    Hi Serhat,
    The version you are using has a limitation implying that RadDocument should be used only in STA thread. This most probably leads you to an issue in .NET framework, related to a large number of threads created. You have two options:
    - Upgrade to the latest version. Now RadDocument can be used in normal (MTA) background thread, moreover some concurrency issues are overcome (import/export is now thread-save).
    - Try the workaround suggested in the mentioned Connect issue:

    You can work around this bug by adding the following code to your thread proc:
    Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
    This asks the dispatcher associated with the thread to shut down right away.

    I hope this helps.

    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
  3. DevCraft banner
Back to Top