Skip to content

IPAddress.TryParse return wrong result for 192.168.1 #112685

@SMAH1

Description

@SMAH1

Description

I use "IPAddress.TryParse" to validate the IP. When I validate 192.168.1 se result 192.168.0.1.

Image

Reproduction Steps

System.Net.IPAddress.TryParse("192.168.1", out var ip);
if (ip.ToString() == "192.168.0.1")
    Console.WriteLine("WHY?");

Expected behavior

Return invalid IP.

Actual behavior

Return wrong IP.

Regression?

No response

Known Workarounds

No response

Configuration

OS: Windows 10 22H2
.NET SDK: 9.0.200
IDE: Microsoft Visual Studio Community 2022 (64-bit) Version 17.13.0
Project Type: Web Project

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions