Skip to Content
NexPDF

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.

English

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

WhereHow it fails
PdfView.LoadAsync, setting DocumentBytesWhen 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.ReloadAsyncThrows the exception of the engine call that failed.
Background rendering in PdfViewNot reported. A page that fails to render stays blank.
NexPdfEngine.ActivateReturns false and sets NexPdfEngine.LastError to the engine's message.
NexPdfSdk.ActivateLicenseThrows NexPdfException with the negative license code in Code.
Any other NexPdfDocument or NexPdfSdk callThrows 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

ExceptionThrown when
NexPdfExceptionAn engine call failed. Message is the engine's message.
ObjectDisposedExceptionA method was called on a disposed NexPdfDocument, for example a view.Document you kept after loading another file.
OverflowExceptionA negative page index was passed where the engine takes an unsigned index.
DllNotFoundExceptionThe app has no engine for this device (Android and Windows).
IOException, FileNotFoundExceptionNexPdfDocument.Open(path) could not read the file, or Save(path) could not write it.

Common engine messages

MessageCauseWhat to do
password requiredThe file is encrypted and no password was givenAsk for the password and set PdfView.Password; see Security
incorrect passwordThe password matches neither the user nor the owner passwordAsk again
no license activated: '<module>' requires a NexPDF license keyThe call needs a module and no key is activeActivate at start-up; see Running without a key
the active license does not include the '<module>' moduleYour plan does not include the moduleCheck NexPdfSdk.IsLicensed(module) and hide the feature, or upgrade the plan
internal error: ...The engine caught an unexpected failure on this inputThe 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:

CodeMeaning
-1Malformed key
-2Bad signature (the key was changed, or it is not a NexPDF key)
-3Unsupported key version (update the SDK)
-4Expired
-5Not yet valid (check the device clock)
-6Wrong platform
-7Wrong 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.

On this page