Home Forums Support KeyNotFoundException

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1330
    Anonymous
    Inactive

    Hello all,

    ok, so i’ve been working with networkcomms for a while now, and everything is working except my newest addition.
    I’ve searched since Monday, and i really don’t know what i could do else to fix this.
    I have a Windows service that talks to a gui; when you start the gui, it will setup the encrypted communication
    and do a echo-test to verify the connection is working as expected. Right after this echo test, the server pushes its entire
    configuration (custom classes using protobuf) to the client, which works pretty fine.
    Now i tried to add another small class which looks like this:

    
    
    [ProtoContract]
    public class clsServerLicInfo
    {
    	[ProtoMember(1)]
    	public bool IsRegistered { get; private set; }
    
    	[ProtoMember(2)]
    	public string LicenseStatusMessage { get; private set; }
    
    	[ProtoMember(3)]
    	public string MachineID { get; private set; }
    	
    	[ProtoMember(4)]
    	public string LicenseExceptionString { get; private set; }
    
    	private clsServerLicInfo() { }
    
    	public clsServerLicInfo(bool nIsRegistered, string nLicenseStatusMessage, string nMachineID, string nLicenseExceptionString)
    	{
    		IsRegistered = nIsRegistered;
    		LicenseStatusMessage = nLicenseStatusMessage;
    		MachineID = nMachineID;
    		LicenseExceptionString = nLicenseExceptionString;
    	}
    }
    
    

    Serverside, the code to send this information looks like this:

    
    // nMessage is not used here at all
    NetworkComms.PacketHandlerCallBackDelegate<string> GetServerLicStatus = (packetHeader, connection, nMessage) =>
    {
    	clsServerLicInfo tObject = new clsServerLicInfo(false, "test", "test", "test");
    	connection.SendObject("rcv_licstat", tObject);
    };
    NetworkComms.AppendGlobalIncomingPacketHandler("get_licstat", GetServerLicStatus);
    

    Clientside:

    
    NetworkComms.PacketHandlerCallBackDelegate<clsServerLicInfo> Receive_ServerLicStatus = (packetHeader, connection, licData) =>
    {
       NetworkComms.Logger.Info(String.Format("[GuiCom] Got lic 
    };
    NetworkComms.AppendGlobalIncomingPacketHandler("rcv_licstat", Receive_ServerLicStatus);
    
    

    There is nothing else i added. Now when i try to run the application, everything still works fine, except for this license thing.
    I dont even get to the try…catch block, it breaks right after receiving the reply packet from the server with
    the following exception:

     (PacketHandlerErrorGlobal_rcv_licstat 7.40.47.859 19-12-2013 [6904-0].txt)
    Base Exception Type: System.Collections.Generic.KeyNotFoundException: Der angegebene Schlüssel war nicht im Wörterbuch angegeben.
       bei System.Collections.Generic.Dictionary'2.get_Item(TKey key)
       bei DPSBase.RijndaelPSKEncrypter.ReverseProcessDataStream(Stream inStream, Stream outStream, Dictionary'2 options, Int64& writtenBytes) in E:\MarcF-networkcomms.net-765edb1ac398\DPSBase\RijndaelPSKEncrypter.cs:Zeile 61.
       bei DPSBase.DataSerializer.DeserialiseGeneralObject[T](MemoryStream receivedObjectStream, List'1 dataProcessors, Dictionary'2 options) in E:\MarcF-networkcomms.net-765edb1ac398\DPSBase\DataSerializer.cs:Zeile 247.
       bei DPSBase.DataSerializer.DeserialiseDataObject[T](MemoryStream receivedObjectStream, List'1 dataProcessors, Dictionary'2 options) in E:\MarcF-networkcomms.net-765edb1ac398\DPSBase\DataSerializer.cs:Zeile 228.
       bei NetworkCommsDotNet.PacketTypeHandlerDelegateWrapper'1.DeSerialize(MemoryStream incomingBytes, SendReceiveOptions options) in E:\MarcF-networkcomms.net-765edb1ac398\NetworkCommsDotNet\Tools\PacketUnwrappers.cs:Zeile 72.
       bei NetworkCommsDotNet.NetworkComms.TriggerGlobalPacketHandlers(PacketHeader packetHeader, Connection connection, MemoryStream incomingDataStream, SendReceiveOptions options, Boolean ignoreUnknownPacketTypeOverride) in E:\MarcF-networkcomms.net-765edb1ac398\NetworkCommsDotNet\NetworkComms.cs:Zeile 902.
    
    Stack Trace:    bei System.Collections.Generic.Dictionary'2.get_Item(TKey key)
       bei DPSBase.RijndaelPSKEncrypter.ReverseProcessDataStream(Stream inStream, Stream outStream, Dictionary'2 options, Int64& writtenBytes) in E:\MarcF-networkcomms.net-765edb1ac398\DPSBase\RijndaelPSKEncrypter.cs:Zeile 61.
       bei DPSBase.DataSerializer.DeserialiseGeneralObject[T](MemoryStream receivedObjectStream, List'1 dataProcessors, Dictionary'2 options) in E:\MarcF-networkcomms.net-765edb1ac398\DPSBase\DataSerializer.cs:Zeile 247.
       bei DPSBase.DataSerializer.DeserialiseDataObject[T](MemoryStream receivedObjectStream, List'1 dataProcessors, Dictionary'2 options) in E:\MarcF-networkcomms.net-765edb1ac398\DPSBase\DataSerializer.cs:Zeile 228.
       bei NetworkCommsDotNet.PacketTypeHandlerDelegateWrapper'1.DeSerialize(MemoryStream incomingBytes, SendReceiveOptions options) in E:\MarcF-networkcomms.net-765edb1ac398\NetworkCommsDotNet\Tools\PacketUnwrappers.cs:Zeile 72.
       bei NetworkCommsDotNet.NetworkComms.TriggerGlobalPacketHandlers(PacketHeader packetHeader, Connection connection, MemoryStream incomingDataStream, SendReceiveOptions options, Boolean ignoreUnknownPacketTypeOverride) in E:\MarcF-networkcomms.net-765edb1ac398\NetworkCommsDotNet\NetworkComms.cs:Zeile 902.
    

    in the logfile it says:

    
    12:12:55 [Debug] - Received packet of type 'getlicstat_r' from [TCP] 127.0.0.1:10315 -> 127.0.0.1:5678 (5-TQw9KkA0-Dzl6HyKKf8g), containing 46 header bytes and 192 payload bytes.
    12:12:55 [Trace] -  ... added completed packet item to IncomingPacketQueue with priority Normal. Loop index - 0
    12:12:55 [Trace] - Removing 238 bytes from incoming packet buffer.
    12:12:55 [Trace] - Pulled packet item with packetType='getlicstat_r' from IncomingPacketQueue which was added with a priority of 2
    12:12:55 [Trace] - Triggering handlers for packet of type 'getlicstat_r' from [TCP] 127.0.0.1:10315 -> 127.0.0.1:5678 (5-TQw9KkA0-Dzl6HyKKf8g)
    12:12:55 [Fatal] - An exception occured in TriggerPacketHandler() for a packet type 'getlicstat_r'. See error log file for more information.
    12:12:55 [Fatal] - PacketHandlerErrorGlobal_getlicstat_r
    

    I think this is something related to protobuf and networkcomms, but i’m not sure.
    Hopefully anyone can help me here.

    Regards,
    Namikon

    #1332
    Anonymous
    Inactive

    The exception seems to be being thrown by the decryption step so I don’t think this is protobuf related at least. The only place I can think that a KeyNotFoundException could be thrown, is if the symmetric pre-shared password was not in the options Dictionary at the point the exception is thrown. This is a bit odd though as it should throw an ArgumentException in that case as we catch it specifically.

    Are you using the latest version of NetworkComms available from the downloads page or something older? This would potentially explain the different exception.

    How are you adding the pre-shared secret? I assume you are adding it to the global send receive options (on the receiving end as well as the sending end) as you don’t specify it when adding the handler?

    One final request to confirm that this is not due to serialization in some strange way; if you replace your clsServerLicInfo object in the send/receive as you have it above with something simple like a string is the exception still thrown?

    Hopefully we can get to the bottom of this quickly and find a solution for you. If it is confirmed as a bug it should be easy enough to fix based on where the exception is.

    Regards,

    Matt

    #1334
    Anonymous
    Inactive

    Wow, that was easy 😛

    The only place I can think that a KeyNotFoundException could be thrown, is if the symmetric pre-shared password was not in the options Dictionary at the point the exception is thrown

    That helped me:
    I have a general “Startup” function to initialize all Handlers and such

    
    private void SetDelegates()
    {
      SetDelegates_Generic();
      SetDelegates_Basic();
      SetDelegates_*...
    ...
    }
    

    So i added connect/disconnect handlers (and my license-handler…) to “SetDelegates_Generic()”. The encryption stuff is called / set in “SetDelegates_Basic()”, so after the handler is registered.

    I moved my function to “SetDelegates_Basic()” and it works as expected. Thanks a lot!

    -Namikon

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.