Invalid SOAP Fault Message only in Mono - c#

I am trying to consume the ONVIF WSDL service on a C#.net application to talk to IP CCTV cameras.
Developing in .NET Visual Studio on Windows, the application runs fine from my command line. Trying to run the same .exe on Mono (Mono JIT compiler version 5.16.0.220 (tarball Mon Nov 26 17:15:30 UTC 2018) on Debian I cannot get the application to work.
I believe the issue is related to the fact on Mono I am receiving a badly formatted SOAP Fault which the application cannot handle. I don't know if the SOAP Fault is caused by the IP camera and Mono cannot handle it properly (in which case I have an error in the error handling, and fixing the root cause whatever that may be would fix it) OR if the SOAP side is actually fine but Mono is just messing up the decoding of my responses.
The below is the error, it looks like the SOAP response contains 'env:faultcode' which is not expecting.
Unhandled Exception:
System.ServiceModel.CommunicationException: Received an invalid SOAP Fault message ---> System.Xml.XmlException: Unexpected node Element name env:faultcode
at System.ServiceModel.Channels.MessageFault.CreateFault12 (System.ServiceModel.Channels.Message message, System.Int32 maxBufferSize) [0x0012c] in <90242c243a054a8a8feb6f7b52756571>:0
at System.ServiceModel.Channels.MessageFault.CreateFault (System.ServiceModel.Channels.Message message, System.Int32 maxBufferSize) [0x0001c] in <90242c243a054a8a8feb6f7b52756571>:0
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_remoting_wrapper(intptr,intptr)
at (wrapper remoting-invoke) OnvifMonitor.OnvifDeviceMgmt.Device.GetDeviceInformation(OnvifMonitor.OnvifDeviceMgmt.GetDeviceInformationRequest)
at OnvifMonitor.OnvifDeviceMgmt.DeviceClient.GetDeviceInformation (OnvifMonitor.OnvifDeviceMgmt.GetDeviceInformationRequest request) [0x00007] in <596fa5448c77457ba1f773bf27dbbf2a>:0
at OnvifMonitor.MonitoringThread.Connect (System.String ip, System.Int32 port) [0x0013e] in <596fa5448c77457ba1f773bf27dbbf2a>:0
at OnvifMonitor.Program.Main (System.String[] args) [0x0000c] in <596fa5448c77457ba1f773bf27dbbf2a>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ServiceModel.CommunicationException: Received an invalid SOAP Fault message ---> System.Xml.XmlException: Unexpected node Element name env:faultcode
at System.ServiceModel.Channels.MessageFault.CreateFault12 (System.ServiceModel.Channels.Message message, System.Int32 maxBufferSize) [0x0012c] in <90242c243a054a8a8feb6f7b52756571>:0
at System.ServiceModel.Channels.MessageFault.CreateFault (System.ServiceModel.Channels.Message message, System.Int32 maxBufferSize) [0x0001c] in <90242c243a054a8a8feb6f7b52756571>:0
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_remoting_wrapper(intptr,intptr)
at (wrapper remoting-invoke) OnvifMonitor.OnvifDeviceMgmt.Device.GetDeviceInformation(OnvifMonitor.OnvifDeviceMgmt.GetDeviceInformationRequest)
at OnvifMonitor.OnvifDeviceMgmt.DeviceClient.GetDeviceInformation (OnvifMonitor.OnvifDeviceMgmt.GetDeviceInformationRequest request) [0x00007] in <596fa5448c77457ba1f773bf27dbbf2a>:0
at OnvifMonitor.MonitoringThread.Connect (System.String ip, System.Int32 port) [0x0013e] in <596fa5448c77457ba1f773bf27dbbf2a>:0
at OnvifMonitor.Program.Main (System.String[] args) [0x0000c] in <596fa5448c77457ba1f773bf27dbbf2a>:0
I don't want to post the full application code as it's pretty long and not sure which part is relevant. However, I have used Visual Studio to "Add Service Reference" of https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl which is the OnvifDeviceMgmt namespace in the below message.
When my application starts I am making a simple request to GetDeviceInformation which should return some generic info to the app. Authentication is passed on, following the examples from https://github.com/thephez/onvif-interface and using some guidance for this based on the code here.
I'll reiterate, this works FINE on Windows but Mono seems to behave differently.
Any ideas on how I could further debug the Soap error? Can I somehow tell it to ignore Soap errors and pass them on, or figure out what's causing the difference?

Related

Mono (Linux, C#): DLL in same folder can not be found (System.DllNotFoundException)

I am trying to run an C# program on my Raspberry Pi 3 using mono. The program starts correctly, but as soon as I reach a point where I use some OpenCV libraries the program error with the following output:
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Emgu.CV.CvInvoke' threw an exception. ---> System.DllNotFoundException: opencv_core220
at (wrapper managed-to-native) Emgu.CV.CvInvoke:cvRedirectError (Emgu.CV.CvInvoke/CvErrorCallback,intptr,intptr)
at Emgu.CV.CvInvoke..cctor () [0x00023] in <4f43ef68be294203a100f85f9cebb2b6>:0
--- End of inner exception stack trace ---
at Emgu.CV.Image`2[TColor,TDepth].AllocateData (System.Int32 rows, System.Int32 cols, System.Int32 numberOfChannels) [0x0002e] in <4f43ef68be294203a100f85f9cebb2b6>:0
at Emgu.CV.Image`2[TColor,TDepth].set_Bitmap (System.Drawing.Bitmap value) [0x00050] in <4f43ef68be294203a100f85f9cebb2b6>:0
at Emgu.CV.Image`2[TColor,TDepth]..ctor (System.Drawing.Bitmap bmp) [0x00008] in <4f43ef68be294203a100f85f9cebb2b6>:0
at App.Program.Main (System.String[] args) [0x00122] in <b44d2f4f9f83495091806ba3e6a1570f>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'Emgu.CV.CvInvoke' threw an exception. ---> System.DllNotFoundException: opencv_core220
at (wrapper managed-to-native) Emgu.CV.CvInvoke:cvRedirectError (Emgu.CV.CvInvoke/CvErrorCallback,intptr,intptr)
at Emgu.CV.CvInvoke..cctor () [0x00023] in <4f43ef68be294203a100f85f9cebb2b6>:0
--- End of inner exception stack trace ---
at Emgu.CV.Image`2[TColor,TDepth].AllocateData (System.Int32 rows, System.Int32 cols, System.Int32 numberOfChannels) [0x0002e] in <4f43ef68be294203a100f85f9cebb2b6>:0
at Emgu.CV.Image`2[TColor,TDepth].set_Bitmap (System.Drawing.Bitmap value) [0x00050] in <4f43ef68be294203a100f85f9cebb2b6>:0
at Emgu.CV.Image`2[TColor,TDepth]..ctor (System.Drawing.Bitmap bmp) [0x00008] in <4f43ef68be294203a100f85f9cebb2b6>:0
at App.Program.Main (System.String[] args) [0x00122] in <b44d2f4f9f83495091806ba3e6a1570f>:0
The mentioned library "opencv_core220" is a dll located in the same directory as the exe I exececute using mono.
What can I do to fix this problem?
I never worked with mono so far, but I read you can not use dlls on linux, like on windows, but you have to use so-files. But I got no idea how to get them from my dlls.
The program totally works on windows.
There are dlls with .net bytecode and dlls which use windows native code. You need the equivalent files, which use Linux native code!
convert .dll file to .so file and add .so file to /usr/lib. Then run your exe and check

postsharp is failing to work on .net core

I am trying to use postsharp on .net core 2.
I have added Postsharp 5.1.19 (preview) however, I am getting the following error when I try to build the project.
/Users/me/.nuget/packages/postsharp/5.1.9-preview/build/PostSharp.targets(5,5): Error MSB4060: The "PostSharp30" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name. (MSB4060) `
Here is a detailed explanation which is essentially not aware that I am on MAC and still looking for (kernel32) and some dlls:
/Users/me/.nuget/packages/postsharp/5.1.9-preview/build/PostSharp.targets(5,5): Error MSB4061: The "PostSharp30" task could not be instantiated from "/Users/me/.nuget/packages/postsharp/5.1.9-preview/build/PostSharp.MSBuild.v5.1.9.Release.dll".
System.TypeInitializationException: The type initializer for 'PostSharp.Compiler.Client.BuildClient' threw an exception. ---> System.DllNotFoundException: kernel32
at (wrapper managed-to-native) PostSharp.Compiler.Client.ProcessUtilities.GetCurrentProcess()
at PostSharp.Compiler.Client.ProcessUtilities.GetParentProcesses () [0x00006] in <7cce0190f299453c822c4cfb425f86da>:0
at PostSharp.Compiler.Client.ProcessUtilities.DetectUnattendedProcess (System.String& log) [0x0002f] in <7cce0190f299453c822c4cfb425f86da>:0
at PostSharp.Compiler.Client.BuildClient..cctor () [0x00016] in <7cce0190f299453c822c4cfb425f86da>:0
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)
at PostSharp.MSBuild.PostSharp30..ctor () [0x00018] in <7cce0190f299453c822c4cfb425f86da>:0
at (wrapper managed-to-native) System.Reflection.MonoCMethod.InternalInvoke(System.Reflection.MonoCMethod,object,object[],System.Exception&)
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/5533/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.Reflection/MonoMethod.cs:661 (MSB4061)`
How can I get this working?
As you can read in the announcement:
PostSharp 5.1 will still only support Windows as the only build
platform.
So even though .NET Core projects are supported, you can build with PostSharp only on Windows, and as you said - you are on MAC.

[Linux | Cscore]avutil-55 DllNotFoundException

I am trying to run my application which uses cscore (https://github.com/filoe/cscore) and its sub namespace "CSCore.Ffmpeg"
I've already tried what the author explained in "https://github.com/filoe/cscore/blob/master/CSCore.Ffmpeg/Readme.md" ('LD_LIBRARY_PATH=./ mono MyApp.exe') without success.
My question would be how to get it working on Debian 9 using mono.
Additionally i would be grateful if anyone could tell me where i could get the required libraries for my operating system.
This is the stacktrace:
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'CSCore.Ffmpeg.FfmpegCalls' threw an exception. ---> System.TypeInitializationException: The type initializer for 'CSCore.Ffmpeg.FfmpegUtils' threw an exception. ---> System.DllNotFoundException: avutil-55
at (wrapper managed-to-native) CSCore.Ffmpeg.Interops.ffmpeg:av_log_set_callback (intptr)
at CSCore.Ffmpeg.FfmpegCalls.SetLogCallback (CSCore.Ffmpeg.FfmpegCalls+LogCallback callback) [0x00006] in <117ca019c81b40cf9cc0852c6d0ddec3>:0
at CSCore.Ffmpeg.FfmpegUtils..cctor () [0x00025] in <117ca019c81b40cf9cc0852c6d0ddec3>:0
--- End of inner exception stack trace ---
at CSCore.Ffmpeg.Interops.InteropHelper.RegisterLibrariesSearchPath (System.String path) [0x00012] in <117ca019c81b40cf9cc0852c6d0ddec3>:0
at CSCore.Ffmpeg.FfmpegCalls..cctor () [0x0008f] in <117ca019c81b40cf9cc0852c6d0ddec3>:0
--- End of inner exception stack trace ---
at CSCore.Ffmpeg.AvFormatContext..ctor (System.String url) [0x00006] in <117ca019c81b40cf9cc0852c6d0ddec3>:0
at CSCore.Ffmpeg.FfmpegDecoder..ctor (System.String url) [0x00029] in <117ca019c81b40cf9cc0852c6d0ddec3>:0
at AudioTool.AudioClient.AudioStart (System.String url) [0x00001] in <57d1cee9c20047c6a0c5acfeeccbf254>:0
at AudioTool.Program.Main (System.String[] args) [0x00038] in <57d1cee9c20047c6a0c5acfeeccbf254>:0
Thanks in advance
Ok. Solved issue by installing the appropriate linux packages and copying the libraries from '/usr/lib/x86_64-linux-gnu/' into the folder where the application is.
After that i had to look what mono expects by setting the mono loglevel to debug (LD_LIBRARY_PATH=./ MONO_LOG_LEVEL=debug mono MyApp.exe)
An error appeared (something like Mono: DllImport error loading library '/root/bot/Debug/libavutil-55.so': '/root/bot/Debug/libavutil-55.so: cannot open shared object file: No such file or directory'.
)
Then i renamed the existing libavutil.so.55 to libavutil-55.so,I repeated that for every missing include and mono accepted that.
I hope that helps everyone who has a similar problem in future.

Mono error when running C# application on Mac: Invalid IL code in System.Drawing.Icon

Note: This is not a duplicate of the linked question because I'm not looking to develop a Mac application.
So I have a C# application on .NET 4.5 that has the following:
1) Windows Forms
2) References to System.Drawing, EmguCV, Aforge.NET dlls
This works perfectly on my Windows system.
When I try to run the program on a Mac system running OSX using Mono, I get the following error:
exception inside UnhandledException handler: An exception was thrown by the type initializer for System.Windows.Forms.Form
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.Form ---> System.InvalidProgramException: Invalid IL code in System.Drawing.Icon:.ctor (System.IO.Stream): method body is empty.
at (wrapper remoting-invoke-with-check) System.Drawing.Icon:.ctor (System.IO.Stream)
at System.Windows.Forms.ResourceImageLoader.GetIcon (System.String name) [0x00000] in :0
at System.Windows.Forms.Form..cctor () [0x00000] in :0
Has anyone faced anything like this? Appreciate any suggestions.

Executing .Net Application using Mono on CentOS or Linux

I have develop a Test Application using WinForm in C# .Net on Visual Studio 2010. Now, I want to run this under Linux using Mono on CentOS. So I tried below command sequence -
[root#localhost TestLinux]# /usr/bin/mono ./Test.exe
I hit an exception
Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: gdiplus.dll
at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
at System.Drawing.GDIPlus..cctor () [0x00000] --- End of inner exception stack trace ---
at <0x00000> <unknown method>
at System.Drawing.Graphics.FromHdcInternal (IntPtr hdc) [0x00000]
at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000]
at System.Windows.Forms.XplatUIX11..ctor () [0x00000]
at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000]
at System.Windows.Forms.XplatUI..cctor () [0x00000] --- End of inner exception stack trace ---
at <0x00000> <unknown method>
at System.Windows.Forms.Application.EnableVisualStyles () [0x00000]
at Test.Program.Main () [0x00000]
While doing some research I found that this is due to linking between gdiplus.dll and its counter part libgdiplus.so.0 on linux, need to put its entry in ldconfig cache.
[root#localhost TestLinux]# ldconfig -p | grep libgdiplus
libgdiplus.so.0 (libc6) => /usr/lib/libgdiplus.so.0
The output clearly shows that libgdiplus.so.0 is there in ldconfig cache but still the program is not working. I also tried to add DllMap entry in application configuration as below
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
<dllmap dll="gdiplus.dll" target="libgdiplus.so.0"/>
</configuration>
Please let me know if anybody stumbled upon this in past.
You have traced the error wrong.
Your mono version does not support EnableVisualStyles.
Upgrade to a version, which supports it ( as far as i remember it is >= 2.9 ) or try to disable this feature in Your .net application, which will result in "not so nice ui elements".
For me it worked, as i was working on gentoo.
Suddenly, after a emerge, my mono application did not crash anymore.
Also be sure that libgdiplus.so.0 is actually installed and on the path, it is not by default in mono. But yes, the main thing is CentOS comes with an outdated version of mono by default.

Categories

Resources