使用.NET 3.5 C#,我有一個WCF Web服務爲移動客戶端提供服務。客戶端經常使用該服務將數據發送到服務器並接收更新。該服務部署在IIS 7.5中,並且配置爲每天早晨0600回收。回收通常無暇的工作,客戶像往常一樣繼續使用該服務。但是,有一些事件導致應用程序進入有趣的狀態,並且我可以看到下面的日誌類型初始化錯誤。這幾乎是重疊循環的競爭,其中還沒有成功卸載DLL的過程中喜歡的事發生了:IIS回收事件後.NET類型初始化異常
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
at Docobo.Keswick.DbAccess.TableData.DataClasses.GetInfo(Type type)
的數據類是使用IQToolkit查找數據庫表名內部靜態類:
internal static class DataClasses
{
private static readonly Dictionary<Type, DataClassInfo> classInfos = new Dictionary<Type, DataClassInfo>();
public static DataClassInfo GetInfo(Type type)
{
DataClassInfo info;
if (!classInfos.TryGetValue(type, out info))
{
// This is not thread-safe, but that's fine.
// If this class is generated more than once it doesn't matter.
info = new DataClassInfo(type);
classInfos[type] = info;
}
return info;
}
}
手動回收應用程序池解決了問題。 從堆棧跟蹤看來,靜態只讀字段classInfos可能是NULL,但我不知道這是怎麼回事?
任何機會'類型'可以爲空? – rodrigogq 2014-12-02 14:19:41
不,我不這麼認爲 – user3703978 2014-12-02 14:27:10