为了隔离任何问题以便能够重现该问题,我在 VS 2017 中使用 ASP.NET MVC 模板 (.NET Framework 4.6.1) 开始了一个全新的项目。
我将最新的ckeditor5添加到/Scripts/ckeditor5/ckeditor.js
在 BundleConfig.cs 中,我添加了以下内容:
bundles.Add(new ScriptBundle("~/bundles/ckeditor").Include(
"~/Scripts/ckeditor5/ckeditor.js"));
Run Code Online (Sandbox Code Playgroud)
在 _layout.cshtml 中,我有这个:
@Scripts.Render("~/bundles/ckeditor")
Run Code Online (Sandbox Code Playgroud)
当我运行该应用程序时,它给出“System.NullReferenceException”错误。看来微软的Ajax解析不喜欢ckeditor5??
在 Microsoft.Ajax.Utilities.JSParser.ParseObjectLiteralProperty(Boolean isBindingPattern)\r\n 在 Microsoft.Ajax.Utilities.JSParser.ParseObjectLiteral(Boolean isBindingPattern)\r\n 在 Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus) \r\n 在 Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)\r\n 在 Microsoft.Ajax.Utilities.JSParser.ParseVarDecl(JSToken inToken)\r\n
在 Microsoft.Ajax.Utilities。 JSParser.ParseVariableStatement()\r\n 在 Microsoft.Ajax.Utilities.JSParser.ParseFunctionBody(块体)\r\n
在 Microsoft.Ajax.Utilities.JSParser.ParseFunction(FunctionType functionType, Context fncCtx)\r\n 在 Microsoft .Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)\r\n 在 Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)\r\n 在 Microsoft.Ajax.Utilities.JSParser.ParseArrayLiteral(Boolean isBindingPattern )\r\n 于
如果我忘记了 Bundle 并且我在 _Layout.cshtml 上硬编码了这样的路径,它会起作用:
<script src="~/Scripts/ckeditor5/ckeditor.js"></script>
Run Code Online (Sandbox Code Playgroud)
知道如何使捆绑包适用于 ckeditor5 吗?
我有一个userList,有些用户没有名字(null).如果我运行第一个LINQ查询,我得到一个错误说"对象引用未设置为对象的实例"错误.
var temp = (from a in userList
where ((a.name == "john") && (a.name != null))
select a).ToList();
Run Code Online (Sandbox Code Playgroud)
但是,如果我通过在前面检查null来切换顺序,那么它可以正常运行而不会抛出任何错误:
var temp = (from a in userList
where ((a.name != null) && (a.name == "john"))
select a).ToList();
Run Code Online (Sandbox Code Playgroud)
这是为什么?如果那是纯粹的C#代码(不是LINQ),我认为两者都是一样的.我没有SQL分析器,我只是好奇它们在SQL级别上被翻译时会有什么不同.
我在Linq-To-Entity上使用SingleOfDefault阅读其他关于类似问题的帖子,有些建议使用"First()",其他一些建议使用"Extension"方法来实现Single().
此代码抛出异常:
Movie movie = (from a in movies
where a.MovieID == '12345'
select a).SingleOrDefault();
Run Code Online (Sandbox Code Playgroud)
如果我使用.ToList()将对象查询转换为List,"SingleOrDefault()"实际上可以正常工作而不会抛出任何错误.
我的问题是:转换为List不好吗?是否会出现更复杂查询的性能问题?它在SQL中被翻译了什么?
Movie movie = (from a in movies.ToList()
where a.MovieID == '12345'
select a).SingleOrDefault();
Run Code Online (Sandbox Code Playgroud) 我一直在阅读很多关于Singleton在线的文章,但大多数文章只展示了创建简单对象并正确锁定以确保线程安全而没有竞争条件.
简单到足以演示,我在那里放了一个文件记录方法.它将适用于10-20个并发线程,但是当我尝试100个线程时,它将失败,因为"进程无法访问该文件,因为它正被另一个进程使用".
public class Logger
{
private string _path = "c:\\temp\\MyTestLog.txt";
// Singleton with padlock for DCL
private volatile static Logger _instance;
private static readonly object _padLock = new Object();
// Singleton
public static Logger Instance()
{
// Implement Double Check Locking (MSDN - Thread-safe)
if (_instance == null)
{
lock (_padLock)
{
if (_instance == null)
_instance = new Logger();
}
}
return _instance;
}
// Simple WriteLog
public void WriteLog(string text, out bool result)
{
try
{
// …Run Code Online (Sandbox Code Playgroud)