System.ComponentModel.Win32Exception

4 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
    Admin
    Boby avatar
    636 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;
    dispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
    Dispatcher.Run();
    This asks the dispatcher associated with the thread to shut down right away.



    I hope this helps.

    Regards,
    Boby
    Telerik
     
    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. Muhammad
    Muhammad avatar
    2 posts
    Member since:
    Nov 2013

    Posted 12 Jun Link to this post

    We are getting the exception as below get this exception, This code is importing an valid XML from data base to RADdocument. This code is working fine on our local systems and never produce any issue but in production environment Sometimes it throws below Exception.Moreover we are not using the STA Thread.

    we are using .Net 4.0 and version of Telerik.Windows.Documents.DLL : 2014.1.331.40

    Below is the code which is producing Exception.

    RadDocument radDocument = null;
     try { tMPL_CNFGInfo = instance.GetStationeryConfigDetails(requestObject).ResultSet;
          XamlFormatProvider xamlFormatProvider = new XamlFormatProvider();                     
          radDocument = xamlFormatProvider.Import(tMPL_CNFGInfo.TEMPLATECONFIGBODY);}            
     catch (System.Exception ex)

     

    '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'.

    Type: System.Windows.Markup.XamlParseException:
    Source:
    PresentationFramework
    Data:
    Stack Trace:    at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, Boolean skipJournaledProperties, 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 System.Windows.Markup.XamlReader.Load(XmlReader reader)
       at System.Windows.Markup.XamlReader.Parse(String xamlText)
       at Telerik.Windows.Documents.FormatProviders.Xaml.XamlFormatProvider.Import(String input)
       at NFS.Business.Services.StationaryService.evaluateDocument(RequestObject`1 requestObject)

    ===INNER EXCEPTION===

    The operation completed successfully

    Type: System.ComponentModel.Win32Exception:
    Source:WindowsBase
    Data:
    Stack Trace:    at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D wc_d)
       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 System.Windows.Threading.Dispatcher.get_CurrentDispatcher()
       at Telerik.Windows.Documents.Model.MailMergeDataSource..ctor()
       at Telerik.Windows.Documents.Model.RadDocument..ctor()
       at System.Xaml.Schema.XamlTypeInvoker.DefaultCtorXamlActivator.InvokeDelegate(Action`1 action, Object argument)
       at System.Xaml.Schema.XamlTypeInvoker.DefaultCtorXamlActivator.CallCtorDelegate(XamlTypeInvoker type)
       at System.Xaml.Schema.XamlTypeInvoker.DefaultCtorXamlActivator.CreateInstance(XamlTypeInvoker type)
       at System.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments)
       at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType, Object[] args)
       at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)

  4. Boby
    Admin
    Boby avatar
    636 posts

    Posted 13 Jun Link to this post

    Hello Muhammad,

    The problem is exactly the same. MailMergeDataSource is DependencyObject, which causes this problem as it starts dispatcher which is not properly stopped.

    Microsoft provided workaround in a bug report here:https://connect.microsoft.com/VisualStudio/feedback/details/620588/system-componentmodel-win32exception-0x80004005-not-enough-storage-is-available-to-process-this-command, namely:
    ------------------------------
    Put the following code:

    Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
    dispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
    Dispatcher.Run();

    anywhere in the background thread processing the RadDocument.


    Regards,
    Boby
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top