I have a class that implements singleton pattern as you can see below:
public class SearchSingletonObject
{
private static SearchSingletonObject foundation = null;
public SearchObject Object= null;
private static StringCollection views = null;
private static object control = new object();
public IEnumerable<string> blacklist = null;
public static void ClearFoundation()
{
foundation = null;
}
public static SearchSingletonObject Foundation
{
get
{
if (foundation == null)
{
lock (control)
{
if (foundation == null)
{
foundation = new SearchSingletonObject();
var blacks = File.ReadAllText(HostingEnvironment.ApplicationPhysicalPath + "\\blacklist.txt");
foundation.blacklist = blacks.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Where(x => !string.IsNullOrEmpty(x) || x != " ");
views = new StringCollection();
var items = ConfigurationManager.AppSettings["SearchView"].Split(',');
foreach (var item in items)
{
views.Add(item);
}
foundation.Object = new SearchObject(ConfigurationManager.AppSettings["ContentDistributor"],
ConfigurationManager.AppSettings["Port"],
views);
}
}
}
return foundation;
}
}
public SearchSingletonObject()
{
}
}
We're using this class in our wcf rest services. But in non-periodic intervals we get "Value can not be null" errors. Here is my log file:
08.03.2011 11:40:39 ERROR Message : Value cannot be null.
Parameter name: source
StackTrace : at System.Linq.Enumerable.Where[TSource](IEnumerable`1 source, Func`2 predicate)
at Search.Service.SearchService.Search(String keyword, Int32 offset, Int32 hit, String navstate, String username, Boolean issecure, Int32 suggest, String sortref, String fields, Int32 IsFirstSearch, String misspelled, String category) in D:\tfs\Hey\HeyRestApi\HeyService\HeyService.cs:line 68
Log file mentions the row below in my service:
var blacks = SearchSingletonObject.Foundation.blacklist.Where<string>(x => item.Equals(x)).FirstOrDefault();
It seems strangely the "blacklist" object getting null value. After the error, we have to reset IIS, to get application working. We can not reproduce the error on our local servers. It just happens in our customers production environment.
How can we solve that problem and what can be the reason of this strange error?
Thanks in advance,