Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 02:44

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement
Bitcoin Dice Game


NullReferenceException was unhandled

Discussion on NullReferenceException was unhandled within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jan 2009
Posts: 8
Received Thanks: 0
Question NullReferenceException was unhandled

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?



blacbullet is offline  
Old 02/02/2020, 03:30   #2
 
elite*gold: 12
Join Date: Jul 2011
Posts: 7,699
Received Thanks: 3,805
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: https://docs.microsoft.com/en-us/vis...r?view=vs-2019


Spirited is offline  
Old 02/02/2020, 04:40   #3
 
elite*gold: 0
Join Date: Jan 2009
Posts: 8
Received Thanks: 0
Hi Spirited,

I followed this guide exactly for the set up.


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.
blacbullet is offline  
Old 02/04/2020, 03:11   #4
 
elite*gold: 0
Join Date: Jan 2014
Posts: 96
Received Thanks: 1
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?


put key inside database mysql and its will be fixed


donaistheboss is offline  
Old 02/05/2020, 23:06   #5
 
elite*gold: 0
Join Date: Jan 2009
Posts: 8
Received Thanks: 0
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?
blacbullet is offline  
Old 02/05/2020, 23:15   #6
 
elite*gold: 12
Join Date: Jul 2011
Posts: 7,699
Received Thanks: 3,805
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).
Spirited is offline  
Thanks
1 User
Old 02/06/2020, 03:50   #7
 
elite*gold: 0
Join Date: Jan 2009
Posts: 8
Received Thanks: 0
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?
blacbullet is offline  
Old 02/06/2020, 04:02   #8
 
elite*gold: 12
Join Date: Jul 2011
Posts: 7,699
Received Thanks: 3,805
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:

Spirited is offline  
Old 02/06/2020, 05:00   #9
 
elite*gold: 0
Join Date: Jan 2009
Posts: 8
Received Thanks: 0
Quote:
Originally Posted by Spirited View Post
There's a fix for that:

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?
blacbullet is offline  
Old 02/06/2020, 05:13   #10
 
elite*gold: 12
Join Date: Jul 2011
Posts: 7,699
Received Thanks: 3,805
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.
Spirited is offline  
Thanks
1 User
Old 02/06/2020, 05:46   #11
 
elite*gold: 0
Join Date: Jan 2009
Posts: 8
Received Thanks: 0
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.
blacbullet is offline  
Old 02/07/2020, 17:36   #12
 
elite*gold: 0
Join Date: Aug 2009
Posts: 930
Received Thanks: 448
.Guru is offline  
Thanks
1 User
Old 02/08/2020, 17:40   #13
 
elite*gold: 0
Join Date: Jan 2009
Posts: 8
Received Thanks: 0
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:
blacbullet is offline  
Old 04/22/2020, 22:12   #14
 
elite*gold: 0
Join Date: Apr 2007
Posts: 52
Received Thanks: 1
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.
Cmcada is offline  
Old 04/23/2020, 16:39   #15
 
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 940
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.


Super Aids is offline  
Thanks
1 User
Reply



« MySQL error | Google tells me to define except.... »

Similar Threads Similar Threads
NullReferenceException
03/21/2011 - CO2 Programming - 12 Replies
Alright, This Damn Exception annoys me as fuck , and I've got No Idea why. I Believe I'm missing something.. Can somebody remind me what is it? I know It's un-pro question but ermm... here we go. http://i989.photobucket.com/albums/af15/RockArch/ Untitled.png?t=1300203698
[Visual Basic 2010]System.NullReferenceException
02/13/2011 - .NET Languages - 3 Replies
Hallo Elitepvpers, ich hoffe ich bin hier am richtigen Platz, also ich hab einen Emulator versucht zuverbessern aber es kommt dieser Fehler: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
[VB 2008] "System.NullReferenceException wurde nicht behandelt"
12/30/2009 - .NET Languages - 9 Replies
Und der Fehler passiert in der Zeile: Sub _Anmelden() WebBrowser1.Document.GetElementById("user&qu ot;).InnerText = TextBox2.Text .......... .......... .......... .......... End Sub
[Help]NullReferenceException
11/23/2008 - CO2 Private Server - 3 Replies
Ok... Well first off, I feel like an idiot fot not knowing what to do here. But I'm completely lost, so if somene could point me in the right direction, I'd appreciate it. Seems this is completely random, sometimes it will occur after 30 minutes, sometimes the server can run for hours without an issue. But occasionally this kicks in, and everything freezes. The code effected is... if (Charr.MyClient.Online) if (MyMath.CanSee(Attacked.LocX,...



All times are GMT +2. The time now is 02:44.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

BTC: 33E6kMtxYa7dApCFzrS3Jb7U3NrVvo8nsK
ETH: 0xc6ec801B7563A4376751F33b0573308aDa611E05

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2020 elitepvpers All Rights Reserved.