Project

General

Profile

MessagingToolkit.Core dependent on System.Windows.Forms?

Added by chrisalbrecht almost 4 years ago

Hi,

I was trying to run MessagingToolkit on Mono 3.2.8 on Debian Linux for an embedded application.

I found that it was failing, due to a dependency on System.Windows.Forms:

Mono: The following assembly referenced from /root/smstest/MessagingToolkit.Core.dll could not be loaded:
Assembly: System.Windows.Forms (assemblyref_index=3)
Version: 4.0.0.0
Public Key: b77a5c561934e089

Is this dependency on System.Windows.Forms actually required for MessagingToolkit.Core? In an embedded application it's not ideal to have such a dependency.

As a side note, Mono does have an implementation of System.Windows.Forms which I installed out of desperation. It got me past the above error, but still failed with the following: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI, but I think this is unrelated to MessagingToolkit.

It'd really be good to have your Core library free from this dependency. Would this be feasible?

Thanks and regards,
Chris


Replies (26)

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by admin almost 4 years ago

Hi,

There are dependency on Windows.Forms now but it can be removed. I will need some time to make these changes as part of the code rewrite. We will make this change in the next release soon.

Thanks
Regards
admin

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht almost 4 years ago

Thanks, this is much appreciated. Can you provide an ETA?

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by admin almost 4 years ago

Hi,

For now, try with the attached patch to see if works for you.

Thanks
Regards

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht almost 4 years ago

Hi thanks for providing a patched dll so quickly. This does get me past the exception I noted above, but now I am getting "COM port is invalid" after 30 seconds, despite the fact that I am using a valid port (/dev/ttyACM0) which responds to AT commands manually. I tried with various port configuration options without any success. I also enabled verbose debugging, but it did not provide any additional details other than "2016.01.18-03.57.48: Sending: ATZ".

I also tried configuring my MessageGateway using IPGatewayConfiguration (and used the linux service ser2net to expose the serial port as a network port), but when I run this I get "Unable to find gateway factory".

Any advice you can provide would be appreciated.

Thanks,
Chris

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht almost 4 years ago

I should also mention that I am not using a virtual serial port as noted in http://platform.twit88.com/boards/2/topics/1536. I have no problem opening and interacting with /dev/ttyACM0 using mono and the SerialPort class in other parts of my application.

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht almost 4 years ago

Hi, just following up to see if you have any thoughts or suggestions at this point.

Are there any plans to support the IPGatewayConfiguration?

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht almost 4 years ago

It looks like this issue is due to the fact that Mono does not implement the SerialPort.DataReceived event (see Limitation 1 at http://www.mono-project.com/archived/howtosystemioports/).

Can you comment on the IPGatewayConfiguration class that appears to be only partially implemented?

Alternatively, would you consider adding an option to use polling to check for the presence of data available on the serial port as a workaround for this issue?

Thanks,
Chris

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by admin almost 4 years ago

Hi,

IPGatewayConfiguration is not fully implemented yet and shall only be available in the next major release.

Try with the attached patch to see if this work for you.

Also can you try to upgrade to latest Mono version do let us know the runtime environment (OS version, etc).

Thanks
Regards
admin

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht almost 4 years ago

Hi,

I'm running Debian 8.2, and I was previously using Mono 3.2.8. I've since updated to 4.2.1 but the behavior is the same.

Thanks again for the latest patched DLL as well. I've just tried it but it still results in the same behavior - however I believe this is just due to a minor bug. In EventThreadFunction() you emit the event with (SerialDataReceivedEventArgs) null, likely since SerialDataReceivedEventArgs has no public constructor. The problem is this leads to a null reference exception when anything tries to access the EventType property on the event's args.

Although its a bit hacky, you could use reflection to access the class's internal constructor and create an instance of the SerialDataReceivedEventArgs:

var constructor = typeof(SerialDataReceivedEventArgs).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new[] {typeof(SerialData)}, null);
var args = (SerialDataReceivedEventArgs)constructor.Invoke(new object[] { SerialData.Chars });

I think if you can provide another patched DLL with this additional change then we might just get it to work on Linux :)

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht almost 4 years ago

Hi,

Thanks again for such a quick reply. The latest patch worked to overcome all of the previous issues, and MessagingToolkit is now able to communicate with the modem. However there still seems to be an issue, as I'm not able to send or receive any SMS messages yet.

I've attached a log of the session, which shows a number of timeouts that occur.

Let me know what you think.

Thanks,
Chris

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by admin almost 4 years ago

Hi,

I can see from Mono source code that the SerialPortStream is throwing this time out exception. The default read time out set is 3 seconds. Can you try setting the ReadTimeOut property to a higher value and see if it works?

Thanks
Regards
admin

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht almost 4 years ago

It looks like this is a change you will need to make internally, since the property isn't exposed via your MobileGatewayConfiguration class. Let me know if I am missing something.

Thanks,
Chris

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by admin almost 4 years ago

Hi,

Right now the property is exposed after connecting to the gateway. You can find this property under MobileGateway. Let us know if this resolves your issue.

Thanks
Regards
admin

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht almost 4 years ago

Hi,

Sorry for the delay getting back to you. This did not seem to work. It looks like the value is being ignored. Can you confirm it is being used?

Thanks,
Chris

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by admin almost 4 years ago

Hi,

It should work. You can also try with the attached latest patch. The ReadTimeOut property is included as part of MobileGatewayConfiguration now.

If it is still not working, do attach the log file here.

Thanks
Regards
admin

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht almost 4 years ago

The latest dll you sent looks to reference System.Windows.Forms again, so I'm not able to run it on Linux.

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht almost 4 years ago

Still running into the same timeout at at System.IO.Ports.SerialPortStream.Read. Log attached.

SMS messages sent in log are not being received at destination.

Thanks

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by admin almost 4 years ago

Hi,

Can you confirm the device and SIM card is able to send and receive SMS? From the log file, the response from the device indicates message is sent successfully.

Thanks
Regards
admin

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht almost 4 years ago

Hi,

It appears that there was an issue with the SIM card I was using. I am now testing with a new SIM card and messages are being sent successfully.

However I still cannot receive messages. There are also now a ton of IOExceptions in the log (several per second).

See attached.

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by admin almost 4 years ago

Hi,

Can you attach your code snippet here?

Thanks
Regards

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht almost 4 years ago

Hi, sorry for the delay getting back to you. Please see attached.

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by admin almost 4 years ago

Hi,

I cannot reproduce this problem. Can you try if the followings work

- Run the program under "sudo" just to make sure there is no permission issue
- Check the device docs to make sure the baudrate, parity, and other settings are configured correctly.

Thanks
Regards
admin

RE: MessagingToolkit.Core dependent on System.Windows.Forms? - Added by chrisalbrecht over 3 years ago

Hi,

It appears that the fix to remove the dependency on System.Windows.Forms (and presumably the fix for the mono serial port issue) was not included in your latest release. Can you include these in the main code line so that we use nuget to pull down the latest version in our build?

Thanks,
Chris

(1-25/26)