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 3855004
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:42:34+00:00 2026-05-19T17:42:34+00:00

The builtin .Net method System.Net.IPAddress.ToString() behaves inconsistently for IPv6 addresses. Given the byte array

  • 0

The builtin .Net method System.Net.IPAddress.ToString() behaves inconsistently for IPv6 addresses.

Given the byte array 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, in some environments "aaaa:aaaa:aaaa:aaaa:aaaa:aaaa:aaaa:aaaa" is returned, whereas others return "aaaa:aaaa:aaaa:aaaa:aaaa:aaaa:172.172.172.172".

I understand that both are valid IPv6 formats, but I would like to be able to explain the difference.

It seems that newer environments (Windows 7 and Server 2008 R2) are more likely to produce the first behaviour, so I’ve checked obvious differences like .Net framework version, but I’ve been unable to detect a pattern.

Is there a way I can select one format over the other, or do I have to code around this to get consistent behaviour?

Code to recreate:

    byte[] bytes = {0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA};
    IPAddress myIP = new IPAddress(bytes);
    Console.WriteLine(myIP.ToString());
  • 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-05-19T17:42:35+00:00Added an answer on May 19, 2026 at 5:42 pm

    Poking around in the internals of ToString, using Reflector, you can see that if it’s determined that the OS supports IPv6 (for some value of supports), then it defers to a Win32 function called WSAAddressToString, whereas if this flag isn’t set, it does manual formatting (from it’s internal byte array) as:

    addressString.Append(string.Format(CultureInfo.InvariantCulture, "{0:x4}", new object[] { this.m_Numbers[0] })).Append(':');
    addressString.Append(string.Format(CultureInfo.InvariantCulture, "{0:x4}", new object[] { this.m_Numbers[1] })).Append(':');
    addressString.Append(string.Format(CultureInfo.InvariantCulture, "{0:x4}", new object[] { this.m_Numbers[2] })).Append(':');
    addressString.Append(string.Format(CultureInfo.InvariantCulture, "{0:x4}", new object[] { this.m_Numbers[3] })).Append(':');
    addressString.Append(string.Format(CultureInfo.InvariantCulture, "{0:x4}", new object[] { this.m_Numbers[4] })).Append(':');
    addressString.Append(string.Format(CultureInfo.InvariantCulture, "{0:x4}", new object[] { this.m_Numbers[5] })).Append(':');
    addressString.Append((int) ((this.m_Numbers[6] >> 8) & 0xff)).Append('.');
    addressString.Append((int) (this.m_Numbers[6] & 0xff)).Append('.');
    addressString.Append((int) ((this.m_Numbers[7] >> 8) & 0xff)).Append('.');
    addressString.Append((int) (this.m_Numbers[7] & 0xff));
    

    which will always return the second format you’ve shown.

    Whether the flag “OS supports IPv6” flag is set seems to depend on both internal knowledge within the class (version must be > 2000) and it would appear an actual attempt to create an IPv6 socket – so if your on an XP machine with IPv6 disabled, I think you’ll also get this second format.

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

Sidebar

Related Questions

I'm attempting to change the built in .Net culture fr-CA, using the following method:
What is the best method for user authorisation/authentication in ASP.NET MVC? I see there
Is there an easy method of accessing custom System.Configuration-based configuration data through a thread-safe
We are attempting to integrate an ASP.NET MVC site with our client's SSO system
Is there a built-in method for it? The .NET framework must have a method
Validation attributes in System.ComponentModel.DataAnnotations is very helpful in ASP.NET MVC 3. There is a
In ASP.NET MVC3, some function, like HtmlHelper.ActionLink, can take in an implicitly typed object
I've noticed that several built-in classes/methods in .NET framwork takes an argument of System.Type
Is there a built-in .NET class that can replace or work like WinHttp.WinHttpRequest? Thanks!
The built-in Math.Pow() function in .NET raises a double base to a double exponent

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.