アプリケーションでランダムな時間にNullReferenceExeceptionsを取得していて、エラーの原因を突き止めることができません。
シナリオとセットアップについて説明するために最善を尽くします。
ありとあらゆる提案に感謝します!
C#.net 3.5フォームアプリケーションですが、Phil Haack( http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx)によって構築されたWebFormRoutingライブラリを使用して、 .net(通常はMVCと組み合わせて使用されます)-URLにURL書き換えを使用するのではなく。
私のデータベースには60個のテーブルがあります。すべて正規化。それはただの大規模なアプリケーションです。(SQL Server 2008)
すべてのクエリは、コード内のLinq to SQLを使用して構築されています(SPはありません)。データコンテキストの新しいインスタンスが作成されるたび。SQLServerの4つの関係図で定義されたすべての関係を持つ1つのデータコンテキストのみを使用します。
データコンテキストはたくさん作成されます。データコンテキストの終了は自動的に処理されます。自動的に閉鎖するために去るべきか、それとも自分でそれを行うべきかについて、双方の議論を聞いたことがあります。この場合、私は自分でそれをしません。
データコンテキストのインスタンスを多数作成するのか、1つだけ作成するのかは問題ではないようです。
たとえば、私は投票ボタンを持っています。次のコードで、おそらく10〜20回に1回エラーが発生します。
protected void VoteUpLinkButton_Click(object sender, EventArgs e)
{
DatabaseDataContext db = new DatabaseDataContext();
StoryVote storyVote = new StoryVote();
storyVote.StoryId = storyId;
storyVote.UserId = Utility.GetUserId(Context);
storyVote.IPAddress = Utility.GetUserIPAddress();
storyVote.CreatedDate = DateTime.Now;
storyVote.IsDeleted = false;
db.StoryVotes.InsertOnSubmit(storyVote);
db.SubmitChanges();
// If this story is not yet published, check to see if we should publish it. Make sure that
// it is already approved.
if (story.PublishedDate == null && story.ApprovedDate != null)
{
Utility.MakeUpcommingNewsPopular(storyId);
}
// Refresh our page.
Response.Redirect("/news/" + category.UniqueName + "/"
+ RouteData.Values["year"].ToString() + "/"
+ RouteData.Values["month"].ToString() + "/"
+ RouteData.Values["day"].ToString() + "/"
+ RouteData.Values["uniquename"].ToString());
}
私が最後に試したのは、SQLServerの「自動クローズ」フラグ設定でした。これはtrueに設定され、falseに変更されました。全体的には良い効果がありましたが、うまくいかなかったようです。
キャッチされなかった詳細は次のとおりです。また、try / catchでキャッチすると、わずかに異なるエラーが発生します。
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. --->
System.NullReferenceException: Object reference not set to an instance of an object. at
System.Web.Util.StringUtil.GetStringHashCode(String s) at
System.Web.UI.ClientScriptManager.EnsureEventValidationFieldLoaded() at
System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) at
System.Web.UI.WebControls.TextBox.LoadPostData(String postDataKey, NameValueCollection postCollection) at
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) at
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace --- at
System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at
System.Web.UI.Page.ProcessRequest(HttpContext context) at
ASP.forms_news_detail_aspx.ProcessRequest(HttpContext context) at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
ヘルプ!!!