unity creashes when using a pinvoke with input string


I’m using unity 2019.2.13f1

I have created a c++ dll that I’m using in my unity project.

I’ve created a method that has const char* (string) as input in the c++:

extern "C"
	__declspec(dllexport) double __stdcall get_au(const char* au) {
		for (auto reg : *au_reg1) {
			if (reg.first.compare(au) == 0)
				return reg.second;
		return -1;

when I’m sending it from my test c# project it is working fine.

but when I’m trying to send from my unity project, the process crashes.

this is my c# declaration:

    [DllImport("au_FeatureExtraction.dll", EntryPoint = "get_au", CallingConvention = CallingConvention.Cdecl)]
    static extern double get_au(string au);

I have other functions that uses the same DLL with\without in parameters and it works fine for that.
(example for other method that works):


extern "C"
	__declspec(dllexport) int __stdcall getdetection_success() {
		return detection_success;

   [DllImport("FeatureExtraction.dll", EntryPoint = "getdetection_success", CallingConvention = CallingConvention.Cdecl)]
    static extern int getdetection_success();

Well, the issues is most likely in your C++ code. You haven’t told us what “au_reg1” actually points to. Since you dereference it it should be a pointer to any supported collection for an auto for loop. Are you actually sure that this pointer is not null? Where and when is it initialized? We’re completely blind here. We know nothing about the context.

Also not totally irrelevant would be to know the build target, scripting backend and .NET compatibility level.