Here the my code( Im new to DOT NET)

Im using some socket.connection with port 25.

private readonly byte[] _buffer = new byte[1024];
int structId = BitConverter.ToInt32(_buffer, 0);
Type currentStructType;
if (!Structs.TryGetValue(structId, out currentStructType))
              throw new BufferParserException(string.Format("Structure  with ID = {0} is not supported.", structId));

here Im getting structId= 540029490 always.
and aboue if condition also FALSE always.means its throwing ex.
I need to get it TRUE.

currentStruct = (IParserStruct)Activator.CreateInstance(currentStructType);

here getting currentStruct = null always.

structLength = BitConverter.ToInt32(_buffer, 4);
if (currentStruct == null || structLength == -1)
              throw new BufferParserException("Got to read the structure, but not created.");

Im not getting wts happening here, how to solve this problem.

Please guide me to solve it.

Hello.
Let's investigate your code:
1. You declare an array (for some reason readonly). And say, that it would contain 1024 elements.

private readonly byte[] _buffer = new byte[1024];

NOTE: The array is still empty
2. On the next step you're trying to convert your empty (well, not really empty: just each element initialized by "0" and you haven't assigned any value in that array) array to Integer, starting from 0 position.

int structId = BitConverter.ToInt32(_buffer, 0);

Since you're trying to convert "Nothing to something" - it ain't gonna work. And that's, probably the reason of this:

here Im getting structId= 540029490 always.

The next trouble ..

aboue if condition also FALSE always.means its throwing ex.

Since I don't know what is Structs and moreover the TryGetValue method in it - I can't say exactly. But can take a guess .. that it returns false because of bad input (structId).

And that's the chain reaction .. the bad structId causes troubles with currentStructType. The corrupted currentStructType causes troubles in currentStruct and so on.

So to solve your problem you should start from structId.

P.S. If you'll place your code in code tags next time - it would be much easier to investigate it .. and you'll get the answers much faster :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.