clr

Can a call to Assembly.Load(byte[]) raise the AppDomain.AssemblyResolve event?

六眼飞鱼酱① 提交于 2019-11-28 22:36:47
问题 Suppose I have a handler for AppDomain.AssemblyResolve event, and in the handler I construct a byte array and invoke the method Assembly.Load(byte[]). Can this method itself cause the AssemblyResolve event to be raised again, and cause my handler to be re-entered? My question is not restricted only to assemblies that can be generated using C# compiler, they can contain abritrary metadata and executable code supported by the CLR. I did some experiments and haven't find any cases when it

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

北城以北 提交于 2019-11-28 22:28:40
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 = chunk.m_ChunkLength; What does this mean? Is ----s something a malicious user might insert into a string to be formatted? In the CoreCLR repository you have a fuller quote: Copy these into local variables so that they are stable even in the presence of race

VB.NET WithEvents keyword behavior - VB.NET compiler restriction?

假如想象 提交于 2019-11-28 21:26:08
I'm working on becoming as familiar with C# as I am with VB.NET (the language used at my workplace). One of the best things about the learning process is that by learning about the other language you tend to learn more about your primary language--little questions like this pop up: According to the sources I've found, and past experience, a field in VB.NET that is declared as WithEvents is capable of raising events. I understand that C# doesn't have a direct equivalent--but my question is: fields without this keyword in VB.NET cannot raise events, is there a way to create this same behavior in

What's the point of MethodImplOptions.InternalCall?

感情迁移 提交于 2019-11-28 21:09:33
Many methods in the BCL are marked with the [MethodImpl(MethodImplOptions.InternalCall)] attribute. This indicates that the "method is implemented within the common language runtime itself". What was the point of designing the framework in this way over having specified explicit CIL instructions that the runtime would be forced to implement? Ultimately, the attribute is creating contractual obligations for the runtime, but in a way that appears to me to be confusing and not immediately obvious. For example, Math.Pow could have been written this way (excuse my informal mixture of C# + IL and

To GC.Collect or not?

那年仲夏 提交于 2019-11-28 21:06:37
问题 Reading this old but classic document Writing High-Performance Managed Applications - A Primer, I came across following statment The GC is self-tuning and will adjust itself according to applications memory requirements. In most cases programmatically invoking a GC will hinder that tuning. "Helping" the GC by calling GC.Collect will more than likely not improve your applications performance I am working with applications that during a given point in time, consumes a lot of memory. When I am

How and when does .NET actually compile code?

时光毁灭记忆、已成空白 提交于 2019-11-28 20:55:15
Let's say you write an app in C#, VB, anything with .NET When you hit build, does it really compile your code? I thought so until I started using redgates reflector on some of my assemblies and saw my code verbatim. I would have expected loops to be unrolled and another plethora of optimizations, instead nothing. So when does the compilation actually happen? I think when it is built, code become IL (Intermediary Language) and when execution occurs, it is loading in the CLR? Is it optimized during CLR only and never at build time? Jorge Córdoba When you compile in VS Your source code is

.NET Free memory usage (how to prevent overallocation / release memory to the OS)

我与影子孤独终老i 提交于 2019-11-28 20:38:16
I'm currently working on a website that makes large use of cached data to avoid roundtrips. At startup we get a "large" graph (hundreds of thouthands of different kinds of objects). Those objects are retrieved over WCF and deserialized (we use protocol buffers for serialization) I'm using redgate's memory profiler to debug memory issues (the memory didn't seem to fit with how much memory we should need "after" we're done initializing and end up with this report Now what we can gather from this report is that: 1) Most of the memory .NET allocated is free (it may have been rightfully allocated

windows form CLR application in Visual studio 2012 RC?

﹥>﹥吖頭↗ 提交于 2019-11-28 20:36:11
quick question, im just trying out VS2012 and trying to make a c++.net app but for the life of me i cant find the option anymore when making a new project. In vs2008 it used to be under new project>visual c++> CLR>windwos form application. Have they removed the option to make c++/CLR application in .net from vs2012? Or is it something i must download? Although Microsoft removed the option to create a C++/CLI Windows Forms application, the template files are still installed. The only thing missing seems to be the .vsz files and a registration in the vcNET.vcdir file. I have recreated these

Potential pitfalls with static constructors in C#

这一生的挚爱 提交于 2019-11-28 20:22:35
问题 My question comes after refactoring a class that contained only static methods to be declared as a static class, and experiencing weird issues when starting the application. I have not performed any thorough investigation but it seems that some call being made from within the static constructor does not complete for some reason. So, I would like to know where there are any pitfalls when using static constructors in C#? More specifically, are there any things that should be avoided at all cost

In .NET 4.0, What is the default implementation of Equals for value types?

倖福魔咒の 提交于 2019-11-28 20:18:12
The two documentation pages seem to contradict on this topic: ValueType.Equals Method says "The default implementation of the Equals method uses reflection to compare the corresponding fields of obj and this instance." Object.Equals Method (Object) says "The default implementation of Equals supports reference equality for reference types, and bitwise equality for value types ." So is it bitwise equality or reflection? I took a glimpse at the source code of ValueType and found a comment saying // if there are no GC references in this object we can avoid reflection // and do a fast memcmp Can