Posted by: glittermonkey | December 11, 2008

.NET Reflection

Wikipedia describes reflection as “The process by which a computer program can observe and modify its own structure and behavior.”  That’s a fairly generic definition and one that encapsulates a lot of different variations.  My understanding of reflection with respect to C# programming has always been the general idea of being able to dynamically run different chunks of code at runtime based on ‘data’.   

Meta-Information: “stores information such as the name of the contained methods, the name of the class, the name of the parent classes, and/or what the compound statement is supposed to do.  Using this information, as an object is consumed (processed), it can be reflected upon to find out the operations that it supports”

Ok, so we know that metadata or ‘meta-information’ is an important piece of the reflective programming concept.  meta-data is the ‘data’ used to make decisions about which code to run.

The following terms help me with my overall understanding of reflection and its use within the .NET framework…

Reflection: The ability to discover the overall makeup of a type (e.g. class, interface, structure, enumeration, etc.) at runtime.

Dynamic Loading: loading an assembly into memory programmatically at runtime. (think Assembly.Load or Assembly.LoadFrom)

Late Binding: The ability to create objects and invoke their members at runtime without compile time knowledge.  (think myAssembly.CreateInstance())

Attributes: Allows a developer to mark their code base with bits of custom metadata.  Attributes meaningless unless another piece of software finds and uses them via reflection

(Example real world usage – allowing a product to be extensible through the use of third-party plugins.  The extensible application defines an interface for the 3rd party plugins to implement and then these plugins can be dynamically loaded via reflection and late binding by the extensible application at runtime)

Posted by: glittermonkey | October 23, 2008

windbg notes for quick reference

attach to process

.load SOS (assumes dll is in debug tools folder)

.sympath SRV*c:\symbols*http://msdl.microsoft.com/download/symbols

debug -> break

!dumpheap -stat

!dumpheap -type Microsoft.Practices.EnterpriseLibrary.Caching

!dumpheap -mt <methodtable>   (Method Table)

!do <address>   (dump object)

!objsize <address>  (object size)

!dumpheap -stat -min 85000 (everything larget than 85000 == stuff on LOH)

!eeheap -gc  (managed heap size)

Posted by: glittermonkey | August 4, 2008

Configure EnterpriseLibrary Cache without app.config file

The basic approach to configuring the EnterpriseLibrary Cache application block from code, without using an app.config file.

private void TestCacheConfiguration()
{
 CacheManagerFactory cacheFactory = new CacheManagerFactory(GenerateConfiguration());
 cache = cacheFactory.Create(“Sample Cache Manager”);
}

private static DictionaryConfigurationSource GenerateConfiguration()
{
 DictionaryConfigurationSource sections = new DictionaryConfigurationSource();
 sections.Add(CacheManagerSettings.SectionName, GenerateDefaultCacheManagerSettings());
 return sections;
}

private static CacheManagerSettings GenerateDefaultCacheManagerSettings()
{
 CacheManagerSettings settings = new CacheManagerSettings();
 settings.BackingStores.Add(new CacheStorageData(“inMemory”, typeof(NullBackingStore)));
 settings.CacheManagers.Add(
  new CacheManagerData(“Smart Alert Cache Manager”,
   10000,
   1000,
   100,
   ”inMemory”));
 return settings;
}

Posted by: glittermonkey | August 4, 2008

What SQL Server Edition you are running?

Q.  How do you determine if you are running Standard, Enterprise, Developer, etc. edition of SQL Server?

A.  select SERVERPROPERTY(‘productversion’), SERVERPROPERTY(‘productlevel’), SERVERPROPERTY(‘Edition’)

Posted by: glittermonkey | April 3, 2008

No Visual Studio template information found.

I started getting this error in my Visual Studio IDE today: “No Visual Studio template information found.”

 errormessage.jpg

If we take a look in the event log we see additional detail on how to address the problem:

eventlog.jpg

Open a command prompt to the location of devenv.exe and run the command: “devenv.exe /installvstemplates”

cmdprompt.jpg

We are back in business!

The only outstanding question: why did this happen in the first place?

Posted by: glittermonkey | March 19, 2008

GlitterMonkey avatar

Big Wheel

Categories