clr

Firing an event everytime a new method is called

喜夏-厌秋 提交于 2019-12-05 23:40:53
问题 I am making a logger for a c# application which needs to log the time when each method was called each method's execution time. I can do this by calling my own EventLogger.LogMethodCall method at the start of every method, but I was wondering if there was a way to make the CLR fire an event every time a new method is called so I wouldn't have to manually call my method. Thanks. 回答1: Try to look into PostSharp and Aspect Oriented Programming 回答2: Perhaps you should use a profiler to get the

How to reference GAC assemblies when integrating a CLR extension into SQL Server

元气小坏坏 提交于 2019-12-05 22:22:52
问题 I've created an assembly for CLR integration in SQL Server 2008. It has one reference to System.Web.Extensions , which is an issue because when I try to add my assembly, I get the following error: Assembly 'system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35.' was not found in the SQL catalog. (Microsoft SQL Server, Error: 6503) How do I get SQL Server to reference the required assembly? 回答1: Apparently I can't, according to this post on the microsoft

How does one retrieve the hash code of an enumeration without boxing it?

左心房为你撑大大i 提交于 2019-12-05 22:03:25
问题 If one has an enumeration stored inside an aggregate type, one might want to include that inside the type's hash code (assuming a typical "multiply by primes" hash function). If one just calls SomeEnum.GetHashCode() , it appears that the JIT boxes the instance, even in release builds. Profiling this shows some 10% of the time of my application spent boxing enumerations inside various GetHashCode functions. Several value types implement IEquatable or similar interfaces, which allows calling

Weird behaviour of c# compiler due caching delegate

与世无争的帅哥 提交于 2019-12-05 21:53:22
问题 Suppose I have following program: static void SomeMethod(Func<int, int> otherMethod) { otherMethod(1); } static int OtherMethod(int x) { return x; } static void Main(string[] args) { SomeMethod(OtherMethod); SomeMethod(x => OtherMethod(x)); SomeMethod(x => OtherMethod(x)); } I cannot understand compiled il code (it uses too extra code). Here is simplified version: class C { public static C c; public static Func<int, int> foo; public static Func<int, int> foo1; static C() { c = new C(); } C(){

Mismatch in object size returned by sos.dll and in-memory process size

戏子无情 提交于 2019-12-05 21:41:59
I have used the following sos command to enumerate all instances of a particular type in a running asp application (hosted on windows xp 4 GB machine). .foreach (obj { !dumpheap -type ::my type:: -short ::start of address space:: ::end of address space:: }) { !objsize ${obj} }. This enumerates all objects of the given type in gc gen2. The object size on an average seems to be around 500 KB and there are around 2000 objects. This alone adds up to around 1 GB of memory whereas my asp-process memory in task manager shows only around 700 MB. One more point is that I haven't considered other loaded

Implementating functional languages for the CLR (Or, papers on the implementation of F#)

不羁岁月 提交于 2019-12-05 20:01:19
Does anyone know of any good papers on the implementation of the F# compiler? I'm trying to generate CIL code for a simple functional language targeting the CLR, but I am struggling with a few aspects. The differences between functional languages and CIL are making it hard to generate well-typed CIL code. I have solutions that work via type erasure, but I'd much rather find a way to generate CIL code that reflects (to at least some extend) the Hindley-Milner type system of my source language (e.g., by generating generic classes). Judging by the generated code from the MS and Mono F# compilers,

Dynamic code execution: String -> Runtime code VB.net

▼魔方 西西 提交于 2019-12-05 19:13:04
I'm trying to execute some code inside a string in runtime. I.E. Dim code As String = "IIf(1 = 2, True, False)" How do i run the code inside code string ? As @ElektroStudios said - the proper way to do this is to use the CodeDom compiler , but this is a bit overkill for something as simple as this. You can sort of cheat and harness the power of a DataColumn Expression So for example: Dim formula = "IIF(Condition = 'Yes', 'Go', 'Stop')" Dim value As String = "Yes" Dim result As String 'add a columns to hold the value Dim colStatus As New DataColumn With colStatus .DataType = System.Type.GetType

What is this CopyPDBs function (from clr.dll) doing?

ぃ、小莉子 提交于 2019-12-05 19:03:04
问题 When using Process Explorer to analyze an ASP.NET MVC application in a production environment running IIS, I've noticed a lot of calls to this CopyPDBs function from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll : All of them are having the exact same stack trace: ntdll.dll!ZwWaitForSingleObject+0xa KERNELBASE.dll!WaitForSingleObjectEx+0x98 clr.dll!GetMetaDataInternalInterface+0x3064a clr.dll!GetMetaDataInternalInterface+0x30732 clr.dll!GetMetaDataInternalInterface+0x306e5 clr.dll

Why does my multithreaded C++ .NET application only crash when executed outside of visual studios?

会有一股神秘感。 提交于 2019-12-05 18:34:58
I have created a very simple C++ .NET application using both managed and unmanaged code to replicate my problem. When the user clicks a button a new thread should spawn and do some time-consuming tasks while calling back to my main thread with status updates. This code compiles and successfully executes from within side of Visual Studios Express 2010. That is, when I click the "play" button, my project builds and executes without crashing. However, if I go to the Release folder where the executable lives and run it the application crashes once the button is clicked. I am compiling with /clr

Fully understanding the .NET versions and backward compatibility

a 夏天 提交于 2019-12-05 18:16:29
问题 I have a .NET 2.0 application and I plan to make a 'smart installer' which checks for the available .NET version on the user's PC and install my specific port for it. I saw that: Windows XP (SP2) comes with .NET 2.0 Windows Vista comes with .NET 3.0 Windows 7 comes with .NET 3.5 Windows 8 comes with .NET 4.5 As far as I know, the only thing that's not backward compatible is the CLR version, which is changed after .NET 4.0. So if I don't want the user to install additional framework just for