Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8100227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:41:26+00:00 2026-06-05T22:41:26+00:00

I’ve used ITK with c++ some time ago and I’m trying to use simple

  • 0

I’ve used ITK with c++ some time ago and I’m trying to use simple itk in c# now. I’ve looked at the MICCAI 2011 tutorial and I’m trying to get started. I’m using a Windows 7 64 bit machine and Visual Studio Ultimate 2010.
According to this wiki I should be able to just unzip and reference the .dlls to my project and it should be working.
I’m able to add the SimpleITKCSharpManaged.dll to my references. However I’m not able to add the SimpleITKCSharpNative.dll to my references. It gives me the error:
Please make sure the file is accesible, and that it is a valid assembly or COM component.

I then try to run a simple console app

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using itk.simple;

namespace TestSimpleItk
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputFilename = "001.png";
            if (File.Exists(inputFilename))
            {
                try
                {
                    var input = SimpleITK.ReadImage(inputFilename);
                    var binary = SimpleITK.BinaryThreshold(input, 100, 255, 255, 0);
                    SimpleITK.WriteImage(binary, "cthead1-binary.png");
                }
                catch (Exception ex)
                { 
                    Console.WriteLine("{0}", ex);
                }

            }
            else
            {
                Console.WriteLine("File '{0}' does not exist", inputFilename);
            }
        }
    }
}

The exception thrown is:
{“The type initializer for ‘itk.simple.SimpleITKPINVOKE’ threw an exception.”}
and the inner exception is:
{“An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)”}

I’ve tried to copy the SimpleITKCSharpNative.dll to my bin/debug directory and I’m still getting the same error.

Any ideas on how to solve this, or how to get SimpleItk up and running without actually building it locally from the source code using CMAKE?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:41:27+00:00Added an answer on June 5, 2026 at 10:41 pm

    Dan Mueller from ITK answered my question. Here’s what he had to say:

    Hi Federico,

    The error you are receiving gives the hint:
    “An attempt was made to load a program with an incorrect format.”

    This error occurs when a .NET program tries to access functions in a
    dll which was built using a different architecture; see for example
    here:
    http://blogs.msdn.com/b/arvindsh/archive/2009/06/21/tip-of-the-day-an-attempt-was-made-to-load-a-program-with-an-incorrect-format-net-p-invoke-issue.aspx

    The easiest way to resolve this is to use the same building settings
    as SimpleITK. For example, if you downloaded
    “SimpleITK-0.4.0-CSharp-Win64-anycpu.zip” then your calling program
    should be built with x64 AnyCPU settings. If you downloaded
    “SimpleITK-0.4.0-CSharp-Win32-x86.zip” you should use x86 Win32
    settings.

    To answer your other question: you only need to add
    “SimpleITKCSharpManaged.dll” to your program references, but
    “SimpleITKCSharpNative.dll” must be in the probe path (the easiest way
    of achieving this is to put it in your binary directory next to your
    program executable and the managed dll). This is explained at the
    following page (this page is for Linux, but the same approach is
    needed for Windows also):
    http://www.itk.org/Wiki/ITK/Release_4/SimpleITK/GettingStarted/Visual_guide_to_building_on_Linux#A_simple_C.23_program

    Please let us know how you get on.

    HTH

    Cheers, Dan

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.