views:

339

answers:

4

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);
        }
    }
}
A: 

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.

Steve Elmer
I have multiple projects, and each one was set to the .NET 4 Framework. I tried setting them all to the .NET 4 Client Profile, and the issue still appears. What's the difference between the two frameworks?
Jon
alas, I cannot answer that question - it is something I have been meaning to explore further. But I have encountered similar behavior and been like "WTF???". And as a result of setting them all to one or the other profile, got everything to work w/out the access violation exception. lol - a classic case of programming by accident.
Steve Elmer
+1  A: 

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

malat
+1  A: 

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

RichardHowells
A: 

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.

Jon