clr

Why is String.GetHashCode() implemented differently in 32-bit and 64-bit versions of the CLR?

戏子无情 提交于 2019-11-29 16:31:35
问题 What are the technical reasons behind the difference between the 32-bit and 64-bit versions of string.GetHashCode()? More importantly, why does the 64-bit version seem to terminate its algorithm when it encounters the NUL character? For example, the following expressions all return true when run under the 64-bit CLR. "\0123456789".GetHashCode() == "\0987654321".GetHashCode() "\0AAAAAAAAA".GetHashCode() == "\0BBBBBBBBB".GetHashCode() "\0The".GetHashCode() == "\0Game".GetHashCode() This

Running a .NET application from a file share without code signing

淺唱寂寞╮ 提交于 2019-11-29 15:42:30
问题 The .NET security model throws security errors whenever a .NET exe is run from a file share. The error does not appear when ran from a local drive. Does anyone know of a way around this without requiring the code to be signed? 回答1: Using CasPol to Fully Trust a Share more answers here: Why does my .NET application crash when run from a network drive? 回答2: Use caspol.exe to assign that file share enough permissions to run your program. 回答3: You might be able to build the application against

Casting int[] to object[]

*爱你&永不变心* 提交于 2019-11-29 15:11:48
I encountered with question: why it's impossible cast int[] to object[] , e.g. object[] o = new int[] { 0, 1, 2 }; Meanwhile I can cast to just object and back to int[] . I'll be glad to hear deep answer. spender Directly from the docs : Array covariance specifically does not extend to arrays of value-types. For example, no conversion exists that permits an int[] to be treated as an object[]. An array of ints or any other value-type is not an array of objects. Value types have different storage characteristics to those of reference types. An array of (reference type) objects holds a list of

What existing CLR hosts do not provide one-to-one mapping between managed and unmanaged threads?

こ雲淡風輕ζ 提交于 2019-11-29 15:10:36
I know I should not rely upon that there is one-to-one mapping between managed and unmanaged threads . From MSDN : An operating-system ThreadId has no fixed relationship to a managed thread, because an unmanaged host can control the relationship between managed and unmanaged threads. Specifically, a sophisticated host can use the Fiber API to schedule many managed threads against the same operating system thread, or to move a managed thread among different operating system threads. In real life though, do such CLR hosts exist? (and if so, what are they?) I just answered a related question, and

CLR sequential structs layout: aligning and size

∥☆過路亽.° 提交于 2019-11-29 14:21:59
All struct s in C# by default are treated as [StructLayout(LayoutKind.Sequential)] -marked value types. So lets take some number of struct s and inspect sizes of this struct s: using System; using System.Reflection; using System.Linq; using System.Runtime.InteropServices; class Foo { struct E { } struct S0 { byte a; } struct S1 { byte a; byte b; } struct S2 { byte a; byte b; byte c; } struct S3 { byte a; int b; } struct S4 { int a; byte b; } struct S5 { byte a; byte b; int c; } struct S6 { byte a; int b; byte c; } struct S7 { int a; byte b; int c; } struct S8 { byte a; short b; int c; } struct

Why “Finalize method should not reference any other objects”?

寵の児 提交于 2019-11-29 14:07:46
I have been pondering why it is recommended that we should not release managed resources inside finalize. If you see the code example at http://msdn.microsoft.com/en-us/library/system.gc.suppressfinalize.aspx , and search for string "Dispose(bool disposing) executes in two distinct scenarios" and read that comment, you will understand what I mean. Only possibility I can think of is that it probably has something to do with the fact that it is not possible to predict when finalizer will get called. Does anyone know the right answer ? thanks, mishal Jon Skeet If you're referencing another object

CLR class memory layout

社会主义新天地 提交于 2019-11-29 13:52:35
问题 What is the memory layout of a CLR class? Coming from a C++ background, the memory layout of a C++ class with virtual functions starts with a v-table pointer, and then the data members of the class follow in memory. Do CLR classes with virtual functions have a v-table pointer? Is this pointer the first field in the class memory layout? Are there any extra fields in a CLR class memory layout in addition to programmers' defined data members? And what do these extra fields represent? 回答1: It's

LNK2022 Error When Using /clr

馋奶兔 提交于 2019-11-29 13:35:49
I'm having a problem linking a C++ project in VS2008 when using the /clr compile option. I am getting the following build errors: Class1.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEA): (0x0200046f). Class1.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEW): (0x02000473). Class2.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEA): (0x0200046f). Class2.obj :

Boost Threads with CLR

隐身守侯 提交于 2019-11-29 13:26:50
问题 Using Visual Studio 2008 and Boost Libraries 1.46.1 I want to compile and link the following with the /CLR flag: #include <boost/thread/thread.hpp> void run() {} int main(int argc, char *argv[]) { boost::thread t(run); } The first error is about a forward-declared dummy-struct in boost::thread. This post works around this by declaring: namespace boost { struct thread::dummy {}; } Sure, I now can compile, but then I get the linker warning Warning 1 warning LNK4248: unresolved typeref token

var in C# - Why can't it be used as a member variable? [duplicate]

爱⌒轻易说出口 提交于 2019-11-29 13:17:39
This question already has an answer here: Implicit typing; why just local variables? 6 answers Why is it not possible to have implicitly-typed variables at a class level within C# for when these variables are immediately assigned? ie: public class TheClass { private var aList = new List<string>(); } Is it just something that hasn't been implemented or is there a conceptual/technical reason for why it hasn't been done? Here's a blog post from Eric that explains the reasoning. 来源: https://stackoverflow.com/questions/2771485/var-in-c-sharp-why-cant-it-be-used-as-a-member-variable