.net-4.0

Why did the BeforeFieldInit behavior change in .NET 4?

一世执手 提交于 2019-12-23 11:24:09
问题 In C# 4, the behavior of types without the beforefieldinit flag was changed, so now a type initializer can call before first use of any static field of the class. My questions are why has the C#/.NET team changed that behavior? What is the main reason? Can you show any practical example where this change makes any sense? 回答1: The behaviour has always been within the bounds of what's documented - it's just that it changed from being eager to lazy in .NET 4. I suspect the JIT team managed to

What is the Difference Between Awaiter (GetAwaiter) and ContinueWith

大兔子大兔子 提交于 2019-12-23 10:29:09
问题 In .net 4.0, I use Task.ContinueWith regularly. But then I spotted "task.GetAwaiter()" which seems to have the same purpose. What is the difference? 回答1: If you're targeting .NET 4, you'd use ContinueWith . In general, you wouldn't normally use task.GetAwaiter() . This method exists in order to support the await keyword, and is not part of .NET 4 (it's added in 4.5). This isn't something you'd typically use directly yourself, but instead write it as part of an async method. 来源: https:/

What is the Difference Between Awaiter (GetAwaiter) and ContinueWith

混江龙づ霸主 提交于 2019-12-23 10:28:36
问题 In .net 4.0, I use Task.ContinueWith regularly. But then I spotted "task.GetAwaiter()" which seems to have the same purpose. What is the difference? 回答1: If you're targeting .NET 4, you'd use ContinueWith . In general, you wouldn't normally use task.GetAwaiter() . This method exists in order to support the await keyword, and is not part of .NET 4 (it's added in 4.5). This isn't something you'd typically use directly yourself, but instead write it as part of an async method. 来源: https:/

Registering a custom URI protocol to handle custom resource loading from XAML

折月煮酒 提交于 2019-12-23 10:16:40
问题 I'm working on a project where loose bits of XAML (and some associated IronPython code) will be dynamically loaded and executed by a client application. The client will be using a custom WCF service (and some local caching) to retrieve the XAML, backing scripts, and related resources (icons, images, etc..). I would like to register a custom URI protocol/scheme to make it easier for the developers of the dynamic packages to reference their resources, like the following: <UserControl xmlns=

why does my .NET 2.0 application crash under .NET 4.0 when I use a OleDbDataAdapter object without an OleDBConnection object?

六月ゝ 毕业季﹏ 提交于 2019-12-23 10:16:01
问题 This is a .NET 2.0 application written using VS 2005. It works fine on systems running .NET 2.0, but hard crashes on systems running .NET 4.0. Here's the critical section of the code: string selectCommand1 = .... string connectionString1 = .... using (OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand1, connectionString1)) { try { adapter.Fill(table1); } catch { MessageBox.Show("error"); } } string selectCommand2 = .... string connectionString2 = .... using (OleDbDataAdapter

Lambda expressions for refactor-safe ArgumentException

给你一囗甜甜゛ 提交于 2019-12-23 09:34:31
问题 Update : This is no longer an issue from C# 6, which has introduced the nameof operator to address such scenarios (see MSDN). Note : Refer to “Getting names of local variables (and parameters) at run-time through lambda expressions” for a generalization of this question, as well as some answers. I like the idea of using lambda expressions to create refactor-safe implementations of the INotifyPropertyChanged interface, using code similar to that provided by Eric De Carufel. I’m experimenting

The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty

时间秒杀一切 提交于 2019-12-23 09:34:24
问题 So yesterday i installed PHP and MySQL on my development machine. Since then i get the following error when trying to run one of my .NET projects: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty. It references this line of the Machine.Config: <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral,

Maximum number of items that can be serialized or deserialized in an object graph… with knowtypes

跟風遠走 提交于 2019-12-23 09:33:26
问题 In a WCF 4.0 service we receive a huge amount of data in a generic list. This list object graph is bigger than the 65536 default limit. We are quite used to it, so we have configured the service for being able to getting those big graphs. <serviceBehaviors> <behavior> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> </behavior> </serviceBehaviors> With the above chunk of xml config we have avoided the problem in the past with no problem, but now it doesn't work. The only

How to use XPath 2.0 Methods in .NET 4.0?

北城以北 提交于 2019-12-23 09:27:05
问题 I am using .NET 4.0 and I would like to use XPath 2.0 methods such as ([Matches()][1], [upper-case()][2], [lower-case()][3]) when trying to find elements in a document. Example XPath: "/MyDocument/MyNode[matches(@MyAttribute, 'MyValue', 'i')]" I have tried using: System.Xml.XPath.XPathNavigator.Compile() System.Xml.XmlDocument.SelectNodes() System.Xml.Linq.XDocument.SelectElements() But I basically throw the exception "UndefinedXsltContextException" (or something similar). Can this be done in

MSTest hangs for seemingly no reason

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 09:13:06
问题 <TLDR> Running an MSTest test from the command line hangs without any errors or timeouts whilst "waiting for runs/agents". The reason might be that "there are no runs in the queue", but why this is so I have no idea, because the exact same test runs just fine on another machine. </TLDR> We've recently moved from evaluating TeamCity on a test machine, to installing it in our production environment. After migrating all of our build configurations we suddenly got problems with our MSTest tests: