Jon
Jon

Reputation: 4045

Access Violation Exception only appearing when running C# app without debugger attached

I have an application that works fine in Visual Studios 2008, and I am trying to get it into VS 2010 in order to use .NET 4, and I have a really weird problem. When I run the code from either Release mode or Debug mode with the debugger attached (F5), I have no problems running the program. However, when I run the program from either Release or Debug without the debugger attached (Shift+F5), I get an Access Violation Exception when I attempt to run some code in a dll from GDCM. I've created the dlls by using CMake and Swig and following the instructions here adjusting the instructions where necessary to build for VS 2010 and .NET 4.

Does any one have any ideas why this is happening and how I can fix it?

Here's an example of a program where the error occurs. Again, if you create a project with the following as the program in VS 2010 it will run fine when the debugger is attached and fail if the debugger is not attached.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using gdcm;

namespace GDCMVS2010Test
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("This program prints the patient name of a dicom file with gdcm");
                Console.WriteLine("Usage: [input.dcm]");
                return;
            }

            gdcm.Reader reader = new gdcm.Reader();
            reader.SetFileName(args[0]);
            reader.Read();

            gdcm.File file = reader.GetFile();

            gdcm.StringFilter filter = new gdcm.StringFilter();
            filter.SetFile(file);
            string value = filter.ToString(new gdcm.Tag(0x0010, 0x0010));

            Console.WriteLine("Patient Name: " + value);
        }
    }
}

Upvotes: 4

Views: 4398

Answers (4)

Jon
Jon

Reputation: 4045

This was because the version of SWIG I was using wasn't working correctly. A new version of SWIG was recently released (version 2.0) which solves this problem. After I reran CMake on GDCM, and then rebuilt GDCM with VS 2010, and put the GDCM dlls back into my example code, everything worked fine.

Upvotes: 1

RichardHowells
RichardHowells

Reputation: 9056

The client profile misses out chunks of the .Net framework that you are unlikely to need on a client machine. ASP .Net for example. See this link http://msdn.microsoft.com/en-us/library/cc656912.aspx

Upvotes: 1

malat
malat

Reputation: 12490

You should really start using GDCM specific groups to communicate your issues, see:

http://sourceforge.net/apps/mediawiki/gdcm/index.php?title=General_questions#Where_are_the_GDCM_mailing_lists_.3F

100 of GDCM users are on this list and will be able to help you.

You should also provide a dataset (the DICOM file) to help with reproducing the bug.

Thanks

Upvotes: 1

Steve Elmer
Steve Elmer

Reputation: 939

Check your project properties. I have encountered this problem when I had my Target Framework set to .NET Framework 4.0 Client Profile, when it should have been the one w/out Client Profile. Or vice versa.

Upvotes: 0

Related Questions