Questions tagged [clr]

The Common Language Runtime (CLR) is a core component of Microsoft's .NET initiative. It is Microsoft's implementation of the Common Language Infrastructure (CLI) standard, which defines an execution environment for program code. In the CLR, code is expressed in a form of bytecode called the Common Intermediate Language (CIL, previously known as MSIL—Microsoft Intermediate Language).

Developers using the CLR write code in a language such as C# or VB.NET. At compile time, a .NET compiler converts such code into CIL code. At runtime, the CLR's just-in-time compiler converts the CIL code into code native to the operating system. Alternatively, the CIL code can be compiled to native code in a separate step prior to runtime by using the Native Image Generator (NGEN). This speeds up all later runs of the software as the CIL-to-native compilation is no longer necessary.

Although some other implementations of the Common Language Infrastructure run on non-Windows operating systems, Microsoft's .NET Framework implementation runs only on Microsoft Windows operating systems.

Books

Articles

3930 questions
1620
votes
6 answers

Try-catch speeding up my code?

I wrote some code for testing the impact of try-catch, but seeing some surprising results. static void Main(string[] args) { Thread.CurrentThread.Priority = ThreadPriority.Highest; Process.GetCurrentProcess().PriorityClass =…
Eren Ersönmez
  • 38,383
  • 7
  • 71
  • 92
438
votes
12 answers

In C#, why is String a reference type that behaves like a value type?

A String is a reference type even though it has most of the characteristics of a value type such as being immutable and having == overloaded to compare the text rather than making sure they reference the same object. Why isn't string just a value…
Davy8
  • 30,868
  • 25
  • 115
  • 173
438
votes
16 answers

Resolving MSB3247 - Found conflicts between different versions of the same dependent assembly

A .NET 3.5 solution ended up with this warning when compiling with msbuild. Sometimes NDepend might help out but in this case it didn't give any further details. Like Bob I ended up having to resort to opening each assembly in ILDASM until I found…
David Gardiner
  • 16,892
  • 20
  • 80
  • 117
417
votes
18 answers

Casting vs using the 'as' keyword in the CLR

When programming interfaces, I've found I'm doing a lot of casting or object type conversion. Is there a difference between these two methods of conversion? If so, is there a cost difference or how does this affect my program? public interface…
Frank V
  • 25,141
  • 34
  • 106
  • 144
345
votes
10 answers

Performance surprise with "as" and nullable types

I'm just revising chapter 4 of C# in Depth which deals with nullable types, and I'm adding a section about using the "as" operator, which allows you to write: object o = ...; int? x = o as int?; if (x.HasValue) { ... // Use x.Value in here } I…
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
244
votes
17 answers

A definitive guide to API-breaking changes in .NET

I would like to gather as much information as possible regarding API versioning in .NET/CLR, and specifically how API changes do or do not break client applications. First, let's define some terms: API change - a change in the publicly visible…
Pavel Minaev
  • 99,783
  • 25
  • 219
  • 289
209
votes
7 answers

What are major differences between C# and Java?

I just want to clarify one thing. This is not a question on which one is better, that part I leave to someone else to discuss. I don't care about it. I've been asked this question on my job interview and I thought it might be useful to learn a bit…
Enes
  • 3,951
  • 3
  • 25
  • 23
172
votes
20 answers

What can you do in MSIL that you cannot do in C# or VB.NET?

All code written in .NET languages compiles to MSIL, but are there specific tasks / operations that you can do only using MSIL directly? Let us also have things done easier in MSIL than C#, VB.NET, F#, j# or any other .NET language. So far we have…
Binoj Antony
  • 15,886
  • 25
  • 88
  • 96
151
votes
3 answers

What's the cause of this FatalExecutionEngineError in .NET 4.5 beta?

The sample code below occurred naturally. Suddenly my code thew a very nasty-sounding FatalExecutionEngineError exception. I spent a good 30 minutes trying to isolate and minimize the culprit sample. Compile this using Visual Studio 2012 as a…
Gleno
  • 16,621
  • 12
  • 64
  • 85
140
votes
2 answers

Why is stack size in C# exactly 1 MB?

Today's PCs have a large amount of physical RAM but still, the stack size of C# is only 1 MB for 32-bit processes and 4 MB for 64-bit processes (Stack capacity in C#). Why the stack size in CLR is still so limited? And why is it exactly 1 MB (4 MB)…
Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
136
votes
2 answers

Making your .NET language step correctly in the debugger

Firstly, I apologize for the length of this question. I am the author of IronScheme. Recently I have been working hard on emitting decent debug info, so that I can use the 'native' .NET debugger. While this has been partly successful, I am running…
leppie
  • 115,091
  • 17
  • 196
  • 297
124
votes
4 answers

Why does struct alignment depend on whether a field type is primitive or user-defined?

In Noda Time v2, we're moving to nanosecond resolution. That means we can no longer use an 8-byte integer to represent the whole range of time we're interested in. That has prompted me to investigate the memory usage of the (many) structs of Noda…
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
123
votes
5 answers

Why Large Object Heap and why do we care?

I have read about Generations and the Large Object Heap, but I still fail to understand what the significance (or benefit) is of having the Large Object Heap? What could have gone wrong (in terms of performance or memory) if the CLR would have just…
Manish Basantani
  • 16,931
  • 22
  • 71
  • 103
121
votes
8 answers

C# 'is' operator performance

I have a program that requires fast performance. Within one of its inner loops, I need to test the type of an object to see whether it inherits from a certain interface. One way to do this would be with the CLR's built-in type-checking…
JubJub
  • 1,485
  • 4
  • 13
  • 14
117
votes
6 answers

How many String objects will be created when using a plus sign?

How many String objects will be created when using a plus sign in the below code? String result = "1" + "2" + "3" + "4"; If it was as below, I would have said three String objects: "1", "2", "12". String result = "1" + "2"; I also know that String…
The Light
  • 26,341
  • 62
  • 176
  • 258
1
2 3
99 100