ladendirekt / pjsip4net

A wrapper library exposing the pjsip library to the .NET world in a OO-friendly way.
71 stars 42 forks source link

NullReferenceException at get_BoundAddress() SipTransportConfigurationElement.cs:line 62 #65

Closed PaulSch closed 7 years ago

PaulSch commented 7 years ago

Hello, I'm trying to get the console application working first I had some trouble as the downloaded zip file was blocked by windows 10, and this resulted in a File security exception, that I helped to resolve using the comments in issue 63 :)

However just as the OP I am running into this NullRef exception:

pjsip4net.Configuration.SipTransportConfigurationElement.get_BoundAddress() in c:\Projects\test\pjsip4net-master\pjsip4net\Configuration\SipTransportConfigurationElement.cs:line 62

I have (I think) configured the app.config file correctly for the account info that was commented out. There is also a Transport section, and I expect that this should contain a BoundAddress and PublicAddress entry? This whole section is empty, and the code does not handle this, so it should not be, but what should it contain?

A little help would be greatly appreciated. Regards, paul

siniypin commented 7 years ago

Hi, can you post your config file here?

PaulSch commented 7 years ago

I had the standard config file from the github repo, however I just discovered that if I add: BoundAddress and PublicAddress with my local IP address it seems to work, not sure if this is the way it is supposed to be used?

Config file:

  <sipua srtp="Disabled" secureSignaling="0" logMessages="true" logLevel="5" traceAndDebug="false" autoAnswer="true" autoRecording="false" autoConference="false" maxCalls="5">
    <accounts>
      <!--<account accountId="sip:1000@66.240.xxx.xx:5080" registrarUri="sip:66.240.xx.xx:5080"
          userName="1000" password="1234" realm="*" isDefault="true"
          publishPresence="false" />-->
      <account accountId="sip:paul.schoonbergen@sip.linphone.org" registrarUri="sip:sip.linphone.org"
          userName="paul.schoonbergen" password="soessoes" realm="*" isDefault="true"
          publishPresence="false" />
    </accounts>
    <sipTransport type="udp" Port="5080">
      <BoundAddress>172.16.2.101</BoundAddress>
      <PublicAddress>172.16.2.101</PublicAddress>
    </sipTransport>
    <networkSettings natInSDP="true" forceLooseRoute="false">
      <!--<stun address="stun.stunprotocol.org"/>-->
      <turn enabled="false" server="" type="udp" userName="" password="" realm="" />
      <ice enabled="false" noRTCP="false" />
      <!--<proxies>
        <add address="sip:proxy.sipthor.net"/>
      </proxies>-->
    </networkSettings>
    <media isVADEnabled="true" playbackDeviceId="9" captureDeviceId="6" />
  </sipua>
PaulSch commented 7 years ago

I just wanted to add, that I'm impressed with the code, nice work!

PaulSch commented 7 years ago

Other question (sorry hijacking my own post) I'm trying to transfer a call before answering it (call forward) but the MediaState is not active, if I make it active the transfer works just fine...

However in all unit tests for transfer there is an explicit setup that the MediaState should be active, but how should i achieve this?

siniypin commented 7 years ago

Hey Paul,

that error is really weird and is buried somewhere down in .Net Configuration framework. I can only suggest to use a bound address property only if you need to bind your SIP transport to a certain network interface, otherwise it would listen to all of them (0.0.0.0). I wonder if it is fixable with configuration property validators.

Thanks for the notice and the complement.

Let's discuss your second question in a new issue.

PaulSch commented 7 years ago

Agree regarding new issue for new question, especially for the benefit of others...

If I leave out the boud address configuration I get the null ref, I'm using Win10 .Net 4.5.2 anything else you would like to know?

If setting the bound address should cause the SIP transport to only listen to that, then that is strange, I just successfully transferred a call coming from another address...

And I definitely want to be listening for all incoming traffic.

siniypin commented 7 years ago

Ah, finally I got it. The property is explicitly set to null, no wonder it fails. https://github.com/siniypin/pjsip4net/blob/master/pjsip4net/Configuration/SipTransportConfigurationElement.cs#L58

Can you try to specify a string '0.0.0.0' as default value for bound address? And an empty string for a public address. You have to pass it in to the prop definition like in the following examples:

PaulSch commented 7 years ago

I have another appointment just now, will check this monday morning 7:00 CET ;-) Enjoy your weekend! and thanks for the quick response!

siniypin commented 7 years ago

Cheers, you too!

PaulSch commented 7 years ago

Just to clarify, I'm running the c version of PJSip on some embedded hardware, that is calling PC_A running PJSip4Net and that forwards the call to PC_B running a linphone windows client

Okay so I tried these changes, needed to adjust the validation regex for the public address, no prob. However getting the following message after the console prompt shows in the console test app: sound_port.c EC suspended because of inactivity

If I undo the changes I do not get that message.

I tried several times, and the first time with these changes I got the following warning, but I can not reproduce it: 2016-11-28 08:03:40,880 [11] WARN - 08:03:40.880 tsx09769FC4 Temporary failure in sending Request msg INVITE/cseq=4381 (tdta09766FA8), will try next server. Err=171064 (Unsuitable transport selected (PJSIP_ETPNOTSUITABLE))

Set everything back the way it was, and it forwards like a charm! :)

But with these changes, I am able to phone my other computer using makecall, but transfering to it does not come through. I also see no response / logging in the console app

PaulSch commented 7 years ago

I was able to spend some more time on this project, and I have discovered that if I add the BoundAddress and PublicAddress nodes to the config file:

    <sipTransport type="udp" Port="5080">
      <BoundAddress></BoundAddress>
      <PublicAddress></PublicAddress>
    </sipTransport>

The CfgFileConfigurationProvider Configure method throws a ConfigurationException when loading the "sipua" section, "Unrecognized element 'BoundAddress'

And the rest of the configuration is skipped due to this exception.

I can set the default values for these properties in the SipTransportConfigurationElement And then when it goes through the CfgFileConfigurationProvider .Configure method, I see the values I provided, but then forwarding does not work. Strangly if I set the configuration properties back, and redun the console application, it bombs out of the configuration, but forwarding actually works!!!!

But this is probably why I can not get the configuration to work in my own project (last comment in issue #67)

Any help would be appreciated, because I would really like to use PJSip

siniypin commented 7 years ago

Hey Paul, regarding the code snippet you sent:

<sipTransport type="udp" Port="5080">
      <BoundAddress></BoundAddress>
      <PublicAddress></PublicAddress>
    </sipTransport>

These props can only be defined as XML attributes, otherwise you'd have to define dedicated classes for these props to be mapped from an XML config element. That's .Config's framework internal kitchen. So, please try this instead:

<sipTransport type="udp" Port="5080" boundAddress="" publicAddress="" />
phrohdoh commented 7 years ago

I am also getting an NRE for BoundAddress (I happen to be running the Integration/Console application).

Changing the sipTransport in App.config to the suggested <sipTransport type="udp" Port="5080" boundAddress="" publicAddress="" /> fixed that issue.

PaulSch commented 7 years ago

Yep this fixes this issue!