Search code examples
c#.netfreeswitch

Initialising the core using Freeswitch embedded


I am working on a project to use freeswitch as embedded in another application. I'm working on a C#/.Net application.

I've tried something very simple, wich is to init the core, in the main function of a simple test project. I added the freeswitch.managed.dll reference to the project, and I just typed these 3 commands like shown in the freeswitch wiki,

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();
freeswitch.switch_core_init(flags, switch_bool_t.SWITCH_FALSE, ref err);    
freeswitch.switch_core_init_and_modload(flags, switch_bool_t.SWITCH_FALSE, ref err);      

preceeded and followed by a "welcome" and a "core inited" console messages. Now when I try and build the whole thing, it simply crashes. It seems the switch_core_set_globals function works fine. but the other 2 just won't work.

"unhandled System. AccessViolationException attempt to read or write protected memory"

It makes me wonder, because I was able to successfully build a project, FSClient a softphone wich uses embedded freeswitch. and no crash, nothing.

So I wanted to know is there a specific configuration or any additionnal setup manipulation one needs to operate to be able to init the fs core properly;


Solution

  • Hi guys I think I finally figured that out! it turns out it's a configuration/platform problem. I was trying to run the project on a x64 platform. I tried to run a similar project on a x86 CPU and it worked. So back to my own computer, I created a new simple console app, added the freeswitch.managed dll and changed the targeted platform to x86 (instead of ANY CPU). I also changed the targeted framework (4.0 client profile or 4.0 instead of 4.5). Now when I try to compile the code I mentionned before, there is just a warning message, but the rest works fine. Hope this helps someone out there!

    P.S. Don't forget to put all the dll's and the conf directory containint the freeswitch configuration file (freeswitch.xml) in the bin/debug folder.