NullReferenceException was unhandled

02/02/2020 03:19 blacbullet#1
Hello Elitepvpers!
Currently trying to play around with the source CoEmuv2
I tried googling the problem and although I found another person with this issue it didn't appear to be answered?
I followed the guides, and used appserv to install mysql.
ips all set to 127.0.0.1
I get this error on line 23 in database.cs
NullReferenceException was unhandled
Object reference not set to an instance of an object.
Code:
if(Connection.State == ConnectionState.Open)
inside of the login server window it has:
Code:
---CoEmu v2 LoginServer - Starting up!---
This program is a branch
[LoginServer-Init] Starting MasterSocket Thread.
[LoginServer] Init OK.
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at MySql.Data.MySqlClient.CharSetMap.GetChararcterSet(DBVersion version, String CharSetName)
   at MySql.Data.MySqlClient.CharSetMap.GetEncoding(DBVersion version, String CharSetName)
   at MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection)
   at MySql.Data.MySqlClient.NativeDriver.Configure(MySqlConnection conn)
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at CoEmu_v2_LoginServer.Database.DatabaseConnection.NewConnection() in C:\Users\drako\OneDrive\Desktop\CoEmu v2\CoEmu v2 LoginServer\Database\DatabaseConnection.cs:line 30
Any ideas? :handsdown:
02/02/2020 03:30 Spirited#2
Looks like the MySQL connection couldn't be opened. Likely a configuration issue.
Post your configuration and what steps you did to set up the server.
Also, try debugging the server for any hints: [Only registered and activated users can see links. Click Here To Register...]
02/02/2020 04:40 blacbullet#3
Hi Spirited,

I followed this guide exactly for the set up.
[Only registered and activated users can see links. Click Here To Register...]

I'm using visual studio c# 2008 Express edition
I tried debugging using this which is how i got the subject error.

by configuration do you mean this?(from loginserver section)
database connection.cs :
Code:
/*
 * Created by SharpDevelop.
 * User: sams
 * Date: 3/8/2009
 * Time: 1:13 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using MySql.Data.MySqlClient;

namespace CoEmu_v2_LoginServer.Database
{
	/// <summary>
	/// Provides MySql resource connections, for multiple connections to a single MySql database.
	/// This is due to the fact that the server is multi-threaded, so allowing a single connection would
	/// likely result in errors, or general loss of performance.
	/// </summary>
	public static class DatabaseConnection
	{
		public const string USER_NAME = "root";
		public const string PASSWORD = "drakonic";
		public const string SERVER = "127.0.0.1";
		public const string DATA_BASE = "conqueremu";
		public static MySqlConnection NewConnection()
		{
			MySqlConnection C = null;
			try{
			C = new MySqlConnection("Server=" + SERVER + ";Database='" + DATA_BASE + "';Username='" + USER_NAME + "';Password='" + PASSWORD + "'");
			C.Open();
			}
			catch(Exception e)
			{
				Console.WriteLine(e.ToString());
				return null;
			}
			return C;
		}
	}
}
Also i'm able to successfully log into navicat, and phpmyadmin using the user and password provided.
02/04/2020 03:11 donaistheboss#4
Quote:
Originally Posted by blacbullet View Post
Hello Elitepvpers!
Currently trying to play around with the source CoEmuv2
I tried googling the problem and although I found another person with this issue it didn't appear to be answered?
I followed the guides, and used appserv to install mysql.
ips all set to 127.0.0.1
I get this error on line 23 in database.cs
NullReferenceException was unhandled
Object reference not set to an instance of an object.
Code:
if(Connection.State == ConnectionState.Open)
inside of the login server window it has:
Code:
---CoEmu v2 LoginServer - Starting up!---
This program is a branch
[LoginServer-Init] Starting MasterSocket Thread.
[LoginServer] Init OK.
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at MySql.Data.MySqlClient.CharSetMap.GetChararcterSet(DBVersion version, String CharSetName)
   at MySql.Data.MySqlClient.CharSetMap.GetEncoding(DBVersion version, String CharSetName)
   at MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection)
   at MySql.Data.MySqlClient.NativeDriver.Configure(MySqlConnection conn)
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at CoEmu_v2_LoginServer.Database.DatabaseConnection.NewConnection() in C:\Users\drako\OneDrive\Desktop\Fresh Conquer\CoEmu v2\CoEmu v2 LoginServer\Database\DatabaseConnection.cs:line 30
Any ideas? :handsdown:


put key inside database mysql and its will be fixed
02/05/2020 23:06 blacbullet#5
Quote:
Originally Posted by donaistheboss View Post
put key inside database mysql and its will be fixed
hmm, I appreciate the response, but I don't know what your saying exactly.. Sorry i'm very much a noob at programming.(Just started learning c#)
What is the key or where would I locate it?
What do you mean by database mysql? As in the information I would see inside of navicat or phpmyadmin?
02/05/2020 23:15 Spirited#6
Quote:
Originally Posted by blacbullet View Post
hmm, I appreciate the response, but I don't know what your saying exactly.. Sorry i'm very much a noob at programming.(Just started learning c#)
What is the key or where would I locate it?
What do you mean by database mysql? As in the information I would see inside of navicat or phpmyadmin?
I don't know what he's talking about most of the time either, so don't sweat it. Yeah, MySQL is your relational database provider. Aka. the tables of data you see in Navicat or MySQL Workbench (a free alternative). Regarding your issue, I'd follow the steps again and see if you accidentally skipped over something. Don't forget to compile your code in Visual Studio (you can use 2019 of you'd like).
02/06/2020 03:50 blacbullet#7
Ok, so I updated to 2019, re-downloaded the source and tried those steps again. It does mention that the gameserver won't work on a 64 bit windows. Something to do with 'libeay32.dll'

Probably unrelated since my problem is with the loginserver..

Maybe I should go with a different source? Mainly wanting to use a source before ninja were added, +12 max gears, 2 reborn. I also downloaded your source(Comet) for a reference but I also would like to have a more complete one as-well.
Any recommendations?
02/06/2020 04:02 Spirited#8
Quote:
Originally Posted by blacbullet View Post
Ok, so I updated to 2019, re-downloaded the source and tried those steps again. It does mention that the gameserver won't work on a 64 bit windows. Something to do with 'libeay32.dll'

Probably unrelated since my problem is with the loginserver..

Maybe I should go with a different source? Mainly wanting to use a source before ninja were added, +12 max gears, 2 reborn. I also downloaded your source(Comet) for a reference but I also would like to have a more complete one as-well.
Any recommendations?
There's a fix for that:

[Only registered and activated users can see links. Click Here To Register...]
02/06/2020 05:00 blacbullet#9
Quote:
Originally Posted by Spirited View Post
There's a fix for that:

[Only registered and activated users can see links. Click Here To Register...]
Hmm, I downloaded the OpenSSL binaries and source, but I don't see the dll?


So could I be getting the subject error because of 64 bit windows? Or is there something else going on here?
I've redone the steps probably 4 times or so, reinstalled appserv twice.
I'm confused that no one else is having this issue?
02/06/2020 05:13 Spirited#10
Quote:
Originally Posted by blacbullet View Post
Hmm, I downloaded the OpenSSL binaries and source, but I don't see the dll?


So could I be getting the subject error because of 64 bit windows? Or is there something else going on here?
I've redone the steps probably 4 times or so, reinstalled appserv twice.
I'm confused that no one else is having this issue?
If you downloaded the binaries, you should see libeay32.dll included. When CoEmu was popular, Windows XP 32-bit was also still popular. With OpenSSL, you need to use the dll that's made for your architecture. That's why the one included with CoEmu doesn't work with 64-bit systems. Shockingly, a lot of people here are still using Windows XP (terrifying).

Appserv is also very old and shouldn't be installed at this point. MySQL Community Edition is a good replacement. Just make sure you set the password type to legacy when installing it. Maybe I'll make some updated tutorials for setting up old server sources like that.
02/06/2020 05:46 blacbullet#11
Quote:
Originally Posted by Spirited View Post
If you downloaded the binaries, you should see libeay32.dll included.
I had downloaded the 64 bit version, However I just checked and saw the dll in the 32 bit version!

Quote:
Originally Posted by Spirited View Post
Appserv is also very old and shouldn't be installed at this point. MySQL Community Edition is a good replacement. Just make sure you set the password type to legacy when installing it. Maybe I'll make some updated tutorials for setting up old server sources like that.

Ok,
I now have Mysql Community installed.
No luck with subject yet.
02/07/2020 17:36 .Guru#12
[Only registered and activated users can see links. Click Here To Register...]
02/08/2020 17:40 blacbullet#13
Ok here's all the code that seem to be involved?

Code:
---CoEmu v2 LoginServer - Starting up!---
This program is a branch
[LoginServer-Init] Starting MasterSocket Thread.
[LoginServer] Init OK.
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at MySql.Data.MySqlClient.CharSetMap.GetChararcterSet(DBVersion version, String CharSetName)
   at MySql.Data.MySqlClient.CharSetMap.GetEncoding(DBVersion version, String CharSetName)
   at MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection)
   at MySql.Data.MySqlClient.NativeDriver.Configure(MySqlConnection conn)
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at CoEmu_v2_LoginServer.Database.DatabaseConnection.NewConnection() in C:\Users\drako\OneDrive\Desktop\CoEmu v2\CoEmu v2 LoginServer\Database\DatabaseConnection.cs:line 30

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at CoEmu_v2_LoginServer.Database.Database.TestConnect() in C:\Users\drako\OneDrive\Desktop\CoEmu v2\CoEmu v2 LoginServer\Database\Database.cs:line 23
   at CoEmu_v2_LoginServer.Program.Main(String[] args) in C:\Users\drako\OneDrive\Desktop\CoEmu v2\CoEmu v2 LoginServer\Main.cs:line 26
LoginServer :
DatabaseConnections.cs:

database.cs:

Main.cs:
04/22/2020 22:12 Cmcada#14
So this may be a bit late.

I've just started playing with the CoEmu source and the issue your are seeing is in principle,
- The MySql query formed to your database was not handled correctly by the source or the database connection server
- Your DB genuinely does not contain the correct schema for your query! (e.g. USE `conqueremu` SELECT * from `monsters`, DB conquer emu schema is missing the monsters table )

I've never written C# before or have any experience with MySql, but it only took me about 20 minutes of research to figure this out, just be persistent and you'll get there.

Theres a number of options here:

1) Your database genuinely does not have the key (check your MySql schema against the query being sent by the reader, (SELECT * from `characters`) or similiar looking at your exception. - If you have used the DB backup included with the source, this will be fine, just make sure your DB is setup correctly, Not sure what connection your using, Oracles MySql 8.0 offering is pretty intuitive, I reccomend it (as Spirited also has)

2) The source was built using mysql.data v6.0.0, this is the handler that implements the MySql C# functionality, this version is not compatible with the latest MySql offerrings, at least with MySql 8.0, you need to update this reference to use an up to date MySql connector, I reccomend v8.0.19.0, just do a spot of googling, the dll is supplied by the MySql connector .net offering (mysql-connector-net-8.0.19), just replace the .dll in the source with an up-to-date version and up-rev your Visual studio references (You will also need to re-target the source for the latest framework verison due to co-dependencies....4.7.2 I recommend, its fully compatible with the source as written.)

3) The DB included in the source has been configured in a legacy fashion, you need to make some changes to your connection options.

i) Connection charset should be explicitly set, this is just good practice, original DB using CharSet Latin1, so add "CharSet=latin1" to the connector options - Ommitting this field leaves the connection manager open to interpret the request at is own volition, it may be absolutely fine, but may hide some oddities if theres some malformed data in the DB.

ii) GUID format in the supplied DB uses a legacy format, either build a whole new DB from scratch or specify option "OldGuids=True"

e.g.

Code:
C = new MySqlConnection("Server=" + SERVER + ";Port=" + PORT + ";Database='" + DATA_BASE + "';Username='" + USER_NAME + "';Password='" + PASSWORD + "'" + ";CharSet=latin1" + ";OldGuids=True");
Tip: If you use MySql Workbench 8.0, which looks like you have already installed, if you use the administrator options 'ClientConnections' when the Account Server or Game Server runs a query, you will see the event in the log, you can check the details of the connection request and debug that way, can give you some insight into whats gone wrong.
04/23/2020 16:39 Super Aids#15
The best thing in this thread is this:

Quote:
I'm using visual studio c# 2008 Express edition
LMAO, we're in 2020. Get Visual Studio 2019, it's free anyway for the community edition.