C# XPS Document, GetFixedDocumentSequence() generate an error - c#

I'm trying to fix this error on C# but I'm really not getting it.
Here the screen of the error and where I call the function
public ReportMagazzino(XpsDocument document)
{
InitializeComponent();
this.WindowState = WindowState.Maximized;
documentViewer.Document = document.GetFixedDocumentSequence(); // Exception is generated here
document.Close();
}
Unable to create an object of type 'System.Windows.ResourceDictionary'. Error on object 'System.Windows.Documents.FixedPage', line 1, position 200
Stack Trace here:
Stack Trace
I tried to follow other threads and install a fix through power shell but nothing worked.

Related

Unknown Error Cause While Debugging WPF - 'System.AccessViolationException' occurred in SkiaSharp.dll

I am incredibly new to C# (my knowledge comes exclusively from YouTube tutorials), so please keep this in mind when viewing my novice code! I apologize in advance.
I am trying to develop a WPF desktop application using VS2022. Without going into extensive detail, the application needs to be capable of loading and displaying SVG files, as well as storing the path data. For this, I am using the SkiaSharp and Skia.Svg nuget packages.
As in the title, when the program tries to run the 'draw' function, it gives the following error:
An unhandled exception of type 'System.AccessViolationException' occurred in SkiaSharp.dll
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
The following are how I initialized the canvas, as well as the 'draw' function itself:
canvas:
SKCanvas canvas;
public void CreateCanvas()
{
SKImageInfo info = new SKImageInfo(1920, 1080);
SKSurface surface = SKSurface.Create(info);
canvas = surface.Canvas;
canvas.Clear(SKColors.Empty);
}
//not actually sure if this is an initializer oop...
public MainWindow()
{
InitializeComponent();
CreateCanvas();
}
draw function:
private void draw(string path, SKCanvas canvas)
{
var svg = new SKSvg();
svg.Load(path);
canvas.DrawPicture(svg.Picture);
}
The "path" string is simply the filepath for the desired svg. The one I've been feeding it for debug purposes is on my desktop, and I am running VS as admin. Again, I'm new to this, so I'm not sure where the error lies or what really causes it. Seeking help in determining the root cause!

EvoPdf "Insufficient Data"

At work I have encountered a problem with EvoPdf for DotNet client where it won't actually convert the html because of the following exception:
An error occured. Initialization failed: Insufficient data
The stack trace shows the following:
at am.aa()
at EvoPdf.HtmlToPdfClient.HtmlToPdfConverter.ConvertHtml(String html, String baseUrl)
at evoPdfTest.Program.Main(String[] args) in D:\git\evoPdfTest\evoPdfTest\Program.cs:line 32
This of course makes no sense, because in order to verify it wasn't anything I did, I decided to make a small console app as follows (also this same error occurs in their demo code as well.
var pdfConverter = new HtmlToPdfConverter(myIpString, myPort);
var paragraphHtml = $$"<!DOCTYPE html><html> <body> The content of the body element is displayed in your browser.</body></html> "";
pdfConverter.LicenseKey = myKey;
// Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
// Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
pdfConverter.ConversionDelay = 2;
// set PDF page size
pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
// set PDF page orientation
pdfConverter.PdfDocumentOptions.PdfPageOrientation = PdfPageOrientation.Portrait;
var pdfBytes = pdfConverter.ConvertHtml(paragraphHtml, null);
Where am I going wrong, and is this just a case of a superemly poorly written error message?
For anyone getting this error in the future:
An error occured. Initialization failed: Insufficient data
This occurs due to a mismatch in versions. In our case, we had an Azure Function running version 8.0.0 of the EvoPDF NuGet library and an Azure Cloud Application endpoint running version 7.5.0. Ensure that all services are running the same version.

Why is system.exception not serializable in send message shape?

I am testing the exception handling of my BizTalk 2010 orchestration. The orchestration has one scope shape with one catch shape attached to it.
The scope shape's transaction type is set to 'NONE' so I can work with the .NET exception. Inside the catch is a construct message shape with a message assignment shape. The message assignment shape is using the active message type from the receive shape.
When the orchestration runs it suspends on the send message shape. The error is:
Type System.Xml.XmlDocument in Assembly System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxx is not marked as serializable.
My project is set up such that for testing purposes I can process either an incoming BizTalk message or an XML file (via the test editor.)
I can take the XML that is submitted to the receive shape, save it as an XML file and process the XML file.
To test the exception handling I have purposely
coded a database insert that will fail. The full database error is written to a log file and a new exception is throw with a message like this:
Failed to process BLAH request to completion - Message Processor - Image ID: ABC Note ID: XYZ. When running the XML file, the application throws the error
in the expected place and the error is caught back at the test editor. I am able to serialize the error message in the test editor function.
However, when running from BizTalk I get the error. A correlation set has been defined with these properties:
BTS.ReceivePortName,ErrorReport.ErrorType,ErrorReport.InboundTransportLocation.
The code in the assign shape is as follows.
msgFail = InputMsg;
msgFail(ErrorReport.ErrorType) = "FailedMessage";
msgFail(ErrorReport.Description) = ex.Message;
msgFail(ErrorReport.FailureCategory) = 0;
msgFail(ErrorReport.FailureCode) = "";
msgFail(ErrorReport.InboundTransportLocation) = InputMsg(BTS.InboundTransportLocation);
msgFail(ErrorReport.RoutingFailureReportID) = System.Convert.ToString(System.Guid.NewGuid());
msgFail is the message I am trying to send.
InputMsg is the active message type from the initial receive shape. It is a multi-part message type tied to a schema that validates.
ex is the exception object name in the catch shape. It is of type System.Exception.
I've read many posts about how to set the properties for the scope and catch shapes to be able to use the exception object, but it is still not working.
I am making an assumption that since I can serialize the error message when running from the XML file that my problem is with how my orchestration is getting the exception.
If you have the ESB Toolkit installed you can use that to create your fault messages.
e.g
eSBFault = Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt.CreateFaultMessage();
eSBFault.FailureCategory= "General System Exception";
eSBFault.FaultCode = "500";
eSBFault.FaultDescription = orchestrationName + ": " + ex.Message;
eSBFault.FaultSeverity = Microsoft.Practices.ESB.ExceptionHandling.FaultSeverity.Error;
eSBFault.Scope = "Scope Name";
Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt.AddMessage(eSBFault, InputMsg);
Note 1: orchestrationName is a variable that was set earlier in the Orchestration
orchestrationName = Microsoft.XLANGs.Core.Service.RootService.Name;
Note 2: Your msgFail is eSBFault in this example, but you can call it msgFail as well. It is of Message Type Microsoft.Practices.ESB.ExceptionHandling.Schemas.Faults.FaultMessage

Line numbers in stack traces for UWP apps

I created a blank Universal Windows App project in Visual Studio 2015.
I add something like:
try {
string foo = null;
int len = foo.Length;
} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine(ex);
}
I get a stack trace like:
Exception thrown: 'System.NullReferenceException' in TestStackTraces.exe
System.NullReferenceException: Object reference not set to an instance of an object.
at TestStackTraces.App.OnLaunched(LaunchActivatedEventArgs e)
i.e., No line numbers.
How do I get line numbers to show up?
This appears to be no longer supported. I am re-posting my answer here, because when I did a search for my answer on another question, it was very difficult to find it in the search results. Hopefully this question will help people find this info easier.
Reference: windows 10 exceptions not including line numbers
Other info:
See corefx #1420 and related corefx #1797.
Also, there is this reference on SO: How to get StackTrace without Exception in Windows Universal 10 App

Unit test throwing NullReferenceException

I've been trying to run a test on a method that loads data from an xml file and returns it as a list, however, I keep getting a NullReferenceException when it runs. I've checked and my filepath is fine.
[TestCase(1)]
public void firstTest(int num)
{
var studentList = StudentListGenerator.CreateStudentList(#"../../TestReport/TestData.xml");
Assert.IsTrue(studentList.Count() > num);
}
The stack trace points back to a line of code in my CreateStudentList method that works just fine if I insert it directly into the test itself (the method as a whole works well when I run it normally).
String xData = File.ReadAllText(filePath);
var x = new XmlSerializer(typeof (Report));
Report dataConverted = (Report) x.Deserialize(new StringReader(xData));
// the last line is where the stack trace ends
Anyone have a guess as to where I'm going wrong?
EDIT:
Here's a link to some of the StudentListGenerator class, which contains the CreateStudentList method: https://gist.github.com/jekrch/eecdd1c8de8a11268be0
And here's the full stacktrace:
at PFdata.Dashboard.Data.StudentListGenerator.CreateStudentList(String
filePath) in
C:\Users\CodeCamp\Desktop\StudentDataDashboard\StudentDataDashboard\Dashboard.Data\StudentListGenerator.cs:line
41 at DashboardTests.StudentDataCalcTests.firstTest(Int32 num) in
C:\Users\CodeCamp\Desktop\StudentDataDashboard\DashboardTests\StudentDataCalcTests.cs:line
22 Result Message: System.NullReferenceException : Object reference
not set to an instance of an object.
So the stacktrace on the original error was misleading. The real source of the NullReferenceException in the CreateStudentList method that I was testing was the following line:
Application.Current.Properties["reportMonth"] = reportMonth;
The problem was that the Application class was not being instantiated by the test. So the solution was to simply instantiate the application at the beginning of the test like so,
var app = new Application();
I got the idea to try this from a comment by Ben Raupov regarding a question about a similar issue. Many thanks to Unicorn2 for helping me factor out a number of other possibilities.

Categories

Resources