Application crashes on element reader (pdftron) - c#

I have an issue with pdftron, where opening a certain file, will cause our application to crash with following error:
An unhandled exception of type 'pdftron.Common.PDFNetException' occurred in PDFNet.dll
Additional information: Exception:
Message: Missing resource
Conditional expression: res
Filename : ContentResources.hpp
Function : trn::PDF::ContentResources::GetResource
Linenumber : 26
In our code: it's in the following line that the error occurs:
while ((element = elReader.Next()) != null)
When doing try/catch, we see that the only thing missing from the page is the text that's written diagonally on that page. Does this have anything to do with a missing font maybe ? Don't mind the cursor in the picture, it doesn't know where to go with the text missing.
I can send the pdf file on request.
PDF File

If you are not on the latest version of PDFNet, 6.7.1, then I would first try against that, as the issue might have been resolved already.
Otherwise, since the issue is document specific, you would need to provide that, by either sharing here, or sending to pdftron support.

Related

c# firestore - Additional information: Path cannot contain empty elements

I'm trying to check if a document exists from my firestore DB but am getting an error before it checks if it exists so I'm a bit confused. I would think my documentsnapshot would return null after the .GetSnapshotAsync() call first however it is just tripping an error and not able to get to the if (docSnapshot.Exists) line.
Context: I am switching over from realtime database to Firestore so the paths are not the same. In this case, lastPath is not empty but it is a realtime database path. Therefore, the line is checking for a realtime database path and is expected to return false.
lastPath = MyCollection/Projects/6f8ebcf7-231f-47e5-ac72-2707cd38ae8f/
The error that occurs: Additional information: Path cannot contain empty elements
So far, I've tried:
The following code is:
DocumentReference documentReference = firestoredb.Document(lastPath); // <<-- throws error not able to continue
and
DocumentSnapshot docSnapshot = await firestoredb.Document(lastPath).GetSnapshotAsync(); // <<-- Also throws error.
Here is the code that follows:
if (docSnapshot.Exists)
{
// do this
}
else if (!docSnapshot.Exists)
{
// do this instead.
}
I can only think of doing a try-catch but I am hoping there is a better way to check if the document exists.
I checked the docs but I keep getting the error and the other posts I've found on SO show mostly for android.
Any and all help is appreciated.

Why different error codes for same Exception?

I am doing one synchronization example. I got two exceptions which are having same details about exception. But with the error codes.
And both exceptions have the same Inner Exceptions
What is means? What Error Codes will tell us more than exceptions?
How to get the details about my error code.
Thanks in Advance
Microsoft.Synchronization.SyncException: A storage engine operation failed with error code 25051 (HRESULT = 0x80004005, Source IID = {0FB15084-AF41-11CE-BD2B-204C4F4F5020}, Parameters=(0, 0, 0, , , , )).
Microsoft.Synchronization.SyncException: A storage engine operation failed with error code 25009 (HRESULT = 0x80004005, Source IID = {0FB15084-AF41-11CE-BD2B-204C4F4F5020}, Parameters=(0, 0, 0, , , , )).
From the wording of the message it looks like these are SQL CE errors. If so, have a look here for the meaning of the actual error codes. For .NET code that wraps native code, it is not uncommon that one managed exception, SyncException here, is used with multiple error codes in addition (most prominent example Win32Exception).
From the documentation there seems to be no apparent way to get this numeric code.
However, whether you can really react differently in your code, depending on one error code or the other, is questionable anyway. Log the error with all details
and be done with it.
Finally got cleaned after reading the documentation

How does one lookup the error number in Windows EventLogEntry Message

I am trying to read through the Windows Event log "Error" entry messages in in c#.
foreach (EventLogEntry log in eventLog.Entries)
{
if (log.EntryType.ToString() == "Error")
{
Console.WriteLine( log.Message);
}
}
The output is "The XYZ service failed to start due to the following error: \r\n%%2"
while the entry I am looking for is
"The XYZ service failed to start due to the following error:\r\nThe system cannot find the file specified."
How does one translate from the id to the appropriate error message ?
Many thanks,
KG
Event log messages are templates, something like:
The %1 service failed to start due to the following error: \r\n%2
An event log entry contains a message number and replacement strings to substitute for %1, %2, etc.
The .Net EventLogEntry.Message property does the substitution for you, so you should never see the %1, %2, etc.
It looks like the substitution is failing, perhaps because there aren't enough replacement strings (check the EventLogEntry.ReplacementStrings property) or the format string is malformed (it seems to have a stray '%'). Though neither of these explanations seem plausible if the log entry is coming from the Service Control Manager.

File Not Found, but the file is there!

public static List<Product> Load(string filename)
{
if (!File.Exists(filename))
{
throw new FileNotFoundException("Data could not be found ", filename );
}
}
Visual Studio 2010 gives the following exception, "FileNotFoundException"
emmm.. ok. this problem seem to have been solved.
.
But however, I still can not find the file!! But the file is there, in the same directory, Ive already verified and double-verified the name is correct! I have no idea what is going on.
The file is called "Products.xml".
You are the one who is throwing the exception. Do you mean to put up an error message?
File.Exists may return false if the user that the code runs under does not have access to the file, as well as if the does not exist.
http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx
The file is called "Products.xml".
You expose yourself to random failure with a filename like that. You should use the full path name of the file, like c:\mumble\foo\products.xml. If you don't then you completely rely on your program's working directory being set correctly. The value of Environment.CurrentDirectory.
Even if it is set correctly by whatever program is starting yours (like a shortcut on the desktop), you still can get into trouble when code you didn't write changes the working directory. A good example is OpenFileDialog with the RestoreDirectory property left to the default value of false.
Always use full path names in your code. Or let the user select the file.
It looks like the problem is File.Exists is returning false and you're throwing an exception which is not handled by your code. Did you intend for this exception to be handled or does this represent a fatal error to your program?
The file located at filename does not exist, and thus it throws the exception with the following line: throw new FileNotFoundException("Data could not be found ", filename );
Did you mean to just output an error?
In you code first check for empty filename as the passed parameter may be empty string, plus apply try catch block on the code as the passed filename might not satisfy the path rules for a file. in catch block through your exception too.
You either:
A) Don't want to throw the exception via this line
throw new FileNotFoundException()
and instead want to display a Dialog to the user, or use some other error handling technique in there. To output an error either use one of the following:
Console.WriteLine("File not found")
MessageBox.Show("File not found");
B) Higher up in your call stack have a try/catch and handle your error there, similarly with a dialog or another error handling approach suitable for your application.
try
{
Load(filename);
}
catch(FileNotFoundException fe)
{}

Copy and read files from dvd and CD C#

I am trying to use the following code in my project. http://www.codeproject.com/KB/miscctrl/imapi2.aspx
However, When I run the application and click on "Detect Media" it says "Media not supported".
Can someone please help me with this issue. Why does it say Media not supported?
Thank you,
Divya.
Referring to Eric's source code for the application, this text comes from the buttonDetectMedia_Click method in the MainForm class:
discFormatData = new MsftDiscFormat2Data();
if (!discFormatData.IsCurrentMediaSupported(discRecorder))
{
labelMediaType.Text = "Media not supported!";
_totalDiscSize = 0;
return;
}
So, the call to IsCurrentMediaSupported is failing. This is actually a COM Interop call to IDiscFormat2::IsCurrentMediaSupported. The MSDN documentation does mention some other possible HRESULT values, though I'd expect that if they occurred, a COMException would be thrown. The sample code does catch this exception, in which case a message box is displayed - that's not the case here though.
When I ran the sample, I got the same "Media not supported!" error. I have a DVD burner, but there is no disc in the drive (don't have any blank discs with me at the moment!), so that appears to be one answer to why you'd get that message. I'd guess if the media in the drive was not writable or incompatible with your burner, you'd also get that message.

Categories