Mono/Linux and wininet.dll - c#

I've got a commandline C# program that compiles and runs fine using Visual C# 2010 and Windows 7. It also compiles and starts fine on Linux/Mono (2.10), but then sits there. (The program is using a 3rd party DLL to fetch data from a remote server.)
Running it in the debugger, I saw it seemed to be waiting for a DNS lookup. So I did the DNS lookup for it, pasted in the IP address. But it still hangs, and breaking into the debugger shows three threads all sitting there waiting:
System.Threading.Monitor.Wait (timeout set to -1)
System.Threading.Thread.Sleep
System.Threading.WaitHandle.WaitOne
I used MoMA to analyze the DLL. I'm not sure how accurate that is, because it matches against Mono 2.8, and I'm using 2.10.8.1, but it says Socket.Dispose() is a missing method. Then 32 [MonoTodo] items, 30 of which are Type.op_Equality or Type.op_Inequality. The other two are CredentialCache.get_DefaultCredentials() and MemoryMappedFile.CreateOrOpen().
But what got my attention was, at the bottom of the report, there are two entries for GetWindowsSocksProxy, which turns into SingleServerConnection.InternetQueryOption, and the P/Invoke library is wininet.dll. Could this be related?
So, is there anything I can do? E.g. can I copy that DLL from a windows machine to my linux machine? If so, where do I put it?
P.S. I wondered about connectivity issues. So I made a quick test Mono using WebClient, which worked fine. But one interesting difference is the non-working script loads "/usr/lib/mono/gac/Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll [External]" at the point where it first needs to connect to something. But my WebClient never did that.

Related

WinForms app - Unable to read local memory

I'm retrieving the following error in a Windows Forms App (.NET Framework) by debugging execution:
And this different type of error (but in the same method) if I run the compiled exe:
Could the problem be linked to the inability to read the memory? (see the "Locals" panel on the bottom of the first picture) Why is impossible to read it?
I think the problem is memory because in the prevoius 32-bit version the application works fine, so the problem is not writing code. I'm now working at this new 64-bit version because of the 64-bit update of St7API.dll, which is called by the St7 class. I attach a few lines from this class for a better understanding.
Thank you in advance for any answers
Edit:
For other previous lines in the code there are no errors using St7API.dll. The app works fine and the error occur only when is run a specific process, maybe the the heaviest for the memory.
For the using of this API is provided a C# class (image 3) and a "closed" DLL. I add an image to the API guide for a function:

Write variables of TwinCAT 2 PLC via ADS remotely

The reason why I am asking a question is because I am having issues writing variable values of a TwinCAT 2 system remotely (but reading variables works fine).
The setup what I am trying to make working is the following: There is an avreage PC where the I would like run my .NET 6 based application TwinCAT.Ads 6.0.129 included, and the 3.1 4024.29 build of TwinCAT 3 runtime is installed. The remote system an industrial assambly station based on (PC-165552) TwinCAT 2 runtime version 2.11 build 2126. The way why I trying to get acces to the variables of the TwinCAT 2 system is CreateVariableHandle, then use the ReadAny, and WriteAny methods. I tried other ways as well but this looks the easiest for me.
I have tested my code to running a test TwinCAT runtime PLC on my localhost, and get acces to the variables of test runtime. The whole data exchange worked fine I could read and write variables, but somehow if I change to remote and I try to acces to the remote PLC variables I can only read thier values, but not write them.
I tried several ways to indentify the problem. I installed the TwinCAT engineering and tried to analyse the ADS communication via the integrated ADS Monitor tool. I sent a Write Request with the ADS Command test tool to the certain variable but even taught the transfer was succesfull the variable did not changed. I also monitored the process with ADS monitor so I had a possibility to check the conctent of the Request and Response messages and they looked absolutely fine with no error. I studied all the available documentation, but I couldent find anything what could cause the mentioned issue.
Since the C# code works fine on local host, and I cant even write those variables remotely on the given target station even with the built in Beckhoff tools. My conclusion is some sort of settings must be wrong on the TwinCAT 2 target station (maybe firewall or something).
Could you please give me some hints where and what settigns I suppose to look around.
The issue was the certain variable was overwriten cyclically on the remote (PLC) side. Unfortunatelly I did't have acces to the source code of the PLC, therefore I did't have a possibility to verifly it myself.
I was expecting something like that because the I didn't received any error during the write request. So it was succesfull but right after the variable was overwriten.
I just swithed the PLC to stop to stop the porgram execution, and after I tried to write the variable.

.net application is blocked on start hanging in process explorer with 1 MB

I have a Windows Forms Application written on C# and it targets .net framework 4.8.
I run this application on Windows 7 x86 on the customer's PC. My application works fine but time to time I have a mystic problem with its launch. Sometimes my application just refuse to start but when I open process explorer I see MyAplication.exe which holds 1MB of RAM. It seems that something is blocking my application.
I examined windows events log but there are no errors. I also tried to write into the log file on the first line of Program.cs but it simply doesn't happen. I kill this 1 MB process and restart my application. It opens and work just fine or I have to restart it few times. I have experienced this kind of 1 MB RAM problem with my another WPF application and even with .net application from an external vendor. I created a dump file for my application using process explorer.
On my personal PC on Windows 10 I used WinDbg application from the Windows Store to analyze dump file of my application. I see the following:
FAULTING_THREAD: 000002a0
PROCESS_NAME: MyApplication.exe
ERROR_CODE: (NTSTATUS) 0x80000003 - {EXCEPTION} Breakpoint A breakpoint has been reached.
EXCEPTION_CODE_STR: 80000003
MISSING_CLR_SYMBOL: 0
STACK_TEXT:
002be670 77176c04 ntdll!KiFastSystemCallRet+0x0
002be674 771765ac ntdll!NtWaitForSingleObject+0xc
002be678 77161db1 ntdll!RtlpWaitOnCriticalSection+0x13e
002be6dc 77161c95 ntdll!RtlEnterCriticalSection+0x150
002be704 76e5cc0f rpcrt4!PerformRpcInitialization+0x29
002be748 76e665fd rpcrt4!RpcStringBindingComposeW+0x15
002be758 72ab1ec0 DialogFilterProc!InitDialogFilterProc+0x32d
002be810 72ab18b3 DialogFilterProc!ReleaseDialogFilterProc+0x17d
002be828 72ab2157 DialogFilterProc!InitDialogFilterProc+0x5c4
002be844 72ab22be DialogFilterProc!InitDialogFilterProc+0x72b
002be8a4 771887cc ntdll!LdrpCallInitRoutine+0x14
002be8c4 77195adb ntdll!LdrpRunInitializeRoutines+0x26f
002be9b8 7718faf2 ntdll!LdrpLoadDll+0x472
002beb2c 77192105 ntdll!LdrLoadDll+0xaf
002beb64 7523b246 KERNELBASE!LoadLibraryExW+0x215
002bebac 772aefa4 user32!__ClientLoadLibrary+0x60
002bece0 77176b3e ntdll!KiUserCallbackDispatcher+0x2e
002bed7c 772b4f21 user32!NtUserMessageCall+0xc
002bed80 772e5d6e user32!CallNextHookEx+0x10b
002bedb0 6d460ef0 tiptsf!TabletCallWndProc+0x5f
002bedd0 772a7a02 user32!DispatchHookW+0x33
002bedec 772a4999 user32!fnHkINLPCWPSTRUCTW+0x52
002bee20 772ae952 user32!__fnINLPCREATESTRUCT+0x8b
002bee50 77176b3e ntdll!KiUserCallbackDispatcher+0x2e
002beec4 772aeb5c user32!NtUserCreateWindowEx+0xc
002beec8 772aeaf0 user32!VerNtUserCreateWindowEx+0x1a3
002bf16c 772aec1c user32!_CreateWindowEx+0x201
002bf218 772aec77 user32!CreateWindowExW+0x33
002bf254 7682633f ole32!InitMainThreadWnd+0x3e
002bf28c 768263fc ole32!wCoInitializeEx+0xef
002bf2a4 768209ff ole32!CoInitializeEx+0x2ee
002bf2c4 7124ab8f clr!Thread::SetApartment+0x13b
002bf310 7123e1b7 clr!SystemDomain::SetThreadAptState+0x92
002bf330 7123e892 clr!SystemDomain::ExecuteMainMethod+0x18c
002bf810 71242498 clr!ExecuteEXE+0x4c
002bf868 712425be clr!_CorExeMainInternal+0xdc
002bf8a8 7123def5 clr!_CorExeMain+0x4d
002bf8e4 7185fa84 mscoreei!_CorExeMain+0xd6
002bf91c 718e7f16 mscoree!ShellShim__CorExeMain+0x99
002bf92c 718e4de3 mscoree!_CorExeMain_Exported+0x8
002bf934 7616ef3c kernel32!BaseThreadInitThunk+0xe
002bf940 77193618 ntdll!__RtlUserThreadStart+0x70
002bf980 771935eb ntdll!_RtlUserThreadStart+0x1b
SYMBOL_NAME: DialogFilterProc!InitDialogFilterProc+32d
MODULE_NAME: DialogFilterProc
IMAGE_NAME: DialogFilterProc.dll
STACK_COMMAND: .ecxr ; kb ; dt ntdll!LdrpLastDllInitializer BaseDllName ; dt ntdll!LdrpFailureData ; ** Pseudo Context ** Pseudo ** Value: 88f6c30 ** ; kb
FAILURE_BUCKET_ID: BREAKPOINT_80000003_DialogFilterProc.dll!InitDialogFilterProc
OSPLATFORM_TYPE: x86
OSNAME: Windows 7
IMAGE_VERSION: 1.0.299.0
FAILURE_ID_HASH: {e56a1c21-26f9-3e25-d015-b9f79339b457}
Followup: MachineOwner
P.S: I disabled antivirus and windows defender but it didn't solve my problem.
I have no internet access on the customer's PC. Not sure if it can have an impact on my problem.
Can anyone help me with this mystic problem? Any ideas are much appreciated!
Lets read the call stack
clr!_CorExeMain
clr!_CorExeMainInternal
Main Method of managd code reached (SystemDomain::ExecuteMainMethod)
clr!ExecuteEXE
clr!SystemDomain::ExecuteMainMethod
clr!SystemDomain::SetThreadAptState
You most probably have an STAThread Apartment attribute on your Main method because
there a COM Appartmentstate is set Thread::SetApartment
clr!Thread::SetApartment
COM initializes (CoInitializeEx)
ole32!CoInitializeEx
ole32!wCoInitializeEx
ole32!InitMainThreadWnd
COM needs a hidden window to pump messages (CreateWindowExW)
user32!CreateWindowExW
user32!_CreateWindowEx
user32!VerNtUserCreateWindowEx
user32!NtUserCreateWindowEx
ntdll!KiUserCallbackDispatcher
user32!__fnINLPCREATESTRUCT
user32!fnHkINLPCWPSTRUCTW
user32!DispatchHookW
Something in this case tiptsf has hooked (DispatchHookW) into window creation to inject its own functionality (TabletCallWndProc). This one is from Microsoft Ink I suspect.
tiptsf!TabletCallWndProc
user32!CallNextHookEx
user32!NtUserMessageCall
ntdll!KiUserCallbackDispatcher
user32!__ClientLoadLibrary
This loads some extension dll
KERNELBASE!LoadLibraryExW
ntdll!LdrLoadDll
ntdll!LdrpLoadDll
ntdll!LdrpRunInitializeRoutines
ntdll!LdrpCallInitRoutine
Now we initialize DialogFilterProc which had problems in Windows 7 around 2012
On my Win10 machine I do not have this DialogFilterProc found. Is this a Windows 7 machine? This one is not documented at all so there is little information what this one tries to do here. According to this it seems to be a System Service which could be disabled, hence the hang.
DialogFilterProc!InitDialogFilterProc
DialogFilterProc!InitDialogFilterProc
DialogFilterProc!ReleaseDialogFilterProc
DialogFilterProc!InitDialogFilterProc
The DialogFilter calls RpcStringBindingComposeW which apparently hangs. From the docs
I can see that it deals with inter process communication.
Either the COM apartment was not yet fully initialized which cause this RPC method to hang or the remote connection could not be established.
See e.g. here for an example where this method is used.
rpcrt4!RpcStringBindingComposeW
rpcrt4!PerformRpcInitialization
ntdll!RtlEnterCriticalSection
ntdll!RtlpWaitOnCriticalSection
ntdll!NtWaitForSingleObject
ntdll!KiFastSystemCallRet
If the first issue is the premature loading of Microsoft Ink you can try to disable it and check if that works around your issue. If the issue persists you can try set on your main method the [STAThread] or [MTAThread] attribute. Perhaps another apartment mode will also resolve your deadlock.
Or if that is really the Dialog Filter which tries to call into a service which did crash or was not running then you need to restart the service to make your UI pop up.
As I could (hopefully) show you it is pretty easy to find out from any method what it is doing and how it can be turned off. Based on that you should have now plenty of further options to explore either the actual root cause or find a dirty workaround.
Addenum
Your DialogFilterProc.dll has version 1.0.299.0 which seems to be older than the one in the fix from 2012 which has 1.0.542.0. Installing the ancient fix could be the solution to your problem.
> File name File version File size Date Time Platform
> Dialogfilterproc.dll 1.0.542.0 13,312 24-Jul-12 17:11 x86

Looking to launch a local exe on a remote machine without having the resurces on the remote machine

So I have built some code, it's quite simple basically it stops all active input from keyboard and mouse until a text file of a certain name appears in the C:\Temp directory. It also has a manifest file to run it as administrator on start up.
So I found something that on the surface looks like it fulfils my needs of being able to do this task however upon running it I found out that the project has been compiled in x86 and does not run on my x64 machine. Here is the reference to the project if anyone would like to look into it, it's a very smartly designed piece of code that does an interesting objective. It also explains clearly enough what I am trying to accomplish.
So after implementing this (and failing) I have setup a couple other avenues to try, one is VBA through excel with the VBA copying itself to and from the machines in a list and running itself, then there is using VBS to write the entire code as a txt file on the target machine change the extension and then execute it remotely. I have just started researching these but I imagine the problems of running as an administrator amongst other things will crop up again to be dealt with. To be honest though I would really prefer to do this in C# only as that is the language I'm trying to go further in so I'm interested in this challenge. If anybody knows of a similar library of code or application I could look into to achieve what I'm trying I would appreciate being pointed in the right direction.
I would try and be more specific about what libraires/API's im trying to implement but the truth is I don't know what libraries I need to even interact with to get what I want. My goal is to have C# executable code on my machine and a tool that can run that executable on another machine.
Thanks
Thanks to the help in comments from #Nick.McDermaid I was able to correctly open and build the project I was trying to download. Unsure what caused the issue previously with me not being able to open and interact with the code but now I have it I shall pursue this avenue further to accomplish my goal.
As an addendum one other avenue I tried for executing code remotely was through VBS where I used
set svcproc=getobject("winmgmts:{impersonationLevel=impersonate}!\\"&MachineName & "\root\cimv2:win32_process")
scmd="""C:\Program Files\Internet Explorer\iexplore.exe"" -framemerging ""https://gifyu.com/images/Boo-Ghost-Gif.gif"""
'scmd="C:\Windows\notepad.exe"
iret=svcproc.create(scmd,null,null,pid)
set svcproc=nothing
to execute something that existed on the remote machine but I ran into a LOT of security policy issues where I could launch the process but I couldn't bring it to the foreground as the Malware tracker on the machine thought it was an attack and quashed it immediately.

SystemMemoryOutofException-Elasticsearch IndexMany

Im getting this error while indexing documents as an attachment. What can be the reason for this type of error. And why is it behaving differently when I run on server and when I run from visual studio.
More details about the problem is mentioned here.
Please have a look at the below link.
https://discuss.elastic.co/t/systemmemoryoutofexception-thrown-while-indexing-files-as-an-attachment/50916
TIA
I am not confident on where the actual error is ocurring. You need to determine if the error is in .net (on the client side) or in elastic? Both Visual Studio and elasticsearch will get to a point where they break without enough memory (or allocated memory) on the host machine.
If it is in elastic (check the logs - or run in console mode) - increase the heap space.
If it is on the client, try forcing your application in to 64 bit mode.

Categories