views:

388

answers:

0

I have a problem where NUnit Assert.IsTrue crashes with an "access denied" (0xc0000005) access violation. Since managed applications are not supposed to cause such errors, I started looking at any unmanaged code loaded by the NUnit tests. And sure enough, after a process of elimination the simplest way to reproduce the problem turned out to be this:

using System;
using System.Runtime.InteropServices;
using NUnit.Framework;

namespace test
{
   class Program
   {
      [DllImport("kernel32.dll")]
      static extern IntPtr LoadLibrary(string library);

      static void Main(string[] args)
      {
         var result = LoadLibrary("cc3270mt.dll");
         Console.WriteLine(result == IntPtr.Zero ?
            "loadlibrary failed" : "loadlibrary ok");
         Assert.IsTrue(true);
         Console.WriteLine("test end");

      }
   }
}

This program will print "loadlibrary ok" and will then crash on the Assert.IsTrue with this on the VS2008 output console:

The program '[2540] test.vshost.exe: Managed' has exited with code -1073741819 (0xc0000005).

cc3270mt.dll (version 7.0.0.4) is a redistributable dependency of any applications or modules built with borland developer studio 2006. What's going on here? Are borland libraries unable to coexist with the .NET runtime in the same process?