We have moved to GitHub Issues
Created by Maarten van der Donk 19 Aug 2013, 07:26:17 Updated by Mark Bowser 24 Feb 2015, 01:14:08
After creating a root dictionary item in Umbraco the method GetRootDictionaryItems throws the following exception: Sequence contains no elements This also happens when trying to get the child dictionary items by calling the method: GetDictionaryItemChildren
From what I've found there are two things going wrong, first: Umbraco is creating dictionary translations in the cmsLanguageText table where languageId = 0. I'm not sure if this is intended or a bug but this is happening since (at least) version 4.7.1 up to 6.1.4.
The second thing, which is what causes the exception, is the PerformGet(int id) method in LanguageRepository.cs. There is a line with the following code:
var languageDto = Database.First
I've tried removing the translations with languageId = 0. This prevented the exception but gave me a bunch of other problems like dictionary items showing up on my dashboard (using LocalizationService) but they where nowhere to be found on the default Umbraco dictionary view (in the Settings section). Also, some dictionary items had duplicates in the database (different Guid but the same dictionaryKey).
Changing the Umbraco source to use FirstOrDefault instead of First seems to fix a lot of this issue. Getting dictionary items with the LocalizationService works but when I try to update a dictionary item (LocalizationService.Save(IDictionaryItem dictionaryItem, int userId = 0)) I get the following exception: Object reference not set to an instance of an object At: DictionaryItemFactory.cs line 39: var text = new LanguageTextDto ; translation.Language is null so that's what causing the exception.
Note: This is only happening to us when we try to get a dictionary item on the front end of a site while also logged into the backoffice. This is causing all methods of get language to fail (umbraco.library.GetDictionaryItem, UmbracoHelper.GetDictionaryValue and LocalizationService Get Dictionary item)
Related discussion on Our: http://our.umbraco.org/forum/developers/api-questions/38029-V6-LocalizationServiceGetDictionaryItemByKey
hi - Has this not been scheduled for a 6.1.x/6.2 patch yet? Basically, dictionary won't work in 6 without this fix, correct?
The following bit is fixed in next patch version of v6, and verified as fixed in v7 as well.
var languageDto = Database.FirstOrDefault<LanguageDto>(sql); if (languageDto == null) return null;
I could not find any issues in using LocalizationService.Save, so if you believe any issues still exists here then please post some code to recreate the issue. I've written a bunch of test cases for the LocalizationService, which can be seen here: https://github.com/umbraco/Umbraco-CMS/blob/7.1.5/src/Umbraco.Tests/Services/LocalizationServiceTests.cs
Assignee: Morten Christensen
Backwards Compatible: True
Affected versions: 6.0.4, 6.1.4, 6.1.5, 6.1.6
Due in version: 6.2.2