MVC 6 RC 1に更新され、新しいMVCアプリケーションが作成されました。MVC 6、HomeControler Index()が2回呼び出されました
インデックスアクションメソッドが2回呼び出されました。
HomeControler
で
Index()
:
public string Index()
{
System.Diagnostics.Debug.WriteLine("############################");
return string.Empty;
}
私は、デフォルトのルーティングを除くStartup.cs
設定からすべてを削除しました。
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
グローバルレイアウトは削除されます。 _ViewStart.cshtml
ブラウザの出力は空です。スクリプトはありません。
コンソール出力:
'dnx.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Miroslav\.dnx\packages\Microsoft.Extensions.Localization.Abstractions\1.0.0-rc1-final\lib\net451\Microsoft.Extensions.Localization.Abstractions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'dnx.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Miroslav\.dnx\packages\Microsoft.VisualStudio.Web.BrowserLink.Loader\14.0.0-rc1-final\lib\dnx451\Microsoft.VisualStudio.Web.BrowserLink.Loader.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'dnx.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Miroslav\.dnx\packages\Microsoft.AspNet.WebUtilities\1.0.0-rc1-final\lib\net451\Microsoft.AspNet.WebUtilities.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
############################
############################
'dnx.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Miroslav\.dnx\packages\Microsoft.AspNet.Http.Extensions\1.0.0-rc1-final\lib\net451\Microsoft.AspNet.Http.Extensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0x70a4 has exited with code 0 (0x0).
コールスタック:
MvcTest1!MvcTest1.Controllers.HomeController.Index() Line 15 C#
[Native to Managed Transition]
[Managed to Native Transition]
Microsoft.AspNet.Mvc.Core.dll!Microsoft.AspNet.Mvc.Controllers.ControllerActionExecutor.ExecuteAsync(System.Reflection.MethodInfo actionMethodInfo, object instance, object[] orderedActionArguments) Unknown
Microsoft.AspNet.Mvc.Core.dll!Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker.InvokeActionAsync(Microsoft.AspNet.Mvc.Filters.ActionExecutingContext actionExecutingContext) Unknown
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.Start<Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker.<InvokeActionAsync>d__6>(ref Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker.<InvokeActionAsync>d__6 stateMachine) Unknown
Microsoft.AspNet.Mvc.Core.dll!Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker.InvokeActionAsync(Microsoft.AspNet.Mvc.Filters.ActionExecutingContext actionExecutingContext) Unknown
Microsoft.AspNet.Mvc.Core.dll!Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.InvokeActionFilterAsync() Unknown
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.Start<Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeActionFilterAsync>d__53>(ref Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeActionFilterAsync>d__53 stateMachine) Unknown
Microsoft.AspNet.Mvc.Core.dll!Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.InvokeActionFilterAsync() Unknown
EDITは
HomeControlerコンストラクタが2回呼び出されていることが見つかりました?
public class HomeController : Controller
{
public HomeController()
{
System.Diagnostics.Debug.WriteLine("CCCCCCCCCCCCCCCCCCCCCC");
}
public string Index()
{
return string.Empty;
}
コンソール出力:
'dnx.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Miroslav\.dnx\packages\Microsoft.Extensions.Localization.Abstractions\1.0.0-rc1-final\lib\net451\Microsoft.Extensions.Localization.Abstractions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'dnx.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Miroslav\.dnx\packages\Microsoft.VisualStudio.Web.BrowserLink.Loader\14.0.0-rc1-final\lib\dnx451\Microsoft.VisualStudio.Web.BrowserLink.Loader.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'dnx.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Miroslav\.dnx\packages\Microsoft.AspNet.WebUtilities\1.0.0-rc1-final\lib\net451\Microsoft.AspNet.WebUtilities.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
CCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCC
'dnx.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Miroslav\.dnx\packages\Microsoft.AspNet.Http.Extensions\1.0.0-rc1-final\lib\net451\Microsoft.AspNet.Http.Extensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0x5d84 has exited with code 0 (0x0).
The thread 0x7334 has exited with code 0 (0x0).
EDIT 2
は、おそらく問題は、デバッグモードで表示されます。
public static class Counter
{
public static int CtrCalled { get; set; }
public static int IndexCalled { get; set; }
}
public class HomeController : Controller
{
public HomeController()
{
Counter.CtrCalled++;
}
public string Index()
{
Counter.IndexCalled++;
return $"Constructor called: {Counter.CtrCalled}, Index called: {Counter.IndexCalled}.";
}
}
デバッグモード出力:Constructor called: 2, Index called: 1.
デバッグモード:Constructor called: 2, Index called: 2.
リリースモード出力:Constructor called: 1, Index called: 1.
あなたのビューは空ですか? –
はい。ビューは空です。しかし、私は問題がデバッグモードにしかないことに気づいた。 –
あなたは 'DependecyResolver'を使っていますか? –