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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:38:32+00:00 2026-06-07T11:38:32+00:00

I have a really weird problem. I tried everything to fix it and so

  • 0

I have a really weird problem. I tried everything to fix it and so far nothing works.

As you can see in the first image image, when I try to reference the static class “SharedConstants” from a namespace outside “UnnamedGameServer” the compiler returns the following error:

The type or namespace name ‘ServerInfo’ does not exist in the
namespace ‘SharedConstants’

I found a turnaround to this problem referencing this class using UnnamedGameServer.SharedConstants instead of SharedConstants and using UnnamedGameServer; on the top of the .cs file. But I prefer avoiding referencing it on every line I use that class.

Here are some screenshots of my code:

First screenshot:

Bug in Visual Studio

Second screenshot:

Bug in Visual Studio

Edit: Screenshot of using statement:

Bug in Visual Studio

Edit 2: Code without screenshots:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Collections;
using ProtoBuf;
using UnnamedGameServer;
using System.Threading;

namespace Unnamed_game
{
    class Connection
    {
        public struct UserInformation
        {
            public string Username;
            public int UserID;
        }

        static private Connection instance;

        private Connection()
        {
            client = new TcpClient();
            header = new PacketHeader();
            _isLoggedCharacter = false;
            _isLoggedUser = false;
            magicByte = UnnamedGameServer.SharedConstants.ServerInfo.MagicByte;
        }

        // properties
        TcpClient client;
        PacketHeader header;
        Thread serverCommThread;
        byte[] magicByte;
        bool _isLoggedCharacter;
        CharacterInformation chInformation
        {
            get
            {
                return Player.Instance().Information;
            }
        }
        bool _isLoggedUser;
        public UserInformation Information;

        // methods
        static public Connection Instance()
        {
            if(instance == null)
            {
                instance = new Connection();
                return instance;
            }
            else
            {
                return instance;
            }
        }
        /// <summary>
        /// Should never be used. Use the parameterless one to get the server address and information. It doesn't use try-catch, the exception handling should be done on Game1.Initialize()
        /// </summary>
        public void ConnectServer(IPEndPoint endPoint)
        {
            if (client.Connected)
            {
                return;
            }
            else
            {
                client.Connect(endPoint);
                serverCommThread = new Thread(HandleServerCommunication);
                serverCommThread.Start();
            }
        }
        public void ConnectServer()
        {
            this.ConnectServer(new IPEndPoint(UnnamedGameServer.SharedConstants.ServerInfo.ServerAddress, UnnamedGameServer.SharedConstants.ServerInfo.Port));
        }
        private void HandleServerCommunication()
        {
            if (client == null)
            {
                throw new Exception("The TcpClient is null");
            }
            else
            {
                // this doesn't work
                byte[] magicByte = SharedConstants.ServerInfo.MagicByte;
                // this works
                magicByte = UnnamedGameServer.SharedConstants.ServerInfo.MagicByte;
            }
        }
        private void SendPacket(ActionType actionType, object packetStruct)
        {
            try
            {
                header.ActionTypeNumber = (short)actionType;
                using (NetworkStream stream = client.GetStream())
                {
                    stream.Write(magicByte, 0, magicByte.Length);
                    Serializer.SerializeWithLengthPrefix<PacketHeader>(stream, header, PrefixStyle.Base128);
                    switch (actionType)
                    {
                        case ActionType.Connect:
                            Serializer.SerializeWithLengthPrefix<PacketConnect>(stream, (PacketConnect)packetStruct, PrefixStyle.Base128);
                            break;
                    }
                    stream.Write(magicByte, 0, magicByte.Length);
                }
            }
            catch (Exception)
            {
                // error
                return;
            }
        }
        public void CreateNewCharacter(string characterName, CharacterClass chClass, CharacterRace chRace)
        {
            var info = new NewCharacterInfo();
            info.Name = characterName;
            info.OwnerUsername = Information.Username;
            info.Class = chClass;
            info.Race = chRace;
            CreateNewCharacter(info);
        }
        public void CreateNewCharacter(NewCharacterInfo info)
        {
            var packet = new PacketCreateNewCharacter();
            packet.chInfo = info;
            SendPacket(ActionType.CreateNewCharacter, packet);
        }
        public void ConnectUser(string username, string unhashedPassword)
        {
            var packet = new PacketConnect();
            packet.Username = username;
            packet.UnhashedPassword = unhashedPassword;
            ConnectUser(packet);
        }
        public void ConnectUser(PacketConnect packet)
        {
            if (_isLoggedCharacter || _isLoggedUser)
            {
                return;
            }
            else
            {
                SendPacket(ActionType.Connect, packet);
            }
        }
        public void ConnectCharacter(string characterName, short serverID)
        {
            var packet = new PacketLoginCharacter();
            packet.CharacterName = characterName;
            packet.ServerID = serverID;
            ConnectCharacter(packet);
        }
        public void ConnectCharacter(PacketLoginCharacter packet)
        {
            if (_isLoggedCharacter || !_isLoggedUser)
            {
                return;
            }
            else
            {
                SendPacket(ActionType.LoginCharacter, packet);
            }
        }
        public void Disconnect(PacketDisconnect packet)
        {
            if (!_isLoggedUser)
            {
                return;
            }
            else
            {
                SendPacket(ActionType.Disconnect, packet);
            }
        }
    }
}

edit 3:: Code where SharedConstants is stored.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;

namespace UnnamedGameServer
{
    /// <summary>
    /// ALL CONSTANTS THAT ARE SHARED BY THE CLIENT AND THE SERVER ARE STORED HERE. DONT ADD MORE CLASSES THAT STORE CONSTANTS. Use GameConstants for game-only constants.
    /// </summary>
    public static class SharedConstants
    {
        /// <summary>
        /// Server information with port, IP and MagicByte
        /// </summary>
        public static class ServerInfo
        {
            public const short Port = 6483;
            public static readonly IPAddress ServerAddress = IPAddress.Loopback;
            public static byte[] MagicByte
            {
                get
                {
                    return new byte[4] { 0xF1, 0x64, 0x83, 0xC4 };
                }
            }
        }
        /// <summary>
        /// Character constants shared by client/server
        /// </summary>
        public static class CharacterConstants
        {
            public static class Movement
            {
                /// <summary>
                /// Coordinates per update
                /// </summary>
                public const float DefaultCoordinatePerUpdate = 8;
                public const float ModifierNormal = 1f;
                public const float ModifierFrozen = 0.8f;
                public const float ModifierSpeedBuff = 1.2f;
                public const float ModifierStop = 0f;
            }
        }
        /// <summary>
        /// Networking constants
        /// </summary>
        public static class Networking
        {
            public const int MilisecondsPerMovementUpdate = 100;
            public const ushort ActionTypeNonMetaActionStart = 0x0FFF + 1;
            /// <summary>
            /// What is the number of actions a non-logged user can perform
            /// </summary>
            public const ushort ActionTypeNonLoggedUser = 0x000F;
        }
    }

    enum CharacterDirection
    {
        NoMovement = 0x00,
        Top = 0x01,
        TopRight = 0x02,
        TopLeft = 0x03,
        Right = 0x04,
        BottomRight = 0x05,
        Bottom = 0x06,
        BottomLeft = 0x07,
        Left = 0x08
    }
    enum CharacterStatus
    {
        Alive = 0x01,
        Dead = 0x02
    }
    enum CharacterClass
    {
        Mage = 0x01,
        Knight = 0x02
    }
    enum CharacterRace
    {
        Human = 0x01
    }
    enum CharacterType
    {
        Player = 0x01,
        GameMaster = 0x02
    }
    enum CharacterFaction
    {
        Newbie = 0x01,
        Army = 0x02,
        Chaos = 0x03
    }
    enum CharacterMovementStatus
    {
        Normal = 0x01,
        Frozen = 0x02,
        SpeedBuff = 0x03,
        Stop = 0x04
    }
    struct CharacterExperience
    {
        public CharacterExperience(short level, int experience)
        {
            Level = level;
            Experience = experience;
        }

        public short Level;
        public int Experience;
    }
}
  • 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-07T11:38:35+00:00Added an answer on June 7, 2026 at 11:38 am

    Having a using statement should work. If there is any code before the using statements then this may cause a problem.

    you could try putting the using statement after the namespace e.g:

    namespace Unnamed_game
    {
        using UnamedGameServer;
        class Connection
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really weird problem with fgets() in C. Below is the code
IDE = VS7 or 2002 Hi all, I have a really weird problem here.
I've been having a really weird problem. I have a mutable array that is
I'm battling a really weird problem here. I have a Windows 2008 R2 server
I have a very weird problem.. I really do hope someone has an answer
I have really weird problem with colors in interface builder. I set a color
ive got a really weird problem. i have no clue why its not working.
I have a really weird problem with a UIWebView. I'm using it to login
I have a very weird problem with resx based localization. At first, let me
I have this really weird problem with my MySQL table. After some time a

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.