在最近升级到.net 4.6之后,我们发现了一个RyuJit产生错误结果的错误,我们现在可以通过在app.config中添加useLegacyJit enabled ="true"来解决这个问题.
如何调试以下生成的机器代码?
我在VS 2015 RTM中创建了一个新的控制台项目,设置为Release,Any CPU,未经检查的Prefer 32 bit,带有和不带调试器的运行产生相同的结果.
using System;
using System.Runtime.CompilerServices;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Calculate());
Console.WriteLine(Calculate());
Console.ReadLine();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Value Calculate()
{
bool? _0 = (bool?)null;
bool? _1 = (bool?)true;
if (!Value.IsPresent<bool>(_1))
{
return default(Value);
}
bool? result = null;
result = (_1.Value ? new bool?(false) : result);
if (_0.HasValue && _0.Value)
{
}
return new Value(result);
}
public struct Value
{
bool? _value;
public Value(bool? …Run Code Online (Sandbox Code Playgroud) 我有一个我使用的库,它使用WCF调用http服务来获取设置.通常,第一次调用需要约100毫秒,后续调用只需几毫秒.但是我发现当我创建一个新的AppDomain时,来自该AppDomain的第一个WCF调用需要2.5秒.
有没有人解释或解决为什么在新的AppDomain中首次创建WCF频道需要这么长时间?
这些是基准测试结果(当在64位版本中没有附带调试器的情况下运行时),请注意第二组数字中的第一个连接如何延长25倍
Running in initial AppDomain
First Connection: 92.5018 ms
Second Connection: 2.6393 ms
Running in new AppDomain
First Connection: 2457.8653 ms
Second Connection: 4.2627 ms
Run Code Online (Sandbox Code Playgroud)
这不是一个完整的例子,但显示了我生成这些数字的大部分内容:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Running in initial AppDomain");
new DomainRunner().Run();
Console.WriteLine();
Console.WriteLine("Running in new thread and AppDomain");
DomainRunner.RunInNewAppDomain("test");
Console.ReadLine();
}
}
class DomainRunner : MarshalByRefObject
{
public static void RunInNewAppDomain(string runnerName)
{
var newAppDomain = AppDomain.CreateDomain(runnerName);
var runnerProxy = (DomainRunner)newAppDomain.CreateInstanceAndUnwrap(typeof(DomainRunner).Assembly.FullName, typeof(DomainRunner).FullName);
runnerProxy.Run();
}
public void Run()
{
AppServSettings.InitSettingLevel(SettingLevel.Production); …Run Code Online (Sandbox Code Playgroud) 可能重复:
dotnet框架中的字符串比较4
我注意到我的机器上的一个性能问题在UI应用程序中进行了大量的字符串比较,以便对大型列表进行过滤.我在调用string.IndexOf时跟踪问题直到使用OrdinalIgnoreCase.以下基准测试是在未附带调试器的Release中运行的,它是在VS 2010中构建的4.0项目,Windows 7,我确实在这台机器上安装了4.5 beta,我不确定这是否会影响这一点.
1.190 seconds for OrdinalIgnoreCase
0.178 seconds for CurrentCultureIgnoreCase
0.175 seconds for InvariantCultureIgnoreCase
0.101 seconds for Ordinal
0.132 seconds for CurrentCulture
0.126 seconds for InvariantCulture
1.176 seconds for OrdinalIgnoreCase
0.189 seconds for CurrentCultureIgnoreCase
0.183 seconds for InvariantCultureIgnoreCase
0.104 seconds for Ordinal
0.138 seconds for CurrentCulture
0.127 seconds for InvariantCulture
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,OrdinalIgnoreCase慢了6.5倍!但没有IgnoreCase Ordinal是最快的.在多个地方,microsoft建议使用 OrdinalIgnoreCase以获得最佳性能.任何人都可以复制这些结果或解释为什么OrdinalIgnoreCase在这个测试中变得如此之慢?
private static void Test(string search, string key, StringComparison comparison, int trials)
{
var sw = Stopwatch.StartNew();
for (int i = 0; i …Run Code Online (Sandbox Code Playgroud) 我有一个必须执行大量数据库查询的服务器进程,它使用TPL并行运行东西.它在今年的整个过程中都运行良好,直到今天它在30分钟的时间内崩溃了两次,但有以下例外情况:
事务(进程ID 89)与另一个进程在通信缓冲区资源上死锁,并被选为死锁牺牲品.重新运行该交易.
数据库配置为记录任何死锁,但它没有记录任何内容,所以似乎这个死锁只发生在客户端?
除了一个没有提供任何信息的msdn论坛帖子之外,我找不到任何对此异常的引用.
有没有人见过这个例外?或者知道我能做些什么来找到它的更多信息?
---> System.AggregateException: One or more errors occurred.
---> System.Data.SqlClient.SqlException: Transaction (Process ID 89) was deadlocked on communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.HasMoreRows()
at System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout)
at App.CoreEngine.V5.DataAccess.SqlReader.Read(String readerDescription) in C:\SourceCode\AppV1\Releases\Libraries\CoreEngine\CoreEngine.V5\DataAccess\SqlReader.cs:line 121
at App.CoreEngine.V5.DataAccess.DataContext.ExecuteQuery(PtQuery query, ValueStore`1 store, String readerDescription) in C:\SourceCode\AppV1\Releases\Libraries\CoreEngine\CoreEngine.V5\DataAccess\DataContext.cs:line 328 …Run Code Online (Sandbox Code Playgroud) 看起来智能感知的行为在SSMS 2012中已经改变,因此它的行为与Visual Studio或SSMS 2008的行为不同.
以前我总是会点击SPACE,这会插入来自intellisense的当前突出显示的单词.但是在SSMS 2012中我必须击中TAB或点击向下箭头然后SPACE
这是SSMS 2012在我输入查询时的样子

如果我点击空间然后发生这种情况:

在SSMS 2008中,它看起来不同

而在视觉工作室

在这两个只是命中SPACE将插入单词.有没有办法在SSMS 2012中自定义或更改智能感知行为?
是什么决定了同一控件上多个DepdencyProperties的评估顺序?
我正在使用Extended WPF Toolkit PropertyGrid并且绑定了SelectedObject和PropertyDefinitions:
<extToolkit:PropertyGrid AutoGenerateProperties="False" SelectedObject="{Binding ActiveDataPoint}" PropertyDefinitions="{Binding ActiveDataPoint.Properties}">
Run Code Online (Sandbox Code Playgroud)
问题是OnSelectedObjectChanged从依赖项属性触发,并且在该更改的处理程序中它引用了PropertyDefinitions,它被视为null.如果我注释掉OnSelectedObjectChanged处理程序,那么我可以看到调试OnPropertyDefinitionsChanged时调用OnSelectedObjectChanged.
public static readonly DependencyProperty PropertyDefinitionsProperty = DependencyProperty.Register( "PropertyDefinitions", typeof( PropertyDefinitionCollection ), typeof( PropertyGrid ), new UIPropertyMetadata( null, OnPropertyDefinitionsChanged ) );
public PropertyDefinitionCollection PropertyDefinitions
{
get
{
return ( PropertyDefinitionCollection )GetValue( PropertyDefinitionsProperty );
}
set
{
SetValue( PropertyDefinitionsProperty, value );
}
}
private static void OnPropertyDefinitionsChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
Console.Write("I changed!");
}
public static readonly DependencyProperty SelectedObjectProperty = DependencyProperty.Register( "SelectedObject", typeof( object ), typeof( PropertyGrid ), new …Run Code Online (Sandbox Code Playgroud) 我正在为IIS中托管的Wcf服务开发一个新的绑定,我认为我已经完成了所有工作,但事实证明,客户端仅在它定位.Net framework 4.5时工作,如果我将其更改为目标4.6然后当我尝试打开连接时出现以下错误:
System.ServiceModel.Security.MessageSecurityException occurred
HResult=-2146233087
Message=The Identity check failed for the outgoing message. The remote endpoint did not provide a domain name system (DNS) claim and therefore did not satisfied DNS identity 'xxx.domain.local'. This may be caused by lack of DNS or CN name in the remote endpoint X.509 certificate's distinguished name.
Source=System.ServiceModel
StackTrace:
at System.ServiceModel.Security.IdentityVerifier.EnsureIdentity(EndpointAddress serviceReference, AuthorizationContext authorizationContext, String errorString)
Run Code Online (Sandbox Code Playgroud)
如果我除了将测试代码中的目标框架更改回4.5之外什么都不做,那么它可以正常工作.这让我觉得它可能是.Net 4.6中的一个错误,我知道在4.6中有Wcf ssl更改
在第一次机会异常打开的情况下,我看到System.ServiceModel内部引发的以下异常
System.ArgumentNullException occurred
HResult=-2147467261
Message=Value cannot be null.
Parameter name: value
ParamName=value …Run Code Online (Sandbox Code Playgroud) 我有一个使用mstest的单元测试套件,我可以在visual studio中运行,但是当我的部署脚本尝试使用命令行调用mstest运行测试时,它会在测试的一半时间内冻结.这可能是测试中的问题,但是无法在调试器中重现问题,我一直无法找到问题.
到目前为止,我一直无法附加mstest进程以便能够调试问题,因为当我附加和暂停时,我在visual studio中看不到任何内容(没有列出线程,没有已知代码).关于它如何使用appdomains以防止轻易附加到它,有什么奇怪的吗?尝试和排除故障的任何其他好方法是,甚至可以从测试内部执行等效的Console WriteLine,以便mstest将在其运行的控制台窗口中显示它?
我有一个加载子AppDomain的服务,然后启动一个运行在其中的线程.它需要一个AppDomain,因为它动态生成并加载一些代码,我需要能够重新启动它而不会终止整个服务.
因此,在子AppDomain的事件循环中运行一个线程,它通过MarshalByRefObject传递给它的事件,MarshalByRefObject将东西粘在并发队列中.我想停止并卸载子AppDomain并创建一个新的AppDomain.
我可以简单地在子AppDomain上调用Unload,但这将中止所有线程并抛出ThrearAbortException.我怎样才能优雅地把它关掉?如果我使用MarshalByRefObject在子AppDomain中设置一些静态标志,那么主进程如何能够等到它完成卸载?
我有一些示例代码,它显示了它的设置以及如何调用Unload来杀死它,我怎么能修改它以允许正常卸载并且永远不会有多个子AppDomains?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.Security.Permissions;
using System.Reflection;
using System.Threading;
namespace TestAppDomains
{
/// <summary>
/// Calls to methods magically get transfered to the appdomain it was created in because it derives from MarshalByRefObject
/// </summary>
class MarshalProxy : MarshalByRefObject
{
public AppDomain GetProxyAppDomain()
{
return AppDomain.CurrentDomain;
}
public void SayHello()
{
Console.WriteLine("MarshalProxy in AD: {0}", AppDomain.CurrentDomain.FriendlyName);
}
public void RunLoop()
{
try
{
while (true)
{
Console.WriteLine("RunLoop {0} in …Run Code Online (Sandbox Code Playgroud) c# ×8
.net ×2
.net-4.6 ×2
appdomain ×2
performance ×2
sql-server ×2
string ×2
wcf ×2
.net-4.5 ×1
c#-4.0 ×1
c#-6.0 ×1
concurrency ×1
debugging ×1
formatting ×1
go ×1
intellisense ×1
jit ×1
marshalling ×1
mstest ×1
printf ×1
ryujit ×1
ssms ×1
timeout ×1
wpf ×1
wpftoolkit ×1
xaml ×1