Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7782609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:35:45+00:00 2026-06-01T19:35:45+00:00

I was just trying to debug the following exception: Exception has been thrown by

  • 0

I was just trying to debug the following exception:

Exception has been thrown by the target of an invocation.: System.Reflection.TargetInvocationException: 
Exception has been thrown by the target of an invocation. ---> 
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: newAddress
   at System.Net.IPAddress..ctor(Int64 newAddress)

This is the code in question:

int hostToNetworkOrder = IPAddress.HostToNetworkOrder( (int)computer.IpAddress );
IPAddress ipAddress = new IPAddress( hostToNetworkOrder );

computer.IpAddress is set to 1582281193. This gets converted to hostToNetworkOrder, which is -374255778.

Now, if I try to construct new IPAddress( -374255778 ); in the Immediate Window in Visual Studio, I get an IPAddress object containing the correct IP address.

But if I step over the line in the code, it will always throw an ArgumentOutOfRangeException. Why?


Update

I was aware that my input being negative was, most likely, the source of this issue. This is how I solved it:

UInt32 hostToNetworkOrder = (UInt32)IPAddress.HostToNetworkOrder( (Int32)computer.IpAddress );
IPAddress ipAddress = new IPAddress( hostToNetworkOrder );

What I still don’t understand is why it worked at all in the Immediate Window.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:35:46+00:00Added an answer on June 1, 2026 at 7:35 pm

    Looking at the IPAddress class in ILSpy there is an internal constructor that takes an int and does not do an argument out of range check – I have a feeling that it may be calling that constructor in the watch window but in the actual code it calls the public ctor(long), which does validate that number.

    To test out my theory, I just tried this bit of code:

    var ipAddress = (IPAddress) typeof (IPAddress)
                                            .GetConstructor(
                                                BindingFlags.NonPublic | BindingFlags.Instance,
                                                null,
                                                new[] {typeof (int)},
                                                null)
                                            .Invoke(new object[] {hostToNetworkOrder });
    

    and, sure enough, the IPAddress class is constructed without error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling for hours trying to debug why the following delete query
I'm just trying to quickly debug a webservice by printing out the contents of
I just spent hours trying to debug an out of memory error caused by
I'm trying to debug an application (under PostgreSQL) and came across the following error:
I'm trying to debug something and I'm wondering if the following code could ever
I'm getting a DoesNotExist error with the following set up - I've been trying
Just trying to get diff to work better for certain kinds of documents. With
just trying to test for equality in this piece of code, but getting a
Just trying to still get my head around IOC principles. Q1: Static Methods -
Just trying to establish whether prototype can do something like $$('#ID a:last').css('color','#111'); Any ideas

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.