Error handling
How failures surface in NexPDF for .NET MAUI - PdfView events, NexPdfEngine.Activate, the exceptions of the engine API, license codes and engine messages.
The engine API (NexPdfDocument and NexPdfSdk) works as in the .NET SDK:
every call returns its result or throws. PdfView and NexPdfEngine report some failures
differently, so that a UI does not crash on a bad file.
Where failures surface
| Where | How it fails |
|---|---|
PdfView.LoadAsync, setting DocumentBytes | When the document cannot be opened, raises LoadFailed with the exception (usually a NexPdfException) instead of throwing. A missing or wrong password also raises PasswordRequired first. |
PdfView.ReloadAsync | Throws the exception of the engine call that failed. |
Background rendering in PdfView | Not reported. A page that fails to render stays blank. |
NexPdfEngine.Activate | Returns false and sets NexPdfEngine.LastError to the engine's message. |
NexPdfSdk.ActivateLicense | Throws NexPdfException with the negative license code in Code. |
Any other NexPdfDocument or NexPdfSdk call | Throws NexPdfException with the engine's message (Code is 0). |
view.LoadFailed += (_, e) =>
{
var message = e is NexPdfException ? e.Message : "The file could not be read.";
ErrorLabel.Text = message;
ErrorLabel.IsVisible = true;
};LoadFailed and PageChanged are raised on the thread that called LoadAsync or scrolled the view,
which is the UI thread in normal use.
Exception types
| Exception | Thrown when |
|---|---|
NexPdfException | An engine call failed. Message is the engine's message. |
ObjectDisposedException | A method was called on a disposed NexPdfDocument, for example a view.Document you kept after loading another file. |
OverflowException | A negative page index was passed where the engine takes an unsigned index. |
DllNotFoundException | The app has no engine for this device (Android and Windows). |
IOException, FileNotFoundException | NexPdfDocument.Open(path) could not read the file, or Save(path) could not write it. |
Common engine messages
| Message | Cause | What to do |
|---|---|---|
password required | The file is encrypted and no password was given | Ask for the password and set PdfView.Password; see Security |
incorrect password | The password matches neither the user nor the owner password | Ask again |
no license activated: '<module>' requires a NexPDF license key | The call needs a module and no key is active | Activate at start-up; see Running without a key |
the active license does not include the '<module>' module | Your plan does not include the module | Check NexPdfSdk.IsLicensed(module) and hide the feature, or upgrade the plan |
internal error: ... | The engine caught an unexpected failure on this input | The app keeps running; report the file to support |
Other messages describe the input: a malformed or truncated PDF, a page index out of range, invalid JSON options. Show them to the user or log them as they are.
License error codes
NexPdfException.Code after NexPdfSdk.ActivateLicense is one of:
| Code | Meaning |
|---|---|
| -1 | Malformed key |
| -2 | Bad signature (the key was changed, or it is not a NexPDF key) |
| -3 | Unsupported key version (update the SDK) |
| -4 | Expired |
| -5 | Not yet valid (check the device clock) |
| -6 | Wrong platform |
| -7 | Wrong application id |
NexPdfEngine.Activate does not return the code; use NexPdfSdk.ActivateLicense when you need it.
A rejected key leaves the previous license state as it was, so the app stays in view-only mode.
The last error
NexPdfSdk.LastError returns the engine's last error message for the current thread, or null.
NexPdfEngine.LastError holds the message of the last failed NexPdfEngine.Activate call only.
Untrusted input
The engine is written in Rust and fuzzed; a malformed PDF produces a NexPdfException or a
LoadFailed event, not a crash. Files users pick or download are read into memory as a whole, so
check their size before loading very large files on phones.