clr

Is there a way to programmatically get the source file and line number of an arbitrary MemberInfo?

I am writing a code analysis tool that uses reflection to validate a particular code base. When I encounter a type or member of interest I would like to load the symbols and extract the source file and line number where the member or type is defined. Is this possible? If so, how? class SourceInfo { public static SourceInfo GetFrom(M...

How do I find out what CLR i am using?

Is there something available that tells me what .NET version I am using and whether it is .NET 2.0 SP1? Thanks ...

Returning non-printable sybol (enter) to SQL Server from C# via CLR

Hello. I have the following CLR function: [Microsoft.SqlServer.Server.SqlFunction] public static SqlString PrintText(SqlString text) { // Put your code here return new SqlString(text.Value); } And I want to get an enter symbol when passing '\r\n' to it. But insteat I get '\r\n' Could you please tell me w...

Why is String.Concat not optimized to StringBuilder.Append?

OK, so concatenations of constant string expressions are optimized by the compiler into one string. Great. Now with string concatenation of strings only known at runtime, why does the compiler not optimize string concatenation in loops and concatenations of say more than 10 strings to use StringBuilder.Append instead? I mean, it's possi...

Convert array<Byte>^ data to const byte* data - C++/CLR

Hello I am trying to call a function in C from C# though c ++ so basically C# -> C++ - >C In C#, I have byte[] bytes - which reads the information from the file. I am passing the byte array and the size to C++ . In C++ I get the byte array and the size but I am not able to convert to the specific data types. void Image::OpenMemFile(...

CLR dependent assembly resolution at startup

Does CLR try to resolve [not necessarily load] all the dependent assemblies when the program starts up? That is, is the dependent assembly resolution done on demand? Please note that I am not talking about Assembly.Load* [reflective] kind of load. ...

.NET code compilation or complication?

Q1) Why is C# initially compiled to IL and then at runtime JIT complied and run on top of a virtual machine(?). Or is it JIT complied to native machine code? Q2) If the second is true (JIT complied to native machine code), then where is the .NET sandbox the code runs under? Q3) In addition, why is the code compiled to IL in the first ...

Fatal Execution Engine Error (7A097706)(80131506)

I have built a Windows Service using VS 2008 targeting Framework 3.5. When I install and attempt to run the service on my workstation, it crashes with a .NET Framework error with the following details: Event Type: Error Event Source: .NET Runtime Event Category: None Event ID: 1023 Date: 2/5/2010 Time: 11:40:48 AM User:...

Loading managed dll into AppDomain from native c++ code.

Hi, I want to load managed assembly into the AppDomain from native c++ code. If it worth something the native code is a CLR profiler so I get notification each time AppDomain is created. ...

Literals and implicit narrowing conversions

hi a) Shouldn’t the following assignment cause an error, since number 100 is a literal of type int and since compiler doesn’t allow implicit narrowing conversions? byte b = 100; b) If compiler doesn’t complain about implicit narrowing conversion from int literal to type byte, then why doesn’t it also allow an implicit narrowing co...

When passing a managed byte[] array through PInvoke to be filled in by Win32, does it need to be pinned?

Suppose you're calling a Win32 function that will fill in your byte array. You create an array of size 32, empty. Then pass it in to the Win32 function to be filled int, and use it later in your managed code. Does there exist the chance that the byte array might be moved or overwritten in between the time it was allocated and it is fille...

Strange Message about threads in C#

Hello, I have a program that I run and in the middle I get this message: Managed Debugging Assistant 'ContextSwitchDeadlock' has detected a problem in 'C:\Documents and Settings\Lena G\My Documents\SchoolStuff\IR Information\Home Work\FianlProject\finalProject\finalProject\bin\Debug\finalProject.vshost.exe'. Additional Information: The...

CLR JIT optimizations violates causality?

I was writing an instructive example for a colleague to show him why testing floats for equality is often a bad idea. The example I went with was adding .1 ten times, and comparing against 1.0 (the one I was shown in my introductory numerical class). I was surprised to find that the two results were equal (code + output). float @float =...

Based on what precedence rules is a[x].SomeMember evaluated as (a[x]).SomeMember and not…?

a) Both dot operator ( a.x ) and index operator ( a[x] ) have the same level of precedence. So based on what precedence rules is an expression a[x].SomeMember evaluated as (a[x]).SomeMember and not as (a.SomeMember )[x]? b) Is casting operator an unary operator ( and thus has lower precedence than dot operator ) and for that reason is a...

How is an array type declaration 'new int[10][]' evaluated?

a) How is an array type declaration new int[10][] evaluated? Is it evaluated as (new int[10])[] or as (new int[10][]) or …? b) I’m not sure how to ask this: I know statement int[][] i = (new int[10])[] would give us compiler error. But assuming compiler wouldn’t report an error, what kind of array type would compiler create based on ...

Fault injection for .NET apps?

I am wondering if anyone knows of tools or techniques to automatically inject common faults into a running .NET program. Stuff like... Randomly inject an OutOfMemoryException upon allocation Randomly inject FileNotFoundException upon trying to access a files Randomly inject IO or Network exceptions upon using a socket. So I'm really...

Returning table with CLR

Hello. I want to write an CLR procedure which takes a text and returns a table with all the words in this text. But I can't figure out how to return a table. Could you please tell me it? [Microsoft.SqlServer.Server.SqlFunction] public static WhatTypeShouldIWriteHere Function1(SqlString str) { string[] words = Regex.Sp...

Can WPF apps be compiled to native code?

I know there are tools like Salamander that can compile a .NET WinForms apps to fully native code with no need for the CLR/.NET Framework to be on a machine. Is this possible for WPF apps as well? ...

.NET: Does CLR automatically introduce basic thread-safety (locks) for heap allocated objects?

I mean for some basic operations, like reads/writes of class attributes. Or, maybe, it introduces some higher level synchronization? ...

Wrap Byte[] in a class to reduce memory overhead

I have large amount of data been passed around in my application as byte[] objects. Which is also turing out to be memory problems in a lot of cases. What about if i wrap byte[] in a class like [Serializable] public class MyClass { public byte[] Data { get; set; } } Do you guys think i would gain any performance becoz now a referenc...