FAQ Database Discussion Community


Who is responsible for C# memory allocation?

c#,.net,garbage-collection,clr
What part of the .NET framework takes responsibility to allocate memory. Is it GC?

Could not load file or assembly with specific version missing

c#,visual-studio,dependencies,clr,assemblies
In my solution I have a third-party A.dll with another B.dll(Specific version = true) dependency. But I have older version of B.dll and it goes with error: Could not load file or assembly 'B, Version=2.0.0.1, ...' but i have B.dll with little older version (2.0.0.0) so how can i solve...

What does ----s mean in the context of StringBuilder.ToString()?

c#,.net,clr,stringbuilder,reference-source
The Reference Source page for stringbuilder.cs has this comment in the ToString method: if (chunk.m_ChunkLength > 0) { // Copy these into local variables so that they // are stable even in the presence of ----s (hackers might do this) char[] sourceArray = chunk.m_ChunkChars; int chunkOffset = chunk.m_ChunkOffset; int chunkLength...

Distinction between a program and library

.net,clr,cil
Typically the CLR deals with two kinds of binary: A program has a file name ending in .exe, is marked as a program in the PE header, and has an entry point. A library has a file name ending in .dll, is marked as a library in the PE header,...

py2exe fails with “No module named 'clr'” when trying to build exe from script using pythonnet

python,dll,clr,python-3.4,python.net
I created a python script that uses pythonnet. The script is in a file named main.py. When I run the script from the command line (simply typing main.py at the Windows command prompt), the imported pythonnet module clr works fine. But when I try to build an exe I get...

Performance/Memory impact using multiple .NET runtime in one solution

c#,.net,clr
Are there going to be any impacts on performance or memory consumption if the solution I work on (200ish csprojects) is completely built for one .NET CLR version (4.5), but extensively uses 3rd party libraries built for older .NET CLR (2.0/1.1) - in my case Common.Logging 1.2? Studying various materials...

How local variable usage infomation is maintained in .net clr source code

.net,garbage-collection,clr,jit
This great answer explains how GC is able to collect local variables before the method finishes executing: The jitter performs two important duties when it compiles the IL for a method into machine code. ... It also generates a table that describes how the local variables inside the method body...

Why does C# .NET need to be compiled in CLR?

.net,windows,clr
I know JAVA needs to be compiled in an intermediate language because its Virtual Machine can run on every OS. But as much as I know the CLR only runs on Windows. So why does it need a virtual machine? Is it just a performance thing?

Address where an element just past the end of an array would be stored

c#,.net,clr,il
According to ECMA-335: II.14.4.2 Managed pointers Managed pointers (&) can point to an instance of a value type, a field of an object, a field of a value type, an element of an array, or the address where an element just past the end of an array would be stored...

.NET CLR Performance counters missing

windows,clr
on my x64 Windows 8.1 laptop almost all .NET CLR performance counters are missing. Any ideas how to fix this? ...

How does the CLR manages a delegate that is part of an object and the object lifecycle ends?

c#,delegates,clr,lifecycle
I have to do an async callback handler in a distributed system architecture. What happens if I assign a delegate that is part of an object in a certain layer, but the object is a local, will the CLR keep the reference until the functionality that it is handling is...

C# - Converting String array to sbyte** (String[] to sbyte**)

c#,arrays,pointers,clr,command-line-interface
XFunction is a CLI to managed C++ code (wrapper). I want to use XFunction(int,sbyte**) in my C# Project and convert String array to sbyte**. sbyte[][] sbytes = new sbyte[7][]; for (int argCounter = 0; argCounter < 7 ; argCounter++) { //get the byte array byte[] bytes = Encoding.ASCII.GetBytes(argument[argCounter]); //convert it...

Huge performance difference in byte-array access between x64 and x86

c#,performance,x86,64bit,clr
I'm currenty doing micro-benchmarks for a better understanding of clr performance and version issues. The micro-benchmark in question is xoring two byte arrays of each 64 bytes together. I'm always making a reference implementation with safe .net before I try to beat the .net framework implementation with unsafe and so...

Using the new source provided by microsoft would it be possible to create a variant of the CLR?

.net,clr
That is to say, if one was so inclined, could they use the source of CoreCLR and other parts of the .NET Framework that were recently released on GitHub to create a runtime of their own based on the CLR? As in, changing the structure of CIL (e.g. adding opcodes),...

Cutting text to specific length preserving the words

c#,regex,tsql,sql-server-2012,clr
I have the following text: Test some text. Now here is some new realylonglonglong text And I need to cut it to 50 characters but without cutting the words. So, the desire result is: Test some text. Now here is some new ... I am looking only for solution using...

Why the CLS mandates the throwing/catching of Exception derived objects?

c#,c++,.net,clr,cls
The CLS is more restrictive than the CLR, which would allow you to throw and catch any type of objects (even value types). Why? Also what would happen if some non CLS-compliant code threw a non Exception derived object while called by a CLS compliant code? UPDATE Second question answered...

Why is stack size in C# exactly 1 MB?

c#,stack,clr,stack-size
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...

msclr is not being used

c++-cli,clr
So for some reason, msclr is not being used at runtime, I think, for some reason. This is the code: #include <stdlib.h> #include <string.h> #include <msclr\marshal.h> #include "stdafx.h" using namespace System; using namespace msclr::interop; int main() { const char* message = "Test String to Marshal"; String^ result; result = marshal_as<String^>(message);...

CLR System.NullReferenceException when forcing 'Set Next Statement' into 'if' block

c#,.net,c#-4.0,lambda,clr
Background I accept this isn't something that can occur during normal code execution but I discovered it while debugging and thought it interesting to share. I think this is caused by the JIT compiler, but would welcome any further thoughts. I have replicated this issue targeting the 4.5 and 4.5.1...

Can dynamic types be used in a CLR functions?

c#,sql-server,sql-server-2012,clr,sqlclr
I was tasked with writing a CLR function that would mass send emails using Mandrill.Net. After a lot of hurdle with assemblies and other issues I managed to patch most of the function. The only thing left was to add sending those emails (I already had code for that). Unfortunately...

CLR Sync Block Address

c#,heap,clr
When I do: public class Employee { public int exp; } class Program { static void Main(string[] args) { Employee o1 = new Employee(); o1.exp = 3; lock (o1) { //I am here } } } and get memory of o1 (address is 0x022cf940): I realized couple of things mentioned...

Set only second argument type in generic method

c#,.net,generics,clr
I have to create a method for selecting a firts property from collection with the specified type. I have created the method like this (I have removed some parts for the brevity): public static IQueryable<TResult> SelectFirstPropertyWithType<T, TResult>(this IQueryable<T> source) { // Get the first property which has the TResult type...

Will every 'await' operator result in a state machine?

c#,asp.net,async-await,clr
Please consider the following code: public async Task<string> GetString() { //Some code here... var data = await A(); //Some more code... return data; } private async Task<string> A() { //Some code here.. var data = await B(); //manipulating data... return data; } private async Task<string> B() { //Some code here.....

Are the Integer values of framework enums guaranteed to stay the same across .Net versions?

c#,.net,enums,clr
For example, System.Windows.VerticalAlignment is defined like this: // Summary: // Describes how a child element is vertically positioned or stretched within // a parent's layout slot. public enum VerticalAlignment { // Summary: // The element is aligned to the top of the parent's layout slot. Top = 0, // //...

Is this an ok way of calling a C++ function from C#?

c#,c++,interop,clr
I am not super experienced in interlanguage calls between C# and C++. However, I created a VS2013 solution with 2 projects. One project is a C# project. The other project is a C++ project (DLL with CLR). I would like to know if my example code looks ok? The example...

null reference checking in CLR

c#,.net,clr
Some questions about null reference checking by the CLR in C# Consider this: class CS { public int X; } void Foo(CS c) { c.X += 10; } CS c = default(CS); Foo(c); obviously a NullReferenceException is thrown here. Now CS becomes a struct struct CS { public int X;...

Is it possible to implement in C++/CLR an abstract class declared in C#?

c#,c++,clr
Say I have a C# project that defines the following abstract class: public abstract class MyAbstractClass { public abstract void DoIt(string param); } Can I then implement it in C++/CLR as public ref class MyDerivedClass : public MyAbstractClass { public: void DoIt(String^ param) { } }; If the answer is...

Where I can find RemotingServices.CreateTransparentProxy implementation?

c#,wcf,clr,transparentproxy
I'm trying to get insights about how transparent proxy created by WCF ChannelFactory work by digging into source codes. CreateTransparentProxy is marked by extern keyword and [MethodImplAttribute(MethodImplOptions.InternalCall)] attribute which means that I must look implementation inside CLR as long as my understanding goes. In CLR source codes I found only...

Why is the “Process ID” counter in “.NET CLR Memory” category constantly zero?

.net,process,clr,performancecounter,perfmon
Under the ".NET CLR Memory" performance counter category, there is a counter named "Process ID". Any given instance of this counter is supposed to return the Process Id of the Windows process associated with the instance. For my own processes, this counter always has a zero value. Why is that?...

“CLR detected an Invalid Program” when compiling a constructor for List

c#,.net,linq,lambda,clr
I'm running into a strange problem when compiling a lambda expression for a parameterless constructor into a delegate. It works for almost all types that I have tried. Only the List<> is producing a “CLR detected an Invalid Program”. A Collection<> or an inherited class from List<> would not present...

C# System.Object being the ultimate base class

c#,clr,cts,cls
In the msdn spec, I could notice that System.Object is the ultimate base class in .Net. They say that System.ValueType is an abstract class inheriting from System.Object and overrides the methods like Equals, Compare etc... Value types like bool, int etc.. inherit from System.ValueType all the other .net objects inherits...

How to read .net assembly's meta data table

metadata,clr
I'm reading Jeffery Richter's book "CLR via C#". He mentioned the CLR metadata table contains TypeRef and MemberRef section. I want to build a call graph by reading these MemberRef and TypeRef information. What is the best way to do so? After a search, I found somebody read the file...

Use C++ DLL library project in C++ /CLR project

c++,visual-c++,dll,clr
I'm trying to use a unmanaged C++ DLL library project in a C++ /CLR managed wrapper project, but because the unmanaged project uses <thread> the managed project won't build: error C1189: #error : <thread> is not supported when compiling with /clr or /clr:pure. to be clear: the managed project itself...

Does .Net Framework Class libraries in GAC compile each time to Native Code ? Or will it load directly from Native Image Directory ?

.net,clr,gac,jit,native-code
I have been reading the book CLR Via C# and in that by using NGen.exe i learnt that i can compile my assemblies to Native Image. This increases the performance. However the native code is customized to my architecture. When i opened the Native Image Directory C:\Windows\assembly\NativeImages_v4.0.30319_64\System\d6591361d8701ff6eb6a9df223c24684 I found Native...

Obtain non-explicit field offset

c#,.net,reflection,clr
I have the following class: [StructLayout(LayoutKind.Sequential)] class Class { public int Field1; public byte Field2; public short? Field3; public bool Field4; } How can I get the byte offset of Field4 starting from the start of the class data (or object header)? To illustrate: Class cls = new Class(); fixed(int*...

How does .NET efficiently listen for raised events?

c#,.net,events,clr
Does it use some sort of even thread that polls an event queue? Also, does the technique differ depending on the type of event? Some events are raised by the program itself, like a button click, while others are raised externally, like the FileCreated event read by the FileSystemWatcher. Are...

C++/CLR application that starts a process and injects a DLL into it only works when not ran as admin

c#,c++,.net,clr,uac
So, this is an odd one. I have a .NET application that loads a C++/CLR DLL which, in turn, starts a process (Using CreateProcess) and injects a DLL into it (using the remote thread method). However, the newly created process (which is a game) has completely different textures when you...

Missing tag in xmla to deploy assembly

dll,ssas,clr,.net-assembly,cube
I am trying to deploy a custom .NET assembly to my SSAS database. While doing so, I am facing Clr Assembly must have main file specified error and changing the target framework as given in the marked answer didn't solve it. I also checked whether the dll was blocked as...

Performance difference in empty array initialization

c#,.net,arrays,performance,clr
Recently, I've been working in performance/memory optimization and have stucked in the empty array initialization which uses generic method to initialize empty array: Code implementation of generic empty array class: public static class EmptyArray<T> { public static readonly T[] Instance; static EmptyArray() { Instance = new T[0]; } } So,...