我有一个简单的ASP.NET核心应用程序,我在2016年12月工作.它在应用程序见解和遥测方面工作得很好.
现在4个月后,我想开始从.NET Core 1.1.0升级到1.1.1.在此过程中,包Microsoft.ApplicationInsights.AspNetCore已从版本更新1.0.2到版本2.0.0.
这不幸导致我的应用程序停止工作,特别是我收到此错误:
An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.
/Views/Shared/_Layout.cshtml
'IHtmlHelper<dynamic>' does not contain a definition for 'ApplicationInsightsJavaScript' and no extension method 'ApplicationInsightsJavaScript' accepting a first argument of type 'IHtmlHelper<dynamic>' could be found (are you missing a using directive or an assembly reference?)
+
@Html.ApplicationInsightsJavaScript(TelemetryConfiguration)
Show compilation source
#pragma checksum "/Views/Shared/_Layout.cshtml" …Run Code Online (Sandbox Code Playgroud) .net c# asp.net-core-mvc azure-application-insights asp.net-core
是)我有的:
public interface IRepository
{
IDisposable CreateConnection();
User GetUser();
//other methods, doesnt matter
}
public class Repository
{
private SqlConnection _connection;
IDisposable CreateConnection()
{
_connection = new SqlConnection();
_connection.Open();
return _connection;
}
User GetUser()
{
//using _connection gets User from Database
//assumes _connection is not null and open
}
//other methods, doesnt matter
}
Run Code Online (Sandbox Code Playgroud)
这使得使用IRepository的类可以轻松测试并且IoC容器友好.但是,使用此类的人必须在调用从数据库获取内容的任何方法之前调用CreateConnection,否则将抛出异常.这本身就很好 - 我们不希望在应用程序中有持久的联系.所以使用这个课我这样做.
using(_repository.CreateConnection())
{
var user = _repository.GetUser();
//do something with user
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不是一个很好的解决方案,因为使用这个类的人(甚至包括我!)_repository.CreateConnection()在调用方法从数据库中获取内容之前经常忘记调用.
为了解决这个问题,我查看了Mark Seemann博客文章SUT Double,他以正确的方式实现了Repository模式.不幸的是,他使Repository实现了IDisposable,这意味着我不能简单地将IoC和DI注入到类中并在之后使用它,因为在一次使用后它将被处理掉.他根据请求使用了一次,并且在请求处理完成后使用ASP.NET WebApi功能来处理它.这是我不能做的事情,因为我的类实例一直使用Repository工作.
这里最好的解决方案是什么?我应该使用某种能给我IDisposable IRepository的工厂吗?它会很容易测试吗?
c# unit-testing idisposable inversion-of-control repository-pattern
假设我们有一个泛型类的想法Matrix<T>哪里T是数字型(Complex或double或者float,int等).
很自然,我们在C#中从in float到doublefrom double进行了隐式转换Complex.一般规则是我们有从较小类型到较大类型的隐式转换.到现在为止还挺好.
现在假设我们正在实现我们的Matrix<T>类型.由于这种新型的方式是数字也(或者至少其持有的数值),这是很自然有隐式转换从Matrix<float>到Matrix<double>,从Matrix<double>对Matrix<Complex>等至少它是好的,有这些像乘数学运算,加等但是这似乎无法正确实现,因为隐式运算符要求至少一个类型与我们实现它的类相同.
示例:下面的代码无法编译,甚至认为它可以解决我的问题.
public abstract partial class Matrix<T>
{
/// <summary>
/// Implicitly converts a matrix to double precision complex numbers.
/// </summary>
public static implicit operator Matrix<Complex64>(Matrix<double> matrix)
{
matrix.ToComplex();
}
/// <summary>
/// Implicitly converts a matrix to double precision real numbers.
/// </summary>
public static implicit …Run Code Online (Sandbox Code Playgroud) 在 F# 中使用预定义标识符相当容易__SOURCE_DIRECTORY__
/sf/answers/340272061/
但是,此标识符在 C# 脚本(csx 文件或 C# Interactive)中不起作用。
> __SOURCE_DIRECTORY__
(1,1): 错误 CS0103: 当前上下文中不存在名称“__SOURCE_DIRECTORY__”
以更传统的方式获取当前目录也行不通。
Directory.GetCurrentDirectory()
返回: C:\Users\$USER_NAME$\
new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath;
返回: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\ManagedLanguages\VBCSharp\InteractiveComponents\
Windows 10 S是一个特殊的Windows版本,简化了安全性和卓越性能.基本上,您只能从Microsoft Store安装应用程序.
您可以通过桌面桥接器向商店提供普通桌面应用程序,这样本身就不是一个大问题.但是,Windows 10 S对Store应用程序施加了额外的限制,这可能会导致它们在启动期间崩溃.
我收到了商店申请审核结果的反馈.
应用策略:10.1.2.1不准确的功能:Windows 10S
发展商须知:
您的应用程序无法在Windows 10 S上运行,应用程序终止,恕不另行通知用户.在Windows 10 S上无法运行的应用程序必须支持正常关机.
重现步骤:1.在Windows 10S上启动应用程序.2.请注意,您的应用程序在Windows 10 S上不起作用,应用程序终止,恕不另行通知用户.
请务必测试适用于Windows 10 S的应用:https: //docs.microsoft.com/windows/uwp/porting/desktop-to-uwp-test-windows-s 经测试的设备:Windows 10桌面
基本上我需要做的是检测Windows 10 S并通知用户它不受支持.
c# ×5
.net ×3
asp.net-core ×1
generics ×1
idisposable ×1
roslyn ×1
unit-testing ×1
uwp ×1
windows-10 ×1