0

I am getting this error with inner exception "The calling thread must be STA because many UI components require this."

System.Windows.Markup.XamlParseException: ''The invocation of the constructor on type 'System.Windows.Documents.DocumentReference' that matches the specified binding constraints threw an exception.' Line number '1' and line position '130'.'

This is not a WPF application. It is a winforms client application which connects to a windows service that always runs in the background. The windows service calls a class libray. This code resides in the class libray. I am thinking this windows service is multi-threaded because of the nature of a windows service. So this error? How do I fix it is the question?

I have the same code in a standalone test application where there are no services nothing. Just a simple winforms where in Form_load I do the processing. That works fine. Only when I access this code from the original application this error occurs

 var path = @"C:\Filess\2020-5-14\username2020514232518460.xps";
        using (XpsDocument xpsDoc = new XpsDocument(path, FileAccess.Read))
        {
            FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence(); //error occurs here
          // return //SaveDocumentPagesToImages(docSeq.DocumentPaginator.Source//, tiffsavePath);
        }

enter image description here

user575219
  • 2,346
  • 15
  • 54
  • 105
  • 1
    A [mcve] would be great here. – Enigmativity May 15 '20 at 05:13
  • There is nothing else the sample does except the few lines posted above. It's just form load where I have those few lines – user575219 May 15 '20 at 05:20
  • 1
    @user575219 - That's not the point. The point is that you do the work to create code that I can run to see the issue you're experiencing. The process of doing that may solve your problem and it will give me the ability to try too. Otherwise it's too hard for me - and probably everyone else. – Enigmativity May 15 '20 at 05:43

0 Answers0