Resolving 'Incorrect Format' Errors with DALSA Sapera LT DLLs in C# Applications

Problem Overview

When developing a C# WPF application that entegrates with Teledyne DALSA Sapera LT cameras, you may encounter a runtime error stating that the DALSA.SaperaLT.SapClassBasic DLL cannot be loaded, often accompanied by the message "attempting to load an incorrect format program." This guide provides sollutions to resolve this common issue.

  1. Select the Correct DLL for Your Target Framework

The Sapera LT SDK provides different DLLs for different .NET frameworks. Using the wrong one will result in a loading failure.

  • .NET Framework (e.g., .NET 4.8): Use DALSA.SaperaLT.SapClassBasic.dll
  • .NET Core / .NET 5+ (e.g., .NET 6.0): Use DALSA.SaperaLT.SapClassBasic.Core.dll

Ensure the correct DLL is referenced for your project's target framework.

  1. Configuring Multi-targeting in a Single Project

If your project needs to support multiple frameworks (e.g., both .NET Framework and .NET 6), you can configure the .csproj file to conditionally reference the appropriate DLL.

<PropertyGroup>
  <OutputType>Library</OutputType>
  <TargetFrameworks>net48;net6.0-windows</TargetFrameworks>
  <UseWPF>true</UseWPF>
  <Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
  <Reference Include="DALSA.SaperaLT.SapClassBasic">
    <HintPath>C:\Path\To\SDK\Bin\DALSA.SaperaLT.SapClassBasic.dll</HintPath>
  </Reference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0-windows' ">
  <Reference Include="DALSA.SaperaLT.SapClassBasic.Core">
    <HintPath>C:\Path\To\SDK\Bin\DALSA.SaperaLT.SapClassBasic.Core.dll</HintPath>
  </Reference>
</ItemGroup>
  1. Preventing DLL Embedding by Fody/Costura

Tools like Fody's Costura can embed referenced DLLs into your main executable. This can cause issues with native dependencies. Ensure these specific assemblies are excluded from embedding.

<Costura IncludeRuntimeReferences='false'>
  <ExcludeAssemblies>
    DALSA.SaperaLT.SapClassBasic
    DALSA.SaperaLT.SapClassBasic.Core
  </ExcludeAssemblies>
</Costura>
  1. Ensure SDK Version Consistency

The application may run correctly on your development machine but fail on another due to a mismatch in the installed Sapera LT SDK version. Verify that the target machine has the same version of the Teledyne DALSA Sapera LT SDK installed as your development environment.

  1. Setting System Paths

If the application still fails to find the DLL, you can make it available to the system.

  • Set the environment variable PATH to include the directory containing the required DLL.
  • Alternatively, copy the appropriate DLL to the system folders:
    • DALSA.SaperaLT.SapClassBasic.dll to C:\Windows\System32
    • DALSA.SaperaLT.SapClassBasic.Core.dll to C:\Windows\SysWOW64

Tags: DALSA SaperaLT C# WPF DLL

Posted on Tue, 18 Aug 2026 16:32:45 +0000 by RamboJustRambo