clr4.0

Does LINQ cache computed values?

耗尽温柔 提交于 2020-01-14 08:11:09
问题 Suppose I have the following code: var X = XElement.Parse (@" <ROOT> <MUL v='2' /> <MUL v='3' /> </ROOT> "); Enumerable.Range (1, 100) .Select (s => X.Elements () .Select (t => Int32.Parse (t.Attribute ("v").Value)) .Aggregate (s, (t, u) => t * u) ) .ToList () .ForEach (s => Console.WriteLine (s)); What is the .NET runtime actually doing here? Is it parsing and converting the attributes to integers each of the 100 times, or is it smart enough to figure out that it should cache the parsed

How to use Finalize with managed resources?

自闭症网瘾萝莉.ら 提交于 2020-01-05 23:15:12
问题 I'm not 100% clear on how an instance of class A can be defined to exist until after the last instance of class B is finalized. Or in other words, I'd like all B's to call close&dispose methods in A inside the B finalisation... and for that to happen before A itself is finalized. The scenario: A. I've got a managed wrapper for an unmanaged resource. For an analogy, lets call A a file system B. managed resources that refer to A, that in turn have requested an unmanaged resource via the A

Does HyperDescriptor work when built in .NET 4?

杀马特。学长 韩版系。学妹 提交于 2019-12-31 14:46:16
问题 I'm working on a .NET 4 project, and would be able to benefit from the dynamic property access that HyperDescriptor provides, but it doesn't seem to be working properly when built in .NET 4. I downloaded the source from CodeProject, converted the solution an projects to VS2010, and updated the target framework to 4.0. While it builds, and the sample executes correctly, the timings show that dynamic property access with HyperDescriptor is the slowest possible way of getting/setting object

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

Why a machine with .NET 4 installed on it cannot run an exe that targeted .NET 4.5 while if they use the same CLR version?

社会主义新天地 提交于 2019-12-17 16:11:55
问题 In Common Language Runtime (CLR) Microsoft page, it says that both .Net Framework 4 and 4.5 uses the CLR version 4. However in this page (.NET Framework Versions and Dependencies) it writes '.Net Framework version 4.5 Included an updated version of CLR 4' Also writes: ' An executable that targets the .NET Framework 4.5.1 will be blocked from running on a computer that only has the .NET Framework 4.5 installed, and the user will be prompted to install the .NET Framework 4.5.1. In addition,

Using a .NET-2.0-targeted COM DLL in the GAC on a .NET-4-only system

烈酒焚心 提交于 2019-12-12 12:08:10
问题 Greetings again, Following up my previous question, I'm trying to maximize the compatibility of my C#-written Windows Explorer extension. In particular, I'm interested in making sure it works in an environment in which .NET 4 is installed and .NET 3.5 and below are not installed. One would think there's no problem, but apparently it's not so simple... There are two problems. First, non-.NET-4-targeted assemblies flat out will not load with CLR 4 unless they have a .config file that specifies

Can we construct an instance of `OpCode`?

我是研究僧i 提交于 2019-12-10 20:49:21
问题 The .NET Framework 4.0 introduces several items to the Reflection API that range from extremely useful to vital for my work. Among these are protected constructors for Assembly , Module , MethodBody , and LocalVariableInfo and the new CustomAttributeData class. There are a couple items I still need that are quite troublesome to work around. I believe they easily apply to the same [small] group of people would need to extend the types I just listed. This time : I'm looking for a way to

Loading/Executing CLR 2.0 assemblies in CLR 4.0

こ雲淡風輕ζ 提交于 2019-12-10 17:28:17
问题 Can the CLR 4.0 execute CLR 2.0 IL without the need for source code recompilation? 回答1: Here's a nice article explaining different scenarios. In the comments section there's a link to MSDN which provides further information. 来源: https://stackoverflow.com/questions/2628078/loading-executing-clr-2-0-assemblies-in-clr-4-0

How does one create a .NET Expression with NodeType of ExpressionType.Index?

谁说我不能喝 提交于 2019-12-07 15:17:24
问题 I'm writing code that evaluates .NET Expression trees. I'm trying to create a C# 4 test to exercise my handling of an ExpressionType.Index , but I can't figure out how to create that type of expression through a LambdaExpression . No matter what I try, the expression comes out as an ExpressionType.Call or ExpressionType.ArrayIndex . For example: IList<int> myList = new ObservableCollection<int> { 3, 56, 8 }; Expression<Func<int>> myExpression = () => myList[3]; // myExpression.Body.NodeType =

Repercussions of enabling useLegacyV2RuntimeActivationPolicy?

守給你的承諾、 提交于 2019-12-06 18:40:41
问题 For my current project, we're using some CLR 2 based mixed mode assemblies. In order to use these from within a .NET 4 targetted assembly, I know you have to add useLegacyV2RuntimeActivationPolicy=true to the <startup> element within app.config. I understand that this changes the activation policy, causing these mixed-mode assemblies to be loaded using the highest supported version of the CLR. However, are there any side effects to doing this? What potential issues should I watch for when