Memory dump using Ping .net - c#

I'm trying to do a ping to a server in a Windows Forms Application but when my program is running, I have memory dump on my computer. Very, very strange.
In my method I only have:
private void CheckServer()
{
this.txResponse.Text = "";
IPAddress IpAdress = IPAddress.Parse("anAdress");
Ping ping = new Ping();
PingReply pingToReply = ping.Send(IpAdress);
if (pingToReply.Status == IPStatus.Success)
txResponse.Text = pingToReply.Status.ToString();
}
I really don't understand what is going on.
I'm using Visual Studio 2012 with .NET Framework 4.5 on Windows 8.If it is necessary more information, please let me know.

Verify that the parsing of the IP Address is successful; otherwise check the surrounding processing outside of the CheckServer method.

Ahhh, the joys of programming having a program blow up when there is absolutely nothing wrong with the code... (your code looks fine other than putting a try/catch block around it)
It could be a hardware issue (memory, disk etc), bad dll, or any number of things that go bump in the night. I assume you have tried rebooting your computer, and pinging your server at the DOS prompt. If not do so.
One thing you could try is to call ping.exe directly with a command line/ip of your choice synchronously or asynchronously, see http://www.codeproject.com/Articles/25983/How-to-Execute-a-Command-in-C and then parse the output to get what you need (lines starting with "Reply from" or "Request timed out." or even the % loss line.
Another thing to try is bypass the c# Ping and PingReply calls entirely and use net sockets and a timer, see http://sourceforge.net/projects/pingutil/?source=typ_redirect particularly the ping.cs file.
These solutions would allow you to potentially write around the problem, but it does not necessarily solve the problem at hand, which does not appear to programming related from the code you have provided.
OK, other thoughts... 1)Do a rebuild all on your project 2) Try compiling using an older version of .NET 3) Create a new project and copy block the source into the newly created files. 4) run the project on another computer to see if you get the same results. Any exception error that may or may not be generated should never cause a core dump.
Yet another option is to analyze the core dump, for an application, see: http://sourceforge.net/projects/core-analyzer/ and also check out
Tool for analyzing java core dump
Worse comes to worse, you may have to reload Visual Studio and/or .NET.

Related

NancyFX/Linux/Mono - Large uploads (over 1MB) work on windows server but not linux

I seem to have a rather strange problem which I was wondering if anyone could shed a light on.
I am writing an Android app which uploads/downloads files from a self hosted C# server. The server is written in C# (using NancyFX self-host) and the Android app is using HttpClient (Apache) to talk to the server.
When I attempt to upload the files on windows (which is where I manually debug into the server code), the upload works fine for any number of files with any arbitrary length. Everything works as expected and both small and large files get uploaded.
However, when I deploy this server to my Linux box (OpenSuSe) and run it, the uploads behave differently. The smaller files (< 1MB) still work as expected but when the file goes over this limit, the HttpClient's .execute() hangs indefinitely. I tried to set the socket timeout to 10 seconds (to test) and I once received a socket timeout exception but other times, it simply hung there, never even timing out. It's also worth mentioning that the request never reaches the server which would implicate that the problem is most probably not with the Nancy server (although I could be wrong).
Given the nature of the problem, I'm inclined to believe that the problem lies somewhere in the Linux server configuration which does not allow larger POST requests for whatever reason but I've not been able to figure out why that would be the case. I do have a PHP server on that very same Linux box and on that, I can upload files larger than 1MB without any problems.
Other steps I've tried: I've disabled the firewall on the Linux server to see if it was a firewall problem (highly unlikely since <1MB reaches the server just fine) but that didn't help. I also changed the MTU to be in-line with my windows machine but that did not make a difference either.
As it stands, I'm out of ideas. Does anyone know how to trace this further to get to the bottom of the problem? Any help would be greatly appreciated.
Many thanks in advance.
I've fixed the problem with the hanging after spending a lot of time googling it. The problem was with Mono and has been fixed in the latest version (3.4). I've installed this version on my Linux box and the hanging issue is gone.
More details here:
https://github.com/mono/mono/commit/a31b580fdcbaa9a8a16d59ffb12d04f5872f54e8
I have another problem now though. The image file that is retrieved on the server side is corrupt. Given the fact that the very same code works in Windows, I'm inclined to believe the issue rests with Mono or more likely, with NancyFx's code on Mono. I will debug further into it and update the progress of this question, in case anyone else ever runs into the same issue.
So for anyone who runs into this problem, the second problem (with files becoming corrupted) can be solved by editing RequestStream.cs within the Nancy library according to this post (look # response by Rohansi commented on Apr 30)
https://github.com/NancyFx/Nancy/issues/1333
This seems to be a problem with Mono on Linux (I'm using 3.4) where if you specify the async flag in the FileStream, the process does not quite work.
For now, I have built a custom version of Nancy and that's what I'm using. I'll try to ask them to see if it would be possible to disable the async using some configuration in the main library and will also raise the issue to Mono dev but for now, if you run into this problem, I hope the above comments helps you.

Using R(D)COM for integrating R with C#

I am trying to use R(D)Com interface. I have R 2.12.1 installed on machine. For using this interface in C#, I loaded rscproxy_1.3-1 package and then installed R_Scilab_DCOM3.0-1B5 on my machine. Also, I copied sciproxy.dll from Program Files\R(D)COM Server\Scilab to Program Files\R(D)COM Server\bin, as informed while installing the interface.
My Problem:
As a part of testing, I tried the code from blog post http://vvella.blogspot.com/2010/08/integrate-c-net-and-r-taking-best-of.html. But my form application failed due to exception raised by statement rconn.Init(“R”). The exception text was Exception from HRESULT: 0x80040013 I tried to run samples from Programs->R->R(D)COM Server->Server 01 Basic Test. On launched form, I clicked button “Start R” but it failed with error printed in text box as “Initializing R...Function call failed Code: -2147221485 Text: installation problem: unable to load connector”
I tried this:
I tried to troubleshoot it with the help of Index html page, and there under installation section, I found that there must be rproxy.dll under installed R/Bin folder. Also, HKEY_LOCAL_MACHINE\Software\R-core\R\InstallPath should point to installation folder.
Things lacking on my machine are
the installed R/bin folder doesn’t
contain rproxy.dll. Where can I get
this dll? Or is it sciproxy.dll
instead?
HKEY_LOCAL_MACHINE\Software\R-core\R\InstallPath
points to installation folder, but
there is no entry under
HKEY_CURRENT_USER\Software.
I can guess there is something fishy about installation, or registering COM server. But I am not successful in figuring it out.
Could you please tell me where am I going wrong?
thanks,
Kapil
Oh god I remember this being a huge pain in the arse. Lets see if I can remember... And before I start, I warn you that I just "got this working" and never cared to work out if I could remove parts from the process.
Downloads are available from http://rcom.univie.ac.at/download.html . If I remember correctly, the RandFriends package is all you need, it installs a crapload (just install it all) but is simple. Alternatively, I think if you install the 'rscproxy' package in R you can just download the 'statconnDCOM' and install that. Memory is hazy, but I know one of these methods results in an annoying splash screen everytime you run your C# executable, and one doesn't. Although that could have just been some setting I played with.
Now, I can't remember how you verify that stuff has installed successfully. Pretty sure it comes with examples though. Once that is started, get your C# project open. Reference the following projects,
StatConnectorCommonLib
STATCONNECTORSRVLib
In your code, you will probably want to implement a IStatConnectorCharacterDevice so you get the R output coming back out in C#. Your code to initialise will then look something like,
private StatConnector _StatConn;
private IStatConnectorCharacterDevice _CharDevice;
private Whatever()
{
// declare
_StatConn = new StatConnectorClass();
_CharDevice = new MyCharDevice();
// init R, wire up char device
_StatConn.Init("R");
_StatConn.SetCharacterOutputDevice(_CharDevice);
}
Then you should be able to just use the functions as needed
_StatConn.EvaluateNoReturn("x <- 3");
var returnObj = _StatConn.Evalute("1 + 1");
Hope that helps.
tl;dr download RAndFriends, do fresh install with that
I had a similar problem calling R.Init(), I found R.GetErrorText() returns the actual error message

How can I get data off of my Windows Phone 7 emulator

I have a unit testing framework for WP7 and it runs on the phone. The results are fairly hard to read so I am writing them to an XDocument.
My question is, how can I then get this XML file off of the phone and onto my desktop where I can actually analyze the results?
What I have done so far is to put a Debugger.Break() line right after where the summary xml is created. I can then copy/paste the xml out of VS or inspect it right in the debugger. The problem is though, that if you don't already have a debugger attached (which is good when lots of ExpectedException tests) Debugger.Attach() seems to not work, also manually attaching VS to the emulator processes seems to do nothing.
I tried running the emulator with some extra command line parameters so I could try to see if I could get it to use my actual hard drive as it's own disk but I couldn't seem to get it to work...
PS it's probably not reasonable to pop open a new process such as a webserver to listen for this data. I know how to do that, I would just rather not.
So how the heck do you get stuff off of these phones??
Have a look at this article about emulator automation from Justin Angel.
It includes details on how to remotely read and write files from/to emulator/device isolated storage.
As you pointed out the other alternative would be to have the applciation send the results to a [local] web server.
The article by Justin Angel is really great, but unfortunately his file-based solution does not work on the final RTM versions of the CoreCon API. Microsoft has simply removed that functionality from the native conman layer.
I've been in the same situation as you and have contemplated various ways to get data out of the device, but in the end only one thing seems to work: as you suggest yourself, pass data to an external webservice.
That solution is less than ideal not only because it takes some effort, but also because of a few caveats:
your app must be granted ID_CAP_NETWORKING capability
network-traffic seems disallowed in the Application_Closing event, and maybe elsewhere too
On the bright side I found that webrequests from the phone, both hardware and emulator, were really fast so the approach works very well (our app is EQATEC Profiler for WP7).

SharePoint fails to load a C++ DLL on Windows 2008

I have a SharePoint DLL that does some licensing things and as part of the code it uses an external C++ DLL to get the serial number of the hardisk.
When I run this application on Windows Server 2003 it works fine, but on Windows Server 2008 the whole site (loaded on load) crashes and resets continually. This is not Windows Server 2008 R2 and is the same in 64 or 32 bits.
If I put a Debugger.Break before the DLL execution then I see the code get to the point of the break and then never come back into the DLL again. I do get some debug assertion warnings from within the function, again only in Windows Server 2008, but I'm not sure this is related.
I created a console application that runs the C# DLL, which in turn loads the C++ DLL, and this works perfectly on Windows Server 2008 (although it does show the assertion errors, but I have suppressed these now).
The assertion errors are not in my code but within ICtypes.c, and not something I can debug.
If I put a breakpoint in the DLL it is never hit and the compiler says:
"step in: Stepping over non user code"
If I try to debug into the DLL using Visual Studio.
I have tried wrapping the code used to call the DLL in:
SPSecurity.RunWithElevatedPrivileges(delegate()
But this also does not help.
I have the source code for this DLL so that is not a problem.
If I delete the DLL from the directory I get an error about a missing DLL. If I replace it, back to no error or warning just a complete failure.
If I replace this code with a hardcoded string the whole application works fine.
Any advice would be much appreciated, I can't understand why it works as a console application, yet not when run by SharePoint. This is with the same user account, on the same machine...
This is the code used to call the DLL:
[DllImport("idDll.dll", EntryPoint = "GetMachineId", SetLastError = true)]
extern static string GetComponentId([MarshalAs(UnmanagedType.LPStr)]String s);
public static string GetComponentId()
{
Debugger.Break();
if (_machine == string.Empty)
{
string temp = "";
id= ComponentId.GetComponentId(temp);
}
return id;
}
This could be security related:
An important point is that it works in a console app.
In a console app RunWithElevatedPrivileges has no effect since it emulates the app pool user for your worker process, a user that should have no special rights on the box itself.
In contrast a console app runs in context of the logged in user.
Try emulating a user with rights like when you run the console application specified here (with Undo() inside try/finally mind you!). When obtaining the token you can create an SPUserToken and establish site context using the SPSite constructor that takes a GUID and a SPUserToken
Theres several examples out there documenting this approach, here for example.
EDIT: oh and the reason it worked on 2003 could be that your app pool account had way too many rights ;-)
Why not use WMI to get the serial number of hard disk, thus avoids execution of unmanaged code. See this sample How to Retrieve the REAL Hard Drive Serial Number
That non-deterministic crashing behavior is often seen with memory overwrites/corruption; sometimes it matters (crash), sometimes you get lucky.
You might want to check into getting a crash dump and analyze it with WindDbg. Since you have the source you could re-build it with the various stack, heap memory protection and warning systems enabled (depending on your compiler) and see what you get.
I'd find out if it is a User Account Control related problem, you can try to disable it.
2003 doesn't have UAC.
Your app pool account might not have the right to retrieve this information?
In visual studio, go into the properties of your executable assembly, and under the debug tab, check the enable debugging unmanaged code option.
If the method your are importing belongs to a class, you need to add the mangled C++ name (e.g. 2#MyClass#MyMethod?zii) as an entry point to the DllImport attribute (run depends on the native DLL to get it).
You do not need C++ for that: http://www.codeproject.com/KB/cs/hard_disk_serialno.aspx
If i put a breakpoint in the DLL it is
never hit and the compiler says :
"step in: Stepping over non user code"
That's the debugger, not the compiler, and if you configured it properly it wouldn't do that. Look for the options calls "Use native debugging" and "Just my code". The first one should be on and the second one off.
This problem may happen due to one of the problems listed below.
the web part may not have the right permissions to call the DLL or
you may not have set the appropriate trust level for your SharePoint site.
For the permission you can use impersonation and for the trust level below site can help you.
http://msdn.microsoft.com/en-us/library/dd583158(office.11).aspx
I made a new C++ DLL from scratch which works fine when referenced as a console application on Windows Server 2003 and Windows Server 2008, but as soon as I reference it from the DLL in SharePoint the same things happens and it won't run.
It does find the DLL, but I think it has no permissions to execute it, even if I put it into the My Documents section and reference it directly!

How can I debug an OutOfMemoryException in ASP.NET?

I am reading an .opml file and parsing it to generate a list of articles for each rss feed I subscribe to and thus add into this .opml file.
At times, when pressing play on Visual Studio (Run), I get an error (not exception) stating an OutOfMemoryException. This is before the application can even run (but has compiled). The page in question (the error comes in the output window with the relevant page) is the RSS Reader page, which calls the methods to do the parsing.
How can I completely fix this error? This error only comes up at times so it is hard to reproduce. Some information points to an issue with my dev environment, not the site or Visual Studio (This could mean another set of variables when live). Has this exception got any link to a potential memory leak (is it a possible warning)? Would memory profiling help (I have a memory profiler)?
Thanks
If I understand correctly, Visual Studio itself is OOM and reporting that it cannot start the debugg process. Is the devenv.exe process using a lot of memory? If you are under VS 2005 on a 64 bit OS you can try the advice from this post to make the devenv.exe use 4GB and perhaps aleviate your problem.
If is not VS itself that is OOM, you'll need to locate the problem. The culprit should be the one that shows up in task list with a large VM size. Running VS itself under debugger may help. Also, sometime system errors (like kernel resource exhaustion) are translated to OOM error.
How are you parsing this? You can run out of memory in a variety of ways, such as doing this in a tight loop:
for(....)
{
//Creates immutable strings faster than they can be garbage collected
nextXMLPart = nextXMLPart + " " + something;
}
How big is the file? If you are reading the entire file into memory that would do it.
Any how, I'd start looking at any loops that repeat a lot. And if that doesn't work, fire up task man and put break points in the code. Watch for where the app is when memory usage starts to shoot up.

Categories

Resources