clr

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

跟風遠走 提交于 2019-12-04 05:09:10
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? Apparently I can't, according to this post on the microsoft forums: CLR integration in SQL Server 2005 supports only a subset of .NET framework libraries to be references

Firing an event everytime a new method is called

家住魔仙堡 提交于 2019-12-04 04:41:43
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. Try to look into PostSharp and Aspect Oriented Programming Perhaps you should use a profiler to get the information you need? I don't believe that can be done. Rather than write your own logger, may I recommend Log4Net?

Can my .Net app reference two different versions of a .net framework library?

﹥>﹥吖頭↗ 提交于 2019-12-04 04:39:26
Say I have two projects, P4 and P3, targetting .net 4.0 and 3.5 respectively. Each project also has a reference to System.Data. In the case of P4, it will be to System.Data v4.0.0.0 In the case of P3, it will be to System.Data v2.0.0.0 Project P4 also references P3. If P4 is loaded and executed, it uses the .net 4.0 CLR. At runtime, references to System.Data seem to resolve to v4.0 inside both P4 and P3. I can override this by using assemblyBinding redirects, but then both P4 and P3 resolve to v2.0. Is there any way I can configure my application so that P4 uses v4.0 and P3 uses v2.0? Have a

How does the C# garbage collector find objects whose only reference is an interior pointer?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 04:33:17
问题 In C#, ref and out params are, as far as I know, passed by passing only the raw address of the relevant value. That address may be an interior pointer to an element in an array or a field within an object. If a garbage collection occurs, it's possible that the only reference to some object is through one of these interior pointers, as in: using System; public class Foo { public int field; public static void Increment(ref int x) { System.GC.Collect(); x = x + 1; Console.WriteLine(x); } public

Debugging in .NET in Release mode

落花浮王杯 提交于 2019-12-04 03:23:08
问题 Some time ago I've read an article on CLR, where author showed that if a project is compiled in DEBUG mode, before each operator comes a NOP command, thus allowing to debug a code. Nevertheless, today I discovered that we can also debug in release mode as well... Please help to understand the difference. 回答1: You can debug in Release mode to an extent. Debug and Release are simply build configurations (of which you can create many), the real difference is that Debug configuration doesn't

Getting the CLR ID

心已入冬 提交于 2019-12-04 03:15:40
问题 Is there any where to get the CLR ID at runtime for the current application? I am monitoring my system using Performance Monitors and the name used for the instance is: ApplicationName.exe_p4952_r15_ad1 I can get all other parameters programmatically but not the r15 which is the runtime ID of the common language runtime (instance) that executes your code. I noticed it is always 15, but it is best to get it dynamically to avoid complications. 回答1: You can get the whole "suffix", i.e. the part

Weird behaviour of c# compiler due caching delegate

和自甴很熟 提交于 2019-12-04 02:47:30
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(){} public int b(int x) { return OtherMethod(x); } public int b1(int x) { return OtherMethod(x); } }

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

走远了吗. 提交于 2019-12-04 02:40:43
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 GetHashCode as a static method; which avoids the boxing. But System.Enum doesn't provide the static

How to return an nvarchar(max) in a CLR UDF?

你离开我真会死。 提交于 2019-12-04 02:30:19
Assuming following definition: /// <summary> /// Replaces each occurrence of sPattern in sInput with sReplace. This is done /// with the CLR: /// new RegEx(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace). /// The result of the replacement is the return value. /// </summary> [SqlFunction(IsDeterministic = true)] public static SqlString FRegexReplace(string sInput, string sPattern, string sReplace) { return new Regex(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace); } Passing in a nvarchar(max) value for sInput with a length > 4000 will result in the value being truncated

Why does CLR create new class for anonymous method?

家住魔仙堡 提交于 2019-12-04 01:55:54
问题 I am using anonymous functions in my projects no less. And till know I was thinking that, C# compiler generates just a method using the code used for the anonymous method in the same class . But, after decompiling this code in IL, I saw that CLR created a new class. public class Comparer { public delegate int Greater(int a, int b); public int Great(Greater greater, int a, int b) { return greater(a, b); } } static void Main(string[] args) { int valueOfA = 11, valueOfB = 23, valueOfC = 42;