clr

Multidimensional arrays do not implement IEnumerable<T>, or do they?

谁说我不能喝 提交于 2019-12-01 05:31:22
问题 For the reasons that I still do not understand (see this SO question) multidimensional arrays in CLR do not implement IEnumerable<T> . So the following does not compile: var m = new int[2,2] {{1, 2}, {3, 4}}; var q = from e in m select e; Then how come that this works just fine in VB.NET ? Sub Main() Dim m(,) As Integer = {{1, 2}, {3, 4}} Dim q = From e In m Select e For Each i In q Console.WriteLine(i) Next End Sub Update: The following code works because the C# compiler replaces the foreach

What exactly happens when you run a .NET executable (step by step to the point where the program is loaded and running)?

懵懂的女人 提交于 2019-12-01 05:10:30
问题 When you run a .NET executable, what exactly takes place, step by step in order. My basic understanding is that you run the executable, the CLR does some checking, compiles the CIL it into platform specific code, loads it up along with the specified required dll's (as specified in the manifest(s)) and runs your program. Can someone elaborate on this, down to the "it allocates memory for this and that" level? I would really like to know what is happening from when you double-click on the

Configuring the continuation behaviour of a TaskCompletionSource's Task

*爱你&永不变心* 提交于 2019-12-01 04:50:40
问题 Consider the following code: public Task SomeAsyncMethod() { var tcs = new TaskCompletionSource(); ... do something, NOT setting the TaskCompletionSource... return tcs.Task } public void Callsite1() { await SomeAsyncMethod(); Debug.WriteLine(Thread.CurrentThread.ManagedThreadId); } public void Callsite2() { SomeAsyncMethod().ContinueWith((task) => { Debug.WriteLine(Thread.CurrentThread.ManagedThreadId); }); } At some point in time, the TaskCompletionSource created in SomeAsyncMethod is set on

C# Entity Framework 4 Common Language Runtime detected an invalid program error?

℡╲_俬逩灬. 提交于 2019-12-01 04:06:36
How do you debug/fix a "Common Language Runtime detected an invalid program" error? What exactly does it mean anyway? I have a C# MVC 2 web app that can deployed to two websites that reside on the same IIS 7.5 webserver (x64). One is the live site (deployed using Release configuration), the second is the beta site (deployed using a new Beta configuration created just for this project). The two websites are: Default Website/my_app Beta/my_app On the beta site when selecting a paged list of purchase orders, it throws the "detected an invalid program" exception. The exact same code when run on

How to get current value of EIP in managed code?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 04:05:47
The question seems like a dirty hack you should not do but let me explain first. The ultimate goal is to have method local statics like in C++. void Func() { static methodLocalObject = new ExpensiveThing(); // use methodlocal Object } What has this to do with the instruction pointer? I want to cache data depending on my caller. To make this fast I walk back in the stack to get the address of my caller and use this as unique key for a dictionary to store the data. That would allow to create a reflection based tracer which does not use Reflection every time to get the name of the current method

How can I know the CLR version of a crash dump?

只谈情不闲聊 提交于 2019-12-01 03:58:41
I have a minidump crashed from a .NET application. Is there any way to know the CLR version (e.g. version of mscorwks.dll) of the fault machine (which generates the crash dump) using either Windbg or some other tool? In WinDbg: the easiest way is to use the !eeversion command, but if you want additional info you can use the lm command with the v verbose option for the runtime module mscorwks . If you're on .NET 4 the runtime is called clr , so in that case you need to change the command accordingly. 0:026> lm vm mscorwks start end module name 79e70000 7a3ff000 mscorwks T (no symbols) Loaded

Turn off clr option for header file with std::mutex

为君一笑 提交于 2019-12-01 03:22:25
I have a Visual Studio project that contains files with managed code and files with unmanaged code. The project has the CLR support, but when I add a file where I do not need .NET I simply turn off the /crl option with a right-click on the file: I added a class that has to contain unmanaged code and use std::mutex. // Foo.h class Foo { std::mutex m; } I got the following error after compiling: error C1189: #error : is not supported when compiling with /clr or /clr:pure. The problem is that I do not have the option to turn off the clr for header files (.h), since this is the window when i right

Why does the String class not have a parameterless constructor?

一笑奈何 提交于 2019-12-01 02:58:37
int and object have a parameterless constructor. Why not string ? Greg Update: To provide more information for you. You don't have an empty Constructor with a string , however you do have String.Empty . The reason is because a string is an immutable object every instance of a string you modify is actually creating a new string in memory. For instance: string name = ""; though it is an empty string it will still hold around twenty bytes . Where the string.Empty will only hold around four or eight bytes . So though they mean the same thing, one is more efficient than the other. However I believe

Is it possible to host the CLR in a C program?

北战南征 提交于 2019-12-01 02:47:02
问题 Every example I can find is in C++, but I'm trying to keep my project in C. Is it even possible to host the CLR in a C program? If so, can you point me to an example? 回答1: As the above comments hint, there is a set of COM APIs for hosting the CLR, and you should be able to call these COM APIs from both C and C++. As an example, below is a quick piece of (untested) C code that shows how to start up the CLR and execute a static method of a class in a managed assembly (which takes in a string as

How can I see the source code of System.Math.Sin?

偶尔善良 提交于 2019-12-01 02:37:45
问题 In this link, we can see the source code of System.Math class. But I cannot find the source code of how sine is defined. Is there anything I am missing here? 回答1: The signature of the method is: [System.Security.SecuritySafeCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern double Sin(double a); The extern in the method means it is defined elsewhere. In this case, it will be implemented directly in the