clr

How does a struct instance's virtual method get located using its type object in heap?

北城以北 提交于 2021-02-02 09:13:03
问题 below is a code example from a book to show when a value type will be boxed: internal struct Point { private readonly Int32 m_x, m_y; public Point(Int32 x, Int32 y) { m_x = x; m_y = y; } //Override ToString method inherited from System.ValueType public override string ToString() { return String.Format("({0}, {1})", m_x.ToString(), m_y.ToString()); } } class Program { static void Main(string[] args) { Point p1 = new Point(10, 10); p1.ToString(); } } and the author says: In the call to ToString

How does the heap and stack work for instances and members of struct in C#?

我是研究僧i 提交于 2021-02-02 08:38:01
问题 I'm reading a book which says: The variable representing an struct instance doesn’t contain a pointer to an instance; the variable contains the fields of the instance itself. Because the variable contains the instance’s fields, a pointer doesn’t have to be dereferenced to manipulate the instance’s fields. The following code demonstrates how reference types and value types differ class SomeRef { public Int32 x; } struct SomeVal { public Int32 x; } static void ValueTypeDemo() { SomeRef r1 = new

Use encrypted assembly in C# application

旧街凉风 提交于 2021-01-28 18:37:58
问题 I am trying to protect dlls I'm using in my WPF application from a simple copy. My solution is to encrypt the code section of these dlls and decrypt when it loads into my application. There is a working way to do that using Assembly: using (FileStream fs = new FileStream(@"Mydll.dll", FileMode.Open, FileAccess.Read)) { byte[] file = new byte[fs.Length]; fs.Read(file, 0, (int) fs.Length); assemblyCashCode = Assembly.Load(file); Type[] types = assemblyCashCode.GetExportedTypes(); Type t =

Use encrypted assembly in C# application

旧街凉风 提交于 2021-01-28 18:32:42
问题 I am trying to protect dlls I'm using in my WPF application from a simple copy. My solution is to encrypt the code section of these dlls and decrypt when it loads into my application. There is a working way to do that using Assembly: using (FileStream fs = new FileStream(@"Mydll.dll", FileMode.Open, FileAccess.Read)) { byte[] file = new byte[fs.Length]; fs.Read(file, 0, (int) fs.Length); assemblyCashCode = Assembly.Load(file); Type[] types = assemblyCashCode.GetExportedTypes(); Type t =

Which version of the .Net framework is my assembly actually running?

梦想的初衷 提交于 2021-01-27 20:11:41
问题 Just a little setup. We have the .Net framework 3.5, 4.0, 4.5, and 4.6.1 installed. If we build a .Net application or assembly using .Net framework 3.5 and then we set the app.config to run using a single supported runtime of 4.6.1: <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup> Which version of the framework is actually being utilized? This question came from from reading this post: How do I force an application compiled to target .NET Framework 4 to

HasThis & ExplicitThis calling conventions

时光毁灭记忆、已成空白 提交于 2021-01-27 18:40:35
问题 I come across HasThis and ExplicitThis calling conventions on .NET Framework reference source, and thus I begin to wonder: When are they set by compiler? Are there any examples using this combination of calling conventions (in "real world" managed program)? MSDN has described them as: ExplicitThis Specifies that the signature is a function-pointer signature, representing a call to an instance or virtual method (not a static method). If ExplicitThis is set, HasThis must also be set. The first

Is it possible to create System.Int32 in C#?

点点圈 提交于 2021-01-27 04:33:27
问题 If you get under the hood, value types in C# are treated very specially by compiler/CLR. But types internal to CLR are treated even more specially. Here is what I mean: int a = 5; int b = 10; int с = a + b; a.CompareTo(b); You can hover with your mouse over int in Visual Studio and see that actually it is System.Int32 struct. That's OK. Now you can grab ILDasm and look into what System.Int32 is: turns over that it is very simple struct with one field of type int32 (this is int32 internal to

use .Net 2.0 dll in .net 4.0 wpf application

谁都会走 提交于 2021-01-27 04:00:43
问题 I am trying to add a reference to a .Net 2.0 DLL in a WPF application that is targeted to the .Net 4 Framework. I added <startup useLegacyV2RuntimeActivationPolicy="true"> to the app.config file. The WPF app builds fine, but gets a BadImageFormatException at Runtime when trying to access the .Net 2.0 DLL. "An attempt was made to load a program with an incorrect format" This works with a new test WPF project, but does not work on my app. My app uses Entity Framework and MEF. Could these

use .Net 2.0 dll in .net 4.0 wpf application

岁酱吖の 提交于 2021-01-27 03:58:43
问题 I am trying to add a reference to a .Net 2.0 DLL in a WPF application that is targeted to the .Net 4 Framework. I added <startup useLegacyV2RuntimeActivationPolicy="true"> to the app.config file. The WPF app builds fine, but gets a BadImageFormatException at Runtime when trying to access the .Net 2.0 DLL. "An attempt was made to load a program with an incorrect format" This works with a new test WPF project, but does not work on my app. My app uses Entity Framework and MEF. Could these

use .Net 2.0 dll in .net 4.0 wpf application

吃可爱长大的小学妹 提交于 2021-01-27 03:58:15
问题 I am trying to add a reference to a .Net 2.0 DLL in a WPF application that is targeted to the .Net 4 Framework. I added <startup useLegacyV2RuntimeActivationPolicy="true"> to the app.config file. The WPF app builds fine, but gets a BadImageFormatException at Runtime when trying to access the .Net 2.0 DLL. "An attempt was made to load a program with an incorrect format" This works with a new test WPF project, but does not work on my app. My app uses Entity Framework and MEF. Could these