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
TheRanger•16mo ago
do u have a screenshot of your error with the code?
Joreyk ( IXLLEGACYIXL )
Joreyk ( IXLLEGACYIXL )OP•16mo ago
Joreyk ( IXLLEGACYIXL )
Joreyk ( IXLLEGACYIXL )OP•16mo ago
in IPAddress line 338
Joreyk ( IXLLEGACYIXL )
Joreyk ( IXLLEGACYIXL )OP•16mo ago
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 )
Joreyk ( IXLLEGACYIXL )OP•16mo ago
it throws on setting the property
TheRanger
TheRanger•16mo ago
dont show decompiled code show where its being called in your code
Joreyk ( IXLLEGACYIXL )
Joreyk ( IXLLEGACYIXL )OP•16mo ago
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
TheRanger•16mo ago
which line in this code throws the error?
Joreyk ( IXLLEGACYIXL )
Joreyk ( IXLLEGACYIXL )OP•16mo ago
line 22 which is coll.Insert(local); 👀
TheRanger
TheRanger•16mo ago
or atleast show the call stack window from here ok line 22, where is that?
Joreyk ( IXLLEGACYIXL )
Joreyk ( IXLLEGACYIXL )OP•16mo ago
coll.Insert(local);
TheRanger
TheRanger•16mo ago
what is the column type in your db table? might be better to just have the property as a string
Joreyk ( IXLLEGACYIXL )
Joreyk ( IXLLEGACYIXL )OP•16mo ago
litedb doesnt have column types i will store it as string thanks
Want results from more Discord servers?
Add your server