Click here to Skip to main content
14,265,748 members
Rate this:
Please Sign up or sign in to vote.
I wrote an app and made an exe of it ,run it on my own machine, works fine.
The same app on another machine when clicked to 'play',it says:
See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at ReClient_ServerWinforms.Form1.Ping_all()
   at ReClient_ServerWinforms.Form1.Form1_Load(Object sender, EventArgs e)
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
ReClient_ServerWinforms
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files%20(x86)/PureTechs%20Ltd/My%20Product%20Name/ReClient_ServerWinforms.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
 


I enabled JIT in my App.config as:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
  <system.windows.forms jitDebugging="true"/>
</configuration>


But still the same error doesn't let me the app to run.
Why?
Posted
Comments
Richard MacCutchan 25-Mar-15 4:16am
   
You need to fix the IndexOutOfRangeException error.
Jeddi khan 25-Mar-15 7:03am
   
But it is all right on my machine.....how'd i know the cause of this error while everything on my side works fine!
Andy Lanng 25-Mar-15 5:55am
   
Does your other machine have a "JIT debugger registered on the computer"
Jeddi khan 25-Mar-15 7:02am
   
On the testing machine i don't have any Visual studio installed.
I then tried by installing it,still it gives the same error
Andy Lanng 25-Mar-15 7:08am
   
Hmm - that is odd. Assuming that you have copied all relevant dlls and configs to the exe folder then maybe fall back on tradition and debug the source in VS on the target machine?
I have found that debugging code in VS can hide problems such as race conditions, but you might find a GAC library missing at the same time.
Oh! PS: jit debugging won't work with VS express:
https://msdn.microsoft.com/en-us/library/bdcetka3%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
Jeddi khan 25-Mar-15 7:20am
   
I have already through that link!
Mine is VS 2013 Professioanl
Andy Lanng 25-Mar-15 7:21am
   
Cool. Just wanted to mention about VS Express in case that was what you installed on the target machine.
So can you debug the source on the target machine?
Jeddi khan 25-Mar-15 7:45am
   
Okay,,,,,let me install the latest VS on remote machine.....I would test it then
Jeddi khan 25-Mar-15 7:46am
   
I would tell you then
Jeddi khan 26-Mar-15 13:08pm
   
I installed VS 2013 on the other machine(where i was testing) and on debug i got the same error:IndexOutOfrangeException
Jeddi khan 26-Mar-15 13:09pm
   
But what a pathetic situation it is:
The following function gives me correct gateway IP on my PC:

static string NetworkGateway()
{
string ip = null;

foreach (NetworkInterface f in NetworkInterface.GetAllNetworkInterfaces())
{
if (f.OperationalStatus == OperationalStatus.Up)
{
foreach (GatewayIPAddressInformation d in f.GetIPProperties().GatewayAddresses)
{
ip = d.Address.ToString();
}
}
}

Console.WriteLine(string.Format("Network Gateway: {0}", ip));
return ip;
}



And this function on another PC gives:- ::

Why so?
Andy Lanng 27-Mar-15 6:08am
   
hmm - looking into it. Maybe check hosts file: "C:\Windows\System32\drivers\etc\hosts" (::1 is localhost for eg) or the zeros are compresses so it's actually 0:0:0:0 or the gateway has no true ip address.
The method seems to return an arbitrary gateway. may I suggest some linq:
//Exact copy of your code in linq
foreach (
GatewayIPAddressInformation d in
from f in NetworkInterface.GetAllNetworkInterfaces()
where f.OperationalStatus == OperationalStatus.Up
from d in f.GetIPProperties().GatewayAddresses
select d)
{
ip = d.Address.ToString();
}
//This also gets all addresses:
NetworkInterface.GetAllNetworkInterfaces()
.Where(f => f.OperationalStatus == OperationalStatus.Up)
.SelectMany(f=>f.GetIPProperties().GatewayAddresses)
.Select(d=>d.Address)
//You can .First or .Last to get a single address, or check that the IP isn't "::"
Jeddi khan 28-Mar-15 9:15am
   
I am not getting ".Select(d=>d.Address)
//You can .First or .Last to get a single address"
Andy Lanng 30-Mar-15 5:46am
   
Ok - let me post as solution so we can see it easier and continue the convo based on that ^_^

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

hmm - looking into it. Maybe check hosts file: "C:\Windows\System32\drivers\etc\hosts" (::1 is localhost for eg) or the zeros are compresses so it's actually 0: 0: 0: 0 or the gateway has no true ip address.
The method seems to return an arbitrary gateway. may I suggest some linq:
//Exact copy of your code in linq
    foreach (
        GatewayIPAddressInformation d in
        from f in NetworkInterface.GetAllNetworkInterfaces()
        where f.OperationalStatus == OperationalStatus.Up
        from d in f.GetIPProperties().GatewayAddresses
        select d)
    {
        ip = d.Address.ToString();
    }
    //This also gets all addresses:
    NetworkInterface.GetAllNetworkInterfaces()
        .Where(f => f.OperationalStatus == OperationalStatus.Up)
        .SelectMany(f=>f.GetIPProperties().GatewayAddresses)
        .Select(d=>d.Address)
//You can .First or .Last to get a single address, or check that the IP isn't "::"
   
Comments
Andy Lanng 30-Mar-15 5:50am
   
Post from OP:
I am not getting ".Select(d=>d.Address)
//You can .First or .Last to get a single address"
Andy Lanng 30-Mar-15 5:53am
   
I used this to get by gateway to print out to console:
NetworkInterface.GetAllNetworkInterfaces()
.Where(f => f.OperationalStatus == OperationalStatus.Up)
.SelectMany(f=>f.GetIPProperties().GatewayAddresses)
.Select(d => d.Address).ToList().ForEach(a => Console.WriteLine(string.Format("Network Gateway: {0}", a.ToString())));

If you are not getting anything from that then it looks like that machine has no gateway that matches the criteria

I don't do networks so I don't know why that would happen :S

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100