Azure错误是:
.Net Core:应用程序启动异常:System.IO.FileNotFoundException:找不到配置文件'appsettings.json',它不是可选的.
所以这有点模糊.我似乎无法解决这个问题.我正在尝试将一个.Net Core Web API项目部署到Azure,我收到此错误:
:(糟糕.500内部服务器错误启动应用程序时出错.
我已经部署了普通的.Net WebAPI,他们已经工作了.我已经按照在线教程进行了操作.但不知何故,我的项目已经破产.在Web.config上启用stdoutLogEnabled并查看Azure Streaming Logs给出了以下信息:
2016-08-26T02:55:12 Welcome, you are now connected to log-streaming service.
Application startup exception: System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional.
at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
at Quanta.API.Startup..ctor(IHostingEnvironment env) in D:\Source\Workspaces\Quanta\src\Quanta.API\Startup.cs:line 50
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
at Microsoft.Extensions.Internal.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, …Run Code Online (Sandbox Code Playgroud) azure azure-web-sites .net-core asp.net-core asp.net-core-webapi
在为ASP.NET Core应用程序编写单元测试期间,我意识到ViewData可以访问,ViewResult但是ViewBag不能访问。
我的HomeController:
public class HomeController : Controller
{
private readonly IHeroRepository _heroItems;
private readonly IQuestRepository _questItems;
public HomeController(
IHeroRepository heroItems,
IQuestRepository questItems)
{
_heroItems = heroItems;
_questItems = questItems;
}
[HttpGet]
public async Task<IActionResult> Index()
{
var recentHeroesVM = await _heroItems.GetRecentHeroesAsync(2);
ViewBag.QuestSelectList = await _questItems.GetSelectListAsync();
return View(recentHeroesVM);
}
}
Run Code Online (Sandbox Code Playgroud)
我的测试课:
public class HomeController_Index
{
[Fact]
public async Task Index_ReturnsAViewResult_WithAListOfRecentHeros()
{
// Arrange
var mockHeroRepo = new Mock<IHeroRepository>();
var mockQuestRepo = …Run Code Online (Sandbox Code Playgroud) 是否可以将有关本地计算表达式的 Entity Framework Core 警告转换为错误?我想强迫自己总是编写正确评估的查询。
Microsoft.EntityFrameworkCore.Query:警告:LINQ 表达式“(...)”无法翻译,将在本地进行评估。
我有一个简单的服务界面:
public interface ICustomService
{
bool ConstructedWithNoParameters { get; }
}
Run Code Online (Sandbox Code Playgroud)
同样简单的实现:
public class CustomService : ICustomService
{
private readonly IEnumerable<int> _items;
public CustomService()
{
_items = Enumerable.Empty<int>();
ConstructedWithNoParameters = true;
}
public CustomService(IEnumerable<int> items)
{
_items = items ?? throw new ArgumentNullException(nameof(items));
}
public bool ConstructedWithNoParameters { get; }
}
Run Code Online (Sandbox Code Playgroud)
请注意,根据调用哪个构造函数,将ConstructedWithNoParameters设置为true。
这是一个简单的测试场景来进行测试:
[Fact]
public void Test1()
{
// Assert
var serviceProvider = new ServiceCollection()
.AddTransient<ICustomService, CustomService>()
.BuildServiceProvider();
// Act
var customService = serviceProvider.GetRequiredService<ICustomService<int>>();
// Arrange …Run Code Online (Sandbox Code Playgroud) asp.net-core ×3
c# ×3
.net-core ×2
azure ×1
ienumerable ×1
unit-testing ×1
viewbag ×1
xunit ×1