在我们的SharePoint 2010项目中,我们使用Linq to SharePoint获取ConfigurationItems列表。在我们的测试环境中,从这个列表中获取数据从未出现过问题。但是在我们的生产环境中,当循环遍历列表中的项时,有时会出现空引用异常(我们目前无法找到规律)。
以下是我们从Linq to SharePoint代码中抛出的异常:
Object reference not set to an instance of an object. StackTrace: at Microsoft.SharePoint.Linq.FieldRef.GetHashCode() at Microsoft.SharePoint.Linq.FieldRef.FieldRefEqualityComparer.GetHashCode(FieldRef obj) at System.Linq.Set`1.InternalGetHashCode(TElement value) at System.Linq.Set`1.Find(TElement value, Boolean add) at System.Linq.Enumerable.d__7a`1.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at Microsoft.SharePoint.Linq.SelectMappingInfo.GetDistinctMappedFields() at Microsoft.SharePoint.Linq.Rules.PushDownProcessor.SelectWithInfoOp.PushDownSelect(Context ctx) at Microsoft.SharePoint.Linq.Rules.PushDownProcessor.SelectWithInfoOp.Process(Context ctx) at Microsoft.SharePoint.Linq.Rules.GuardedRule`4.c__DisplayClass7.b__6(TSourceBase src, TContext ctx) at Microsoft.SharePoint.Linq.Rules.RewriteRule`2.Apply(TNode src, TContext ctx) at Microsoft.SharePoint.Linq.Rules.CacheRule`3.Apply(TSource src, TContext ctx) at Microsoft.SharePoint.Linq.Rules.PushDownProcessor.b__0(Expression e, Context ctx) at Microsoft.SharePoint.Linq.Rules.ChildRule`2.Apply(TNode src, TContext ctx) at Microsoft.SharePoint.Linq.Rules.PushDownProcessor.b__3(Expression e, Context ctx) at Microsoft.SharePoint.Linq.Rules.RewriteRule`2.Apply(TNode src, TContext ctx) at Microsoft.SharePoint.Linq.Rules.CacheRule`3.Apply(TSource src, TContext ctx) at Microsoft.SharePoint.Linq.SPLinqProvider.Rewrite(Expression expression, List`1& assumptions) at Microsoft.SharePoint.Linq.SPLinqProvider.RewriteAndCompile[T](Expression expression, List`1& assumptions) at Microsoft.SharePoint.Linq.LinqQuery`1.GetEnumerator() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Common.Configuration.ConfigurationRepository.GetConfiguration(String siteUrl) InnerException:
源: Microsoft.SharePoint.Linq TargetSite: Int32 GetHashCode()
以下是我们在GetConfiguration方法中使用的代码。
以下是我们从Linq to SharePoint代码中抛出的异常:
Object reference not set to an instance of an object. StackTrace: at Microsoft.SharePoint.Linq.FieldRef.GetHashCode() at Microsoft.SharePoint.Linq.FieldRef.FieldRefEqualityComparer.GetHashCode(FieldRef obj) at System.Linq.Set`1.InternalGetHashCode(TElement value) at System.Linq.Set`1.Find(TElement value, Boolean add) at System.Linq.Enumerable.d__7a`1.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at Microsoft.SharePoint.Linq.SelectMappingInfo.GetDistinctMappedFields() at Microsoft.SharePoint.Linq.Rules.PushDownProcessor.SelectWithInfoOp.PushDownSelect(Context ctx) at Microsoft.SharePoint.Linq.Rules.PushDownProcessor.SelectWithInfoOp.Process(Context ctx) at Microsoft.SharePoint.Linq.Rules.GuardedRule`4.c__DisplayClass7.b__6(TSourceBase src, TContext ctx) at Microsoft.SharePoint.Linq.Rules.RewriteRule`2.Apply(TNode src, TContext ctx) at Microsoft.SharePoint.Linq.Rules.CacheRule`3.Apply(TSource src, TContext ctx) at Microsoft.SharePoint.Linq.Rules.PushDownProcessor.b__0(Expression e, Context ctx) at Microsoft.SharePoint.Linq.Rules.ChildRule`2.Apply(TNode src, TContext ctx) at Microsoft.SharePoint.Linq.Rules.PushDownProcessor.b__3(Expression e, Context ctx) at Microsoft.SharePoint.Linq.Rules.RewriteRule`2.Apply(TNode src, TContext ctx) at Microsoft.SharePoint.Linq.Rules.CacheRule`3.Apply(TSource src, TContext ctx) at Microsoft.SharePoint.Linq.SPLinqProvider.Rewrite(Expression expression, List`1& assumptions) at Microsoft.SharePoint.Linq.SPLinqProvider.RewriteAndCompile[T](Expression expression, List`1& assumptions) at Microsoft.SharePoint.Linq.LinqQuery`1.GetEnumerator() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Common.Configuration.ConfigurationRepository.GetConfiguration(String siteUrl) InnerException:
源: Microsoft.SharePoint.Linq TargetSite: Int32 GetHashCode()
以下是我们在GetConfiguration方法中使用的代码。
using (SpDataContext dataContext = new SpDataContext(siteUrl))
{
result = new ConfigurationModel()
{
Configurations = (from item in dataContext.GasportConfiguration
select new ConfigurationItem()
{
Key = item.Key,
Value = item.Value,
Environment = (Environment)Enum.Parse(typeof(Environment), item.Environment.ToString(), true)
}).ToList()
};
}
有没有人有想法如何跟踪这个异常的原因?
更新于2011年5月31日:
我们在生产环境中找到了一种可以重现此行为的模式。并且在我们的测试环境中也遇到了这个问题,通过使用AdPlus提取了一些崩溃转储文件。
我们发现这种行为发生在应用程序池被回收后。唯一修复此错误的方法是执行完整的IISreset。
在崩溃转储分析中,我发现一个异常消息,指出: 异常代码:0xC0000005 异常信息:线程尝试读取或写入其没有适当访问权限的虚拟地址。
希望有人能给我更多关于此异常的信息?