Exceptions
Exception types and error conditions in the Perfectly Clear .NET API.
The .NET API primarily uses return codes rather than exceptions for error handling, but certain conditions can still cause exceptions to be thrown.
Handling Exceptions
Wrapping SDK calls in try-catch blocks ensures graceful handling of system-level errors.
try
{
using (var pfc = new PerfectlyClear("license/path", ""))
{
Bitmap bm = pfc.ReadImage("input.jpg");
pfc.AutoCorrect(ref bm);
bm.Save("output.jpg");
bm.Dispose();
}
}
catch (DllNotFoundException ex)
{
Console.WriteLine("PerfectlyClearPro.dll not found");
}
catch (BadImageFormatException ex)
{
Console.WriteLine("Architecture mismatch 32 or 64 bit");
}
catch (OutOfMemoryException ex)
{
Console.WriteLine("Insufficient memory");
}Common exception types
These exceptions may be thrown during SDK operations and should be handled appropriately.
DllNotFoundException
Thrown when the native PerfectlyClearPro.dll cannot be located by the runtime.
Cause: Native DLL cannot be found.
Solutions: Ensure PerfectlyClearPro.dll is in application directory. Check all dependency DLLs are present.
BadImageFormatException
Thrown when there is a mismatch between the application and DLL processor architectures.
Cause: Architecture mismatch.
Solutions: Use 64-bit DLL with 64-bit apps for x64. Use 32-bit DLL with 32-bit apps for x86.
OutOfMemoryException
Thrown when the system cannot allocate sufficient memory for image processing.
Cause: Insufficient memory for large images.
Solutions: Use downsampled images for analysis. Dispose bitmaps promptly. Consider 64-bit builds.
AccessViolationException
Thrown when attempting to access memory that has been freed or is invalid.
Cause: Using disposed objects.
Solutions: Use the using statement. Do not access objects after Dispose.
Thread Safety
Multi-threaded applications require each thread to create its own PerfectlyClear instance while sharing the license initialization.
PerfectlyClear.SetProtectionPath("license", "code");
Parallel.ForEach(imagePaths, path =>
{
using (var pfc = new PerfectlyClear())
{
Bitmap bm = pfc.ReadImage(path);
pfc.AutoCorrect(ref bm);
bm.Save(GetOutputPath(path));
bm.Dispose();
}
});
PerfectlyClear.ReleaseProtectionPath();PFC-SDK Version 10.7.2.1269 built from 4fa849d8101945eea725a08dd0dae5101f090fa0 on 11-10-2025.
Copyright © 2026 EyeQ Imaging Inc. All rights reserved.