'Using FreeSwitch Embedded, getting heap corruption error. No error targeting Framework 4.0, does happen with all later Framework

I have code that is working targeted to .NET Framework 4.0, which is no longer MS supported. You can not even install .NET Framework 4.0 SDK to newest versions of Visual Studio. I am attempting to update to a later framework, preferably 4.7.2 for widest compatibility, but 4.6.1 would be acceptable as I can at least have the SDK available in my IDE. Code compiles without any errors. 64 bit would be a nice bonus, but not a requirement.

The error happens at the first call to initialize the FreeSWITCH.Managed.dll as outlined here:

FreeSwitch embedded

Relevant code here:

            string err = "";
            const uint flags = (uint)(switch_core_flag_enum_t.SCF_USE_SQL | switch_core_flag_enum_t.SCF_USE_AUTO_NAT);
            freeswitch.switch_core_set_globals();
            try
            {
                freeswitch.switch_core_init(flags, switch_bool_t.SWITCH_FALSE, ref err);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception in switch_core_init "+ex.ToString());
            }

The program immediately crashes at the freeswitch.switch_core_init, no JIT error box. There is an option to debug on the test machine, and the error shown there is a heap corruption error. Presumably on the err string.

I see on this thread:

Prior post on subject

That some people have solved this problem, but as they didn't post HOW they solved it, I'm at a bit of a loss here. I've tried initializing a value to the string, including making it 500 million characters in size of spaces to no avail.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source