il

Why does my application spend 24% of its life doing a null check?

南楼画角 提交于 2019-11-28 15:18:56
I've got a performance critical binary decision tree, and I'd like to focus this question on a single line of code. The code for the binary tree iterator is below with the results from running performance analysis against it. public ScTreeNode GetNodeForState(int rootIndex, float[] inputs) { 0.2% ScTreeNode node = RootNodes[rootIndex].TreeNode; 24.6% while (node.BranchData != null) { 0.2% BranchNodeData b = node.BranchData; 0.5% node = b.Child2; 12.8% if (inputs[b.SplitInputIndex] <= b.SplitValue) 0.8% node = b.Child1; } 0.4% return node; } BranchData is a field, not a property. I did this to

Are Module initializers supported in Silverlight and Windows Phone 7?

三世轮回 提交于 2019-11-28 12:36:37
问题 If you are willing to manipulate IL .net supports Module Initializers http://blogs.msdn.com/b/junfeng/archive/2005/11/19/494914.aspx http://tech.einaregilsson.com/2009/12/16/module-initializers-in-csharp/ Are Module initializers supported in Silverlight and Windows Phone 7? 回答1: Only C++/CLI supports a module initializer. And that's only indirectly, it uses them to get the CRT started and to get unmanaged variables and objects initialized. You have to write on in IL. I tried, it worked just

Could not load file or assembly 'AssemblyName PublicKeyToken=null' or one of its dependencies

瘦欲@ 提交于 2019-11-28 10:55:13
{"Could not load file or assembly 'AssemblyName, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"AssemblyName, PublicKeyToken=null"} I'm getting the message in question as an InnerException.Message while trying to debug my application after signing the unsigned third-party assemblies it is using. The weird thing is that I have already signed the assembly shown in the message, the one that can't be loaded. What could the problem be here? How can I resolve this? EDIT Editing

Why does generated IL code start with a Nop?

▼魔方 西西 提交于 2019-11-28 08:13:56
I was trawling through some of the IL of one of my assemblies (via ILDasm) and I noticed that all of my methods begin with a nop instruction. Does anyone know why that is? The assembly was compiled in debug mode. Nop instructions do not do anything (i.e have no side effects), but act as a convenient instruction to place a breakpoint. Tip If you need a place for an additional breakpoint for debugging purposes, you can force the inclusion of a Nop in a Debug build by adding a pair of empty braces, e.g. _grid.PreviewMouseRightButtonDown += (sender, e) => { _isRightMouseDown = true; RowColumnIndex

How CLR works when invoking a method of a struct

倾然丶 夕夏残阳落幕 提交于 2019-11-28 07:04:24
I think I've known the answer for a class, just want to confirm my understanding is correct. Let's say I have a ClassA and its instance named a . When a.MethodA() is invoked: (1) CLR find the type of ClassA by the type pointer of a in the heap(the type have been loaded into the heap) (2) Find the MethodA in the type, if not found, go to its base type, until the object class. Maybe my understanding is not quite precise, but I think it's basicly correct(Correct me if it's wrong!). And here comes the question of a simple struct . struct MyStruct { public void MethodA() { } } I have var x = new

MissingManifestResourceException when running tests after building with MSBuild (.mresource has path in manifest)

别说谁变了你拦得住时间么 提交于 2019-11-28 05:29:33
问题 I am having a problem with embedded resources for a C# project on a build server using MSBuild on the command line. The project works just fine when building and running tests in Visual Studio, but when running MSBuild from the command line I get the following problems when running a test: System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure ".Properties.Resources.resources" was correctly

How to pass ctor args in Activator.CreateInstance or use IL?

偶尔善良 提交于 2019-11-28 03:43:34
I need a performance enhanced Activator.CreateInstance() and came across this article by Miron Abramson that uses a factory to create the instance in IL and then cache it. (I've included code below from Miron Abramson's site in case it somehow disappears). I'm new to IL Emit code and anything beyond Activator.CreateInstance() for instantiating a class and any help would be much appreciative. My problem is that I need to create an instance of an object that takes a ctor with a parameter. I see there is a way to pass in the Type of the parameter, but is there a way to pass in the value of the

Compiler generated sealed class for delegate keyword contains virtual methods

半城伤御伤魂 提交于 2019-11-27 20:58:14
问题 When delegate keyword is used in C#, the C# compiler automatically generates a class derived from System.MulticastDelegate class. This compiler generated class contains 3 methods as well: Invoke, BeginInvoke and EndInvoke . All these three methods are marked public virtual extern but interestingly the class itself is marked sealed . Virtual methods defined in a sealed class not only strikes as counter-intuitive but are actually illegal in C#. So my question is, is there a specific reason for

A tool for easy IL code inspection

半世苍凉 提交于 2019-11-27 18:45:23
Sometimes I would like to quickly see the IL representation of my code snippets in C#, to understand what exactly happens to various code statements under the hood, like it's done here for example . I know there are ildasm , Reflector , ILSpy , dotPeek and probably quite some other tools available. What I'm wondering here is that if there is any more elegant way from writing some lines of code to seeing the corresponding IL, than compiling your .net code, loading the assembly into one of those programs and finding the code you are curious about. Maybe having a plugin for visual studio, which

Is there a race condition in this common pattern used to prevent NullReferenceException?

夙愿已清 提交于 2019-11-27 15:51:27
问题 I asked this question and got this interesting (and a little disconcerting) answer. Daniel states in his answer (unless I'm reading it incorrectly) that the ECMA-335 CLI specification could allow a compiler to generate code that throws a NullReferenceException from the following DoCallback method. class MyClass { private Action _Callback; public Action Callback { get { return _Callback; } set { _Callback = value; } } public void DoCallback() { Action local; local = Callback; if (local == null