Questions tagged [keynotfoundexception]

For issues relating to the .NET KeyNotFoundException.

The KeyNotFoundException is an Exception of the .NET that is thrown when the key specified for accessing an element in a collection does not match any key in the collection.

KeyNotFoundException uses the HRESULT COR_E_KEYNOTFOUND, which has the value 0x80131577.

44 questions
2
votes
1 answer

KeyNotFound Exception when Key Present in Dictionary?

I have a very verbose dictionary that stores 350 keys, each of which is a byte array of 3 bytes. This dictionary is to interpret incoming data from home-brewed hardware. In stress-testing an application, I've hit a strange error where it is telling…
Will
  • 3,413
  • 7
  • 50
  • 107
2
votes
3 answers

KeyNotFound Exception in Dictionary(of T)

I'm about ready to bang my head against the wall I have a class called Map which has a dictionary called tiles. class Map { public Dictionary tiles = new Dictionary(); public Size mapSize; public Map(Size…
C Patton
  • 21
  • 1
2
votes
2 answers

KeyNotFound Exception when calling Html.ValidationSummary() dynamically through helper method

I have a Helper Method in my View which renders the whole form dynamically. Now i want to add a support for Client Validation as available in Asp.Net MVC RC 2. Following is the code i use to render Validation Summary field onto the…
Huzefa
  • 41
  • 4
2
votes
3 answers

Should I throw a KeyNotFoundException for a database lookup?

I've got some code that, given an ID, returns an item from the database. If no item matches the given ID, is it appropriate to throw a KeyNotFoundException, or are such exceptions meant only for Dictionary types?
yoozer8
  • 7,361
  • 7
  • 58
  • 93
2
votes
1 answer

invoking method with two same parameters returns two different results

I have a simple project, using MVC pattern, ET and WCF. It uses Dijkstra to find paths between cities. This is the class itself. However, when calling FindPathFromCityToCity() with two same lists in the map object, same from and to, when it's on a…
Nikola
  • 2,093
  • 3
  • 22
  • 43
2
votes
5 answers

Useless Exceptions (NullReferenceException, KeyNotFoundException)

I find the C# exceptions very annoying, because they provide so less information. What is the reason for this? NullReferenceException or KeyNotFoundExceptions are hard to debug and sometimes you don´t get a linenumber in the stacktrace. Why can the…
2
votes
2 answers

KeyNotFoundException in filled dictionary

I am trying to modify value in dictionary, but the compiler throws KeyNotFoundException. I'm sure, I declared that key in dictionary, because I am calling GenerateEmptyChunks() method, which fills dictionary with chunks with key of their position…
Matej Kormuth
  • 2,139
  • 3
  • 35
  • 52
1
vote
2 answers

Operations over dictionary-key without System.Collections.Generic.KeyNotFoundException

I have a simple dictionary call result: Dictionary results=new(); results["a"]="a"; results["b"]="b"; results["c"]="c"; To simplify the example my dictionary only contains 3 letter keys a,b,c. But sometimes it will not contain one of…
hesolar
  • 543
  • 4
  • 23
1
vote
1 answer

.Net dictionary doesn't fetch value directly after inserting on rare occasions

I have written following code snippet: public interface IModelToViewModelServiceBase where TDomain : class, IDataModel where TViewModel : class, IDataModelViewModel { TViewModel GetViewModel(TDomain…
Dima
  • 340
  • 3
  • 12
1
vote
3 answers

Getting KeyNotFoundException when using key previously retrieved from key collection?

I've got the following code where for some reason I'm getting a KeyNotFoundException even though I'm using a key that I had retrived a couple of lines above. Does anyone know of a situation where this wouldn't work? I'm stumped. BTW…
Martin MacPherson
  • 337
  • 1
  • 2
  • 10
1
vote
1 answer

KeyNotFoundException, but not when debugging

I've been building an extensions library, and I've utilised a great extension method found at http://www.extensionmethod.net for inclusion. In my unit test (using NUnit 1.5.2), I've come across an interesting issue. Firstly, lets look at the…
Matthew Abbott
  • 81
  • 1
  • 1
  • 5
0
votes
3 answers

How to unit test KeyNotFoundException without assigning dictionary value

I wish to run a unit test on a particular dictionary in my code, trying to get a value I don't expect to be in the database (in this case, key=1). I have written the following code: Try Dim s As String = myDict(1) Catch ex As…
Stephen Holt
  • 2,360
  • 4
  • 26
  • 34
0
votes
1 answer

Apache Ignite .Net : KeyNotFoundException occurs when using multi-PK

I use gridgain Ignite community 8.8.31(it is same at apache ignite 2.15), and I made two tables using DDL.(Insert data with DML) When I try to cache.get() using C#/.NET, Person3 has error but Person4 is runs well. These two tables are exactly same…
GH Lee
  • 3
  • 2
0
votes
0 answers

How to resolve KeyNotFoundException for MySql.Data.dll in .NET 2.0 with Maria10.6 version?

Currently, I am using both of .NET 2.0 and .NET 4.0 Framework websites. All Websites are using MySql.Data.dll 6.8.3 ver. I found the reason for 'KeyNotFoundException' from these references that indicate unsupported chatset is the…
CY96
  • 1
  • 1
0
votes
1 answer

Umbraco installation problem. Can not install starter kit. The key was not present in the dictionary

This is a problem I get when trying to install Umbraco. I know that Umbraco has its own forum, but they have just moved it to another url, and I can not seem to be able to post a question there. So I try here. I know this problem has been reported…