简体   繁体   中英

"Access violation reading location" Thrown From Empty DLL Method

I am getting the following error:

Exception thrown at 0x71D1336E (vcruntime140.dll) in My Test App.exe: 0xC0000005: Access violation reading location 0x00974000.

When calling the following method from C# .NET Framework console (this is a C++ DLL unmanaged project):

extern "C" {
    __declspec(dllexport) int SetIpAddress() {
        return 0x8;
    }
}

This is my console code:

class Program
{
    [DllImport("C:\\Users\\Dash\\Release\\Test.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern int SetIpAddress();

    static void Main(string[] args)
    {
        int result = SetIpAddress();
        Console.WriteLine($"SetIpAddress result: {result}");
    }
}

From all the similar SO questions relating to "access violation reading location," it relates to issues with allocating memory. But, as you can see, there is no memory being allocated in any of the methods. Thoughts?

The issue was a mistake in target builds - one was DEBUG, the other was RELEASE.

@bschellekens comment helped me figure this out. Thank you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM