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

  • Home
  • SEARCH
  • 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 8643943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:10:28+00:00 2026-06-12T12:10:28+00:00

I have a struct on the server-side with a layout like this: struct SomeStruct

  • 0

I have a struct on the server-side with a layout like this:

struct SomeStruct
{
    public string SomeString { get; set; };
    public string SomeString1;
    public string SomeString2;
    public string SomeString3;
}

I am using a client/server model, and an instance of this struct gets referenced a lot of times as it has really important information (over 200 times).

The thing is that when some function gets called, the values inside this struct become null. I don’t know why and it is been bugging me for a really long time.

I call a lot of methods before realizing that this values are null, so I don’t know which section of my code nullify my strings.

I am using VS2012, but I have 2010 and 2008 ultimate as well. I was wondering if there is a way to perform a trigger when some section of code nullifies my strings.

I tried to add some properties like this, bot the exception was never thrown:

struct SomeStruct {
    string somestr;
    public string SomeString
    {
        get { return somestr; }
        set
        {
            if (value == null)
            {
                throw new Exception("stirng is null");
            }

            somestr = value;
        }
    }
    public string SomeString1;
    public string SomeString2;
    public string SomeString3;
}

Might not be important, but this is one of the structs I am using (the Name variable becomes null in some part of my code, and the rest turns into default()):

[ProtoContract]
public struct CharacterInformation
{
    [ProtoMember(2)]
    public string Name;
    [ProtoMember(3)]
    public IntegerVector2 Position;
    [ProtoMember(5)]
    public CharacterDirection Direction;
    [ProtoMember(6)]
    public CharacterStatus Status;
    [ProtoMember(7)]
    public CharacterClass Class;
    [ProtoMember(8)]
    public CharacterRace Race;
    [ProtoMember(9)]
    public CharacterType Type;
    [ProtoMember(10)]
    public CharacterFaction Faction;
    [ProtoMember(11)]
    public float MovementModifier;
    [ProtoMember(12)]
    public CharacterEquipment Equipment;
}

Edit: The only instance of this struct is created on a Sql-related function:

public CharacterServerInformation GetInformation(int charID)
        {
            CharacterServerInformation information = new CharacterServerInformation();
            if (!authInstance.CharacterExists(charID))
            {
                // char doesn't exists
                throw new Exception("Character doesn't exists");
            }
            information.ID = charID;
            information.Experience = GetExperience(charID);
            information.Info.Direction = CharacterDirection.Bottom;
            information.Info.Name = authInstance.CharacterGetName(charID);
            information.Info.Class = GetClass(charID);
            information.Info.Faction = GetFaction(charID);
            information.Info.Position = GetPosition(charID);
            information.Info.Race = GetRace(charID);
            information.Info.Status = GetStatus(charID);
            information.Info.Type = GetType(charID);
            information.Info.MovementModifier = 1f; // should store old movement modifier, but well, whatever
            information.HealthLeft = GetHealthLastLogout(charID);
            return information;
        }
  • 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-12T12:10:29+00:00Added an answer on June 12, 2026 at 12:10 pm

    I suspect the problem is purely because you’re using struct and not making a class. Since struct members are copied by value into methods and when returned from methods, including property getters, it’s likely that you’re “losing” the information by accidentally writing a new struct somewhere.

    In this case, class seems is far more appropriate. If you read Choosing Between Classes and Structures, you’ll see that struct should only be used when:

    • It logically represents a single value, similar to primitive types (integer, double, and so on).
    • It has an instance size smaller than 16 bytes.
    • It is immutable.
    • It will not have to be boxed frequently.

    In your case, all of these criteria ( except maybe the last) are being violated, so class would be more appropriate.

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

Sidebar

Related Questions

Ok so I have struct like this typedef struct { float x; float y;
i have a structure public struct SERVER_USB_DEVICE { USB_HWID usbHWID; byte status; bool bExcludeDevice;
I have a structure [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct SERVER_USB_DEVICE { USB_HWID usbHWID;
I have a struct that looks something like: struct foo_t { template <std::size_t x,
I have written the following code in the server side for a chat client
I have this simple client-server application pair. The code is pretty simple, I'm using
I have an issue when my client sends struct data to my server. My
I have a socket server running on multiple machines. It works like a charm
Suppose I have: struct Magic { Magic(Foo* foo); Magic(Bar* bar); }; Is there a
using C++, I have struct Base { virtual void stuff(/*base stuff*/); }; struct Derived

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.