誰かがこの問題を解決できますか?ウェブホストに公開する前にローカルiis7にウェブサイトを公開しましたが、データベース接続またはアプリ設定が取得されていないため、取得しています
[NullReferenceException: Object reference not set to an instance of an object.]
私のサイトは2つのプロジェクトを持つソリューション内にあります。1つのプロジェクトはデータベースデータとリモートサイトへの呼び出しを含むクラスライブラリであり、2番目のプロジェクトにはすべてのUIデータ、コントローラーヘルパーなどがあります。
だから私はWeb.DomainとWeb.UIを持っています。
次のような基本的なクラスがある場合:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Web.Domain.EAN
{
public class testFromDomain : ItestFromDomain
{
public string testdata()
{
return "test from domain";
}
}
}
それは問題なく動作するので、設定ファイルに問題があると私は信じています
誰かが私が間違っていることや行方不明になっていることを知っていますか?
私のサイトはMVC4です
--------------------完全なエラー------------------
'/'アプリケーションのサーバーエラー。
オブジェクト参照がオブジェクト インスタンスに設定されていません。説明:現在のWebリクエストの実行中に未処理の例外が発生しました。エラーとそれがコードのどこで発生したかについての詳細は、スタックトレースを確認してください。
例外の詳細:System.NullReferenceException:オブジェクト参照がオブジェクトのインスタンスに設定されていません。
ソースエラー:
現在のWebリクエストの実行中に、未処理の例外が生成されました。例外の発生源と場所に関する情報は、以下の例外スタックトレースを使用して識別できます。
スタックトレース:
[NullReferenceException:オブジェクト参照がオブジェクトのインスタンスに設定されていません。] Web.UI.Helpers.Weather.GetWeatherCurrentForcast.data(String id)+1947 System.Threading.Tasks.Task`1.InnerInvoke()+78 System.Threading .Tasks.Task.Execute()+109 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)+144 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)+84 Web.UI.Controllers.d__3.MoveNext( )+462 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(タスクタスク)+144 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(タスクタスク)+84 lambda_method(Closure、Task)+57 System.Web.Mvc.Async.TaskAsync .EndExecute(IAsyncResult asyncResult)+105System.Web.Mvc.Async。<>c_DisplayClass3f.b _3e(IAsyncResult asyncResult)+22System.Web.Mvc.Async。<>c_ DisplayClass39.b _33()+124System.Web.Mvc.Async。<>c_ DisplayClass4f.b _49()+838059システム。 Web.Mvc.Async。<> c_DisplayClass37.b _36(IAsyncResult asyncResult)+ 15System.Web.Mvc.Async 。<>c_ DisplayClass2a.b _20()+ 33System.Web.Mvc.Async 。<>c_ DisplayClass25 .b _22(IAsyncResult asyncResult)+838644System.Web.Mvc。<>c_ DisplayClass1d.b _18(IAsyncResult asyncResult)+ 28System.Web.Mvc.Async。<>c_ DisplayClass4.b _3(IAsyncResult ar)+15システム.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+65System.Web.Mvc.Async。<>c_DisplayClass4.b _3(IAsyncResult ar)+15 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+51System.Web.Mvc。<>c_ DisplayClass8.b _3(IAsyncResult asyncResult)+42System.Web.Mvc。 Async。<> c_DisplayClass4.b _3(IAsyncResult ar)+15 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+51 System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar)+282
バージョン情報:Microsoft .NET Frameworkバージョン:4.0.30319; ASP.NETバージョン:4.0.30319.18034
---------------------訪問者レビューの完全なコード------------------
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Caching;
using System.Text;
using System.Threading.Tasks;
namespace Web.Domain.VisitorReviews
{
public class DisplayVisitorReviews
{
public string ForumImageID { get; private set; }
public string ForumPostTitle { get; private set; }
public string ForumCity { get; private set; }
public string ForumRegion { get; private set; }
public string ForumCountry { get; private set; }
public string ForumPost { get; private set; }
public string ForumRatePost { get; private set; }
public string ForumMember { get; private set; }
public string ForumImageType { get; private set; }
public byte[] ForumImage { get; private set; }
public DisplayVisitorReviews(string ForumImageID,
string ForumPostTitle,
string ForumCity,
string ForumRegion,
string ForumCountry,
string ForumPost,
string ForumRatePost,
string ForumMember,
string ForumImageType,
byte[] ForumImage)
{
this.ForumImageID = ForumImageID;
this.ForumPostTitle = ForumPostTitle;
this.ForumCity = ForumCity;
this.ForumRegion = ForumRegion;
this.ForumCountry = ForumCountry;
this.ForumPost = ForumPost;
this.ForumRatePost = ForumRatePost;
this.ForumMember = ForumMember;
this.ForumImageType = ForumImageType;
this.ForumImage = ForumImage;
}
}
public class GetVisitorReviews : IGetVisitorReviews
{
private string dbConn;
public GetVisitorReviews()
{
dbConn = ConfigurationManager.ConnectionStrings["Website"].ConnectionString;
}
public IEnumerable<DisplayVisitorReviews> DisplayTopTenVisitorReviews(string id)
{
//string cacheTopTenDestinationReports = "TopTenDestinationReports + "-"+ id";
//string TopTenDestinationReportsCacheKey = cacheTopTenDestinationReports;
//MemoryCache CacheTopTenDestinationReports = MemoryCache.Default;
//if (CacheTopTenDestinationReports.Contains(TopTenDestinationReportsCacheKey))
// return CacheTopTenDestinationReports[TopTenDestinationReportsCacheKey] as IEnumerable<DisplayVisitorReviews>;
string spName = "dbo.GetTopTenForumPosts";
using (SqlConnection cn = new SqlConnection(dbConn))
{
using (SqlCommand cmd = new SqlCommand(spName, cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@strLocation", SqlDbType.VarChar, 150));
cmd.Parameters["@strLocation"].Value = id;
List<DisplayVisitorReviews> lst = new List<DisplayVisitorReviews>();
try
{
cn.Open();
using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.Default))
{
if (rdr.HasRows)
{
while (rdr.Read())
{
DisplayVisitorReviews GetData = new DisplayVisitorReviews(
Convert.ToString((Guid)rdr["ForumImageID"]),
(string)rdr["ForumPostTitle"],
(string)rdr["ForumCity"],
(string)rdr["ForumRegion"],
(string)rdr["ForumCountry"],
(string)rdr["ForumPost"],
Convert.ToString((int)rdr["ForumRatePost"]),
(string)rdr["ForumMember"],
(string)rdr["ForumImageType"],
(byte[])rdr["ForumImage"]);
lst.Add(GetData);
}
}
}
//CacheItemPolicy policy = new CacheItemPolicy();
//policy.AbsoluteExpiration = DateTime.Now.AddHours(1);
//CacheTopTenDestinationReports.Add(TopTenDestinationReportsCacheKey, lst.AsEnumerable(), policy);
return lst;
}
catch (Exception ex)
{
throw new ApplicationException(ex.InnerException.ToString());
}
}
}
}
}
}
using System;
using System.Collections.Generic;
namespace Web.Domain.VisitorReviews
{
public interface IGetVisitorReviews
{
IEnumerable<DisplayVisitorReviews> DisplayTopTenVisitorReviews(string id);
}
}
kernel.Bind<IGetVisitorReviews>().To<GetVisitorReviews>().InSingletonScope();
private readonly IGetVisitorReviews _IGVR;
public MembersController(IGetVisitorReviews IGVR)
{
_IGVR = IGVR;
}
public PartialViewResult pvVisitorReviews()
{
var destinations = _IGVR.DisplayTopTenVisitorReviews("NA").Take(5);
return PartialView("pvHomePageVisitorReviews",destinations);
}
<add name="Website" connectionString="Data Source=Windows7\SQL2012;Initial Catalog=WebsiteDB;Persist Security Info=true; Integrated Security=SSPI" providerName="System.Data.SqlClient" />
レビュー用に完全なコードを追加しました。その理由は、コードの量が最も少ないためです。また、天気の部分ビューをコメントアウトすると、同じエラーがレビューにも当てはまります。レビューなど、web.configから参照された場合にサイトがロードするものをコメントアウトすると、同じエラーが発生します。
------------------------クラスで接続設定を囲んだ後の完全なエラー-------------
Server Error in '/' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 87: <div class="dvAsyncDestination">
Line 88:
Line 89: @{Html.RenderAction("pvVisitorReviews", "Members", true);}
Line 90:
Line 91: </div>
Source File: f:\LocalTestSite\Views\Home\Index.cshtml Line: 89
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Web.UI.Controllers.MembersController.pvVisitorReviews() +184
lambda_method(Closure , ControllerBase , Object[] ) +78
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +260
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +38
System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +33
System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +123
System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +838059
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +15
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +33
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +838644
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +51
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51
System.Web.Mvc.<>c__DisplayClass4.<Wrap>b__3() +15
System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +41
System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1783
[HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.]
System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +2819
System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +275
System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +94
System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +700
DevTrends.MvcDonutCaching.HtmlHelperExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, Boolean excludeFromParentCache) +233
DevTrends.MvcDonutCaching.HtmlHelperExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, String controllerName, Boolean excludeFromParentCache) +17
ASP._Page_Views_Home_Index_cshtml.Execute() in f:\LocalTestSite\Views\Home\Index.cshtml:89
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
System.Web.WebPages.StartPage.ExecutePageHierarchy() +143
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +181
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +378
System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +33
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +854172
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +838644
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +51
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18034