Why does IPAdress storage in objects immediate crash

public class Host
{
public string Name { get; set; }
public IPAddress IP { get; set; }
}
string ip = "127.0.0.1";
IPAddress parsedIP = IPAddress.Parse(ip);
var local = new Host()
{
Name = "localhost",
IP = parsedIP
};
public class Host
{
public string Name { get; set; }
public IPAddress IP { get; set; }
}
string ip = "127.0.0.1";
IPAddress parsedIP = IPAddress.Parse(ip);
var local = new Host()
{
Name = "localhost",
IP = parsedIP
};
IP = parsedIP this line throws an exception that there is a socket error , without any reason, i just cant store an ipaddress objekt inside an objekt
13 Replies
TheRanger
TheRanger12mo ago
do u have a screenshot of your error with the code?
Joreyk ( IXLLEGACYIXL )
in IPAddress line 338
Joreyk ( IXLLEGACYIXL )
this doenst happen on the parsing, the parsing is successful ( its copied from docs here https://learn.microsoft.com/en-us/dotnet/api/system.net.ipaddress.parse?view=net-7.0 )
IPAddress.Parse Method (System.Net)
Converts an IP address string to an IPAddress instance.
Joreyk ( IXLLEGACYIXL )
it throws on setting the property
TheRanger
TheRanger12mo ago
dont show decompiled code show where its being called in your code
Joreyk ( IXLLEGACYIXL )
using LiteDB;
using NexOSTesting;
using System.Net;


string ip = "127.0.0.1";
IPAddress parsedIP = IPAddress.Parse(ip);
var local = new Host()
{
Name = "localhost",
IP = parsedIP
};
ConnectionString connection = new ConnectionString(@"C:\\Godot\\MyDatabase.db");
connection.Connection = ConnectionType.Shared;
using (var db = new LiteDatabase(connection))
{
var coll = db.GetCollection<Host>("OS/Hosts");
// Create an instance of IPAddress for the specified address string (in
// dotted-quad, or colon-hexadecimal notation).

coll.Insert(local);
Console.Read();
db.Dispose();
}
using LiteDB;
using NexOSTesting;
using System.Net;


string ip = "127.0.0.1";
IPAddress parsedIP = IPAddress.Parse(ip);
var local = new Host()
{
Name = "localhost",
IP = parsedIP
};
ConnectionString connection = new ConnectionString(@"C:\\Godot\\MyDatabase.db");
connection.Connection = ConnectionType.Shared;
using (var db = new LiteDatabase(connection))
{
var coll = db.GetCollection<Host>("OS/Hosts");
// Create an instance of IPAddress for the specified address string (in
// dotted-quad, or colon-hexadecimal notation).

coll.Insert(local);
Console.Read();
db.Dispose();
}
this is it currently and the Host class from above nothing more in the project
TheRanger
TheRanger12mo ago
which line in this code throws the error?
Joreyk ( IXLLEGACYIXL )
line 22 which is coll.Insert(local); 👀
TheRanger
TheRanger12mo ago
or atleast show the call stack window from here ok line 22, where is that?
Joreyk ( IXLLEGACYIXL )
coll.Insert(local);
TheRanger
TheRanger12mo ago
what is the column type in your db table? might be better to just have the property as a string
Joreyk ( IXLLEGACYIXL )
litedb doesnt have column types i will store it as string thanks