ASP.NET DllImport Calls Application to Exit

I strongly suspect that my problem is related to a security problem, but here is a full description just in case, if I am mistaken.

I have a DLL that was originally written in C (not C ++). I use DllImport to call methods in this library. The ad looks something like this:

[DllImport(@"MyAntiquatedLibrary.dll")
[SecurityPermission(SecurityAction.Assert, Unrestricted = true)]
internal static extern void GetConnectionString(string port, string server, string instance, [Out] StringBuilder output);

The C declaration in the header file is as follows:

void GetConnectionString(const char far *Portname, const char far *ServerName const char far *InstanceName, char far *retConnectionName);

So, I created a sample page in my WebApplication project in visual studio, whose code is as follows:

protected void Page_Load(object sender, EventArgs e)
{
  try
  {
    var connectionString = new StringBuilder();
    GetConnectionString(null, "myHost", "myInstance", connectionString);
    MyLabel.Text = connectionString.ToString();
  }
  catch(Exception ex)
  {
    MyLabel.Text = string.Format("Something went wrong: {0}", ex.Message);
  }
}

When I debug the program and pass the GetConnectionString () method method, I get:

AccessViolationException was unhandled.
Attempted to read or write protected memory.  This is often an indication that other memory is corrupt.

, DLL - - WebApplication. ConsoleApplication, .

WindowsConsole. , . , C-API, , -, , .

+5
2

, C-API . , API, UnitTests, -.

, , ASP.NET .NET.

+1

IIS 64- , CPU = X86, AnyCPU, jit, , 64- . 32- IIS, . - , , dll asp.net.

+1

All Articles