<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>LifeCycle Solutions, LLC - Weblog - C#</title>
    <link>http://blog.lifecycle-solutions.com/</link>
    <description>Technical Writing</description>
    <language>en-us</language>
    <copyright>LifeCycle Solutions, LLC</copyright>
    <lastBuildDate>Thu, 26 Feb 2009 23:27:30 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.2.8279.16125</generator>
    <managingEditor>info@lifecycle-solutions.com</managingEditor>
    <webMaster>info@lifecycle-solutions.com</webMaster>
    <item>
      <trackback:ping>http://blog.lifecycle-solutions.com/Trackback.aspx?guid=881a0cb7-695e-4842-9637-b40c8051106a</trackback:ping>
      <pingback:server>http://blog.lifecycle-solutions.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.lifecycle-solutions.com/PermaLink,guid,881a0cb7-695e-4842-9637-b40c8051106a.aspx</pingback:target>
      <dc:creator>Daniel Root</dc:creator>
      <wfw:comment>http://blog.lifecycle-solutions.com/CommentView,guid,881a0cb7-695e-4842-9637-b40c8051106a.aspx</wfw:comment>
      <wfw:commentRss>http://blog.lifecycle-solutions.com/SyndicationService.asmx/GetEntryCommentsRss?guid=881a0cb7-695e-4842-9637-b40c8051106a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've recently started playing with NDepend again.  This tool is a sort of data
mining utility for your code.  Feed it your assemblies and it can tell you almost
anything about them.  Using a custom query language with a SQL-like syntax, you
can dig into all sorts of metrics and useful information. Out of the box, it ships
with tons of useful queries for common code problems.  
</p>
        <p>
I ran some of our code through it and got dinged on some of the code complexity queries:
</p>
        <p>
 <a href="http://blog.lifecycle-solutions.com/content/binary/WindowsLiveWriter/DeepZoomYourCodeQualityWithNDepend_C61E/image_2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="187" alt="image" src="http://blog.lifecycle-solutions.com/content/binary/WindowsLiveWriter/DeepZoomYourCodeQualityWithNDepend_C61E/image_thumb.png" width="430" border="0" /></a></p>
        <p>
In this case, I had several huge methods that needed to be broken up and optimized. 
Thanks to NDepend's prodding, I spent some time refactoring using ReSharper, and whittled
those down to 0s:
</p>
        <p>
          <a href="http://blog.lifecycle-solutions.com/content/binary/WindowsLiveWriter/DeepZoomYourCodeQualityWithNDepend_C61E/image_4.png">
          </a>
          <a href="http://blog.lifecycle-solutions.com/content/binary/WindowsLiveWriter/DeepZoomYourCodeQualityWithNDepend_C61E/image_8.png">
            <img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="142" alt="image" src="http://blog.lifecycle-solutions.com/content/binary/WindowsLiveWriter/DeepZoomYourCodeQualityWithNDepend_C61E/image_thumb_3.png" width="405" border="0" />
          </a>
        </p>
        <p>
That's helpful, but not nearly everything that NDepend can do.  For example,
the code I'm testing with is involved in some multithreading, so with a little digging
through the docs, I came up with this query to show all methods that change state
(besides property and event setters), but don't use any locks:
</p>
        <p>
WARN IF Count &lt; 0 IN SELECT METHODS WHERE 
<br />
!IsDirectlyUsing "System.Threading.Monitor" AND ( ChangesObjectState OR
ChangesTypeState ) AND 
<br />
!IsConstructor AND !IsClassConstructor AND !IsPropertySetter AND !IsEventAdder AND
!IsEventRemover
</p>
        <p>
This doesn't guarantee thread-safe code, but it definitely helps drill down to potential
problem areas.
</p>
        <p>
Another area I can see us using this in is to provide metrics for our customers. 
Generally they are not concerned with things like Cyclomatic Complexity, but some
simple numbers may be useful.  We use FinalBuilder, so it's possible we could
run NDepend's console utility to roll the numbers into some XML and publish to their
customer wiki.  For example, here's a quick query to spit out the total number
of tests for a project:
</p>
        <p>
SELECT METHODS FROM ASSEMBLIES "TestAssemblyName" WHERE HasAttribute "NUnit.Framework.TestAttribute"
</p>
        <p>
Once we get a customer set up with these metrics, we'll post more about how to automate
that.  Until then, go <a href="http://www.ndepend.com">check out NDepend</a>!
</p>
        <p>
        </p>
        <img width="0" height="0" src="http://blog.lifecycle-solutions.com/aggbug.ashx?id=881a0cb7-695e-4842-9637-b40c8051106a" />
      </body>
      <title>DeepZoom Your Code Quality With NDepend</title>
      <guid isPermaLink="false">http://blog.lifecycle-solutions.com/PermaLink,guid,881a0cb7-695e-4842-9637-b40c8051106a.aspx</guid>
      <link>http://blog.lifecycle-solutions.com/2009/02/26/DeepZoomYourCodeQualityWithNDepend.aspx</link>
      <pubDate>Thu, 26 Feb 2009 23:27:30 GMT</pubDate>
      <description>&lt;p&gt;
I've recently started playing with NDepend again.&amp;#160; This tool is a sort of data
mining utility for your code.&amp;#160; Feed it your assemblies and it can tell you almost
anything about them.&amp;#160; Using a custom query language with a SQL-like syntax, you
can dig into all sorts of metrics and useful information. Out of the box, it ships
with tons of useful queries for common code problems.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
I ran some of our code through it and got dinged on some of the code complexity queries:
&lt;/p&gt;
&lt;p&gt;
&amp;#160;&lt;a href="http://blog.lifecycle-solutions.com/content/binary/WindowsLiveWriter/DeepZoomYourCodeQualityWithNDepend_C61E/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="187" alt="image" src="http://blog.lifecycle-solutions.com/content/binary/WindowsLiveWriter/DeepZoomYourCodeQualityWithNDepend_C61E/image_thumb.png" width="430" border="0" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
In this case, I had several huge methods that needed to be broken up and optimized.&amp;#160;
Thanks to NDepend's prodding, I spent some time refactoring using ReSharper, and whittled
those down to 0s:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.lifecycle-solutions.com/content/binary/WindowsLiveWriter/DeepZoomYourCodeQualityWithNDepend_C61E/image_4.png"&gt;&lt;/a&gt;&lt;a href="http://blog.lifecycle-solutions.com/content/binary/WindowsLiveWriter/DeepZoomYourCodeQualityWithNDepend_C61E/image_8.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="142" alt="image" src="http://blog.lifecycle-solutions.com/content/binary/WindowsLiveWriter/DeepZoomYourCodeQualityWithNDepend_C61E/image_thumb_3.png" width="405" border="0" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
That's helpful, but not nearly everything that NDepend can do.&amp;#160; For example,
the code I'm testing with is involved in some multithreading, so with a little digging
through the docs, I came up with this query to show all methods that change state
(besides property and event setters), but don't use any locks:
&lt;/p&gt;
&lt;p&gt;
WARN IF Count &amp;lt; 0 IN SELECT METHODS WHERE 
&lt;br /&gt;
!IsDirectlyUsing &amp;quot;System.Threading.Monitor&amp;quot; AND ( ChangesObjectState OR
ChangesTypeState ) AND 
&lt;br /&gt;
!IsConstructor AND !IsClassConstructor AND !IsPropertySetter AND !IsEventAdder AND
!IsEventRemover
&lt;/p&gt;
&lt;p&gt;
This doesn't guarantee thread-safe code, but it definitely helps drill down to potential
problem areas.
&lt;/p&gt;
&lt;p&gt;
Another area I can see us using this in is to provide metrics for our customers.&amp;#160;
Generally they are not concerned with things like Cyclomatic Complexity, but some
simple numbers may be useful.&amp;#160; We use FinalBuilder, so it's possible we could
run NDepend's console utility to roll the numbers into some XML and publish to their
customer wiki.&amp;#160; For example, here's a quick query to spit out the total number
of tests for a project:
&lt;/p&gt;
&lt;p&gt;
SELECT METHODS FROM ASSEMBLIES &amp;quot;TestAssemblyName&amp;quot; WHERE HasAttribute &amp;quot;NUnit.Framework.TestAttribute&amp;quot;
&lt;/p&gt;
&lt;p&gt;
Once we get a customer set up with these metrics, we'll post more about how to automate
that.&amp;#160; Until then, go &lt;a href="http://www.ndepend.com"&gt;check out NDepend&lt;/a&gt;!
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&gt;&gt;&lt;img width="0" height="0" src="http://blog.lifecycle-solutions.com/aggbug.ashx?id=881a0cb7-695e-4842-9637-b40c8051106a" /&gt;</description>
      <comments>http://blog.lifecycle-solutions.com/CommentView,guid,881a0cb7-695e-4842-9637-b40c8051106a.aspx</comments>
      <category>C#</category>
      <category>Utilities</category>
      <category>Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://blog.lifecycle-solutions.com/Trackback.aspx?guid=9b6813e5-35e1-4246-8735-7d235617fa9a</trackback:ping>
      <pingback:server>http://blog.lifecycle-solutions.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.lifecycle-solutions.com/PermaLink,guid,9b6813e5-35e1-4246-8735-7d235617fa9a.aspx</pingback:target>
      <dc:creator>Daniel Root</dc:creator>
      <wfw:comment>http://blog.lifecycle-solutions.com/CommentView,guid,9b6813e5-35e1-4246-8735-7d235617fa9a.aspx</wfw:comment>
      <wfw:commentRss>http://blog.lifecycle-solutions.com/SyndicationService.asmx/GetEntryCommentsRss?guid=9b6813e5-35e1-4246-8735-7d235617fa9a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I blogged about <a href="http://www.codeproject.com/KB/codegen/narrange.aspx">NArrange</a> a
while back, but there's a new version out that makes it even better.  It adds
support for organizing code <em>without</em> adding #region directives, which I'm
beginning to <a href="http://www.codinghorror.com/blog/archives/001147.html">agree
are evil</a>.  The end result is a code file organized by member type and access
level (ie fields, properties, private, public, etc), and then alphabetically. 
It includes a configuration tool which lets you set up a configuration file with all
of the rules you want it to follow.  To turn off #region directives open a configuration
file in narrange-config, and change Formatting -&gt; Regions -&gt; Region Style to
'NoDirective'.
</p>
        <img width="0" height="0" src="http://blog.lifecycle-solutions.com/aggbug.ashx?id=9b6813e5-35e1-4246-8735-7d235617fa9a" />
      </body>
      <title>NArrange - Take 2</title>
      <guid isPermaLink="false">http://blog.lifecycle-solutions.com/PermaLink,guid,9b6813e5-35e1-4246-8735-7d235617fa9a.aspx</guid>
      <link>http://blog.lifecycle-solutions.com/2008/07/11/NArrangeTake2.aspx</link>
      <pubDate>Fri, 11 Jul 2008 18:44:20 GMT</pubDate>
      <description>&lt;p&gt;
I blogged about &lt;a href="http://www.codeproject.com/KB/codegen/narrange.aspx"&gt;NArrange&lt;/a&gt; a
while back, but there's a new version out that makes it even better.&amp;nbsp; It adds
support for organizing code &lt;em&gt;without&lt;/em&gt; adding #region directives, which I'm
beginning to &lt;a href="http://www.codinghorror.com/blog/archives/001147.html"&gt;agree
are evil&lt;/a&gt;.&amp;nbsp; The end result is a code file organized by member type and access
level (ie fields, properties, private, public, etc), and then alphabetically.&amp;nbsp;
It includes a configuration tool which lets you set up a configuration file with all
of the rules you want it to follow.&amp;nbsp; To turn off #region directives open a configuration
file in narrange-config, and change Formatting -&amp;gt; Regions -&amp;gt; Region Style to
'NoDirective'.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.lifecycle-solutions.com/aggbug.ashx?id=9b6813e5-35e1-4246-8735-7d235617fa9a" /&gt;</description>
      <comments>http://blog.lifecycle-solutions.com/CommentView,guid,9b6813e5-35e1-4246-8735-7d235617fa9a.aspx</comments>
      <category>C#</category>
    </item>
    <item>
      <trackback:ping>http://blog.lifecycle-solutions.com/Trackback.aspx?guid=f3b61d4a-4aac-4654-9d0c-3d39b2884429</trackback:ping>
      <pingback:server>http://blog.lifecycle-solutions.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.lifecycle-solutions.com/PermaLink,guid,f3b61d4a-4aac-4654-9d0c-3d39b2884429.aspx</pingback:target>
      <dc:creator>Daniel Root</dc:creator>
      <wfw:comment>http://blog.lifecycle-solutions.com/CommentView,guid,f3b61d4a-4aac-4654-9d0c-3d39b2884429.aspx</wfw:comment>
      <wfw:commentRss>http://blog.lifecycle-solutions.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f3b61d4a-4aac-4654-9d0c-3d39b2884429</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've been experimenting with the idea of using System.Reflection.Emit to generate
code from interfaces.  If you're not familiar with this namespace, it contains
classes to generate compiled assemblies programmatically.   Regex uses this
when compiling a regular expression for faster execution.  Instead of parsing
the expression each time, it generates on-the-fly a class that can be used to execute
the expression.  This namespace is also used by Mock Type frameworks such as
RhinoMocks and TypeMock.  Given a base class or interface, these generate on-the-fly
a class that can mimic the base enough to use when unit testing.  I'm sure there
are other places this is used, but suffice it to say this is one of those obscure
corners of the framework that us Morts rarely dig into.  So it's not surprising
that I would run into an obscure error that stumped even Google.
</p>
        <p>
I religiously studied the MSDN examples and wrote code to let me do something like
this:
</p>
        <p>
ICustomer concreteType = CodeGenerator&lt;ICustomer&gt;.GetInstance();
</p>
        <p>
You can see how freaking awesome this could be for component development- I get, at
runtime, a class that implements my interface, but I don't have to wire up goo like
INotifyPropertyChanged, IDataError, property getter/setters, etc.   Depending
on how my tinkering goes, more on the awesomeness later.  The error I was getting
whenever I called typeBuilder.CreateType() was:
</p>
        <p>
System.TypeLoadException: Method 'get_Id' in type 'Customer' from assembly 'TypeAssembly,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation
</p>
        <p>
Except I WAS implementing 'get_Id'.  I copied the code to do it straight from
MSDN! See:
</p>
        <p>
MethodAttributes getSetAttributes = MethodAttributes.Public | 
<br />
MethodAttributes.SpecialName | 
<br />
MethodAttributes.HideBySig;<br />
var getMethodBuilder = typeBuilder.DefineMethod("get_" + propertyOnInterface.Name,<br />
                                               
getSetAttributes,<br />
                                              
propertyOnInterface.PropertyType,<br />
                                              
Type.EmptyTypes); 
</p>
        <p>
ILGenerator getMethodIl = getMethodBuilder.GetILGenerator();<br />
getMethodIl.Emit(OpCodes.Ldarg_0);<br />
getMethodIl.Emit(OpCodes.Ldfld, fieldBuilder);<br />
getMethodIl.Emit(OpCodes.Ret); 
</p>
        <p>
propBuilder.SetGetMethod(getMethodBuilder);
</p>
        <p>
Much googling turned up only a few unrelated posts.  After testing, I discovered
that removing a call to 'AddInterfaceImplementation' fixed the issue- though the resulting
class no longer implemented my interface.  Clearly the interface was generating
some sort of code.  Some more digging, and I figured out the solution:
</p>
        <p>
MethodAttributes getSetAttributes = MethodAttributes.Public | 
<br />
MethodAttributes.SpecialName | 
<br />
MethodAttributes.HideBySig;| <strong>MethodAttributes.Virtual</strong>;
</p>
        <p>
I could be flawed in my understanding here, but apparently, when adding an interface,
.NET treats property get and set accessors sort of like abstract methods.  The
code I was generating <em>did</em> implement 'get_Id', but did not mark it as overriding
the interface's definition.  So, when creating the type, there was the interfaces'
unfinished implementation of 'get_Id', and my completely unrelated 'get_Id'.  
</p>
        <p>
So anyway, hopefully this post will make it into Google and help some other poor guy
who, late one night, finds themselves turning over parts of the framework better left
alone.
</p>
        <img width="0" height="0" src="http://blog.lifecycle-solutions.com/aggbug.ashx?id=f3b61d4a-4aac-4654-9d0c-3d39b2884429" />
      </body>
      <title>Obscure Error: Method 'nnn' in type 'nnn' from assembly 'nnn' does not have an implementation</title>
      <guid isPermaLink="false">http://blog.lifecycle-solutions.com/PermaLink,guid,f3b61d4a-4aac-4654-9d0c-3d39b2884429.aspx</guid>
      <link>http://blog.lifecycle-solutions.com/2008/02/28/ObscureErrorMethodNnnInTypeNnnFromAssemblyNnnDoesNotHaveAnImplementation.aspx</link>
      <pubDate>Thu, 28 Feb 2008 15:41:42 GMT</pubDate>
      <description>&lt;p&gt;
I've been experimenting with the idea of using System.Reflection.Emit to generate
code from interfaces.&amp;nbsp; If you're not familiar with this namespace, it contains
classes to generate compiled assemblies programmatically.&amp;nbsp;&amp;nbsp; Regex uses this
when compiling a regular expression for faster execution.&amp;nbsp; Instead of parsing
the expression each time, it generates on-the-fly a class that can be used to execute
the expression.&amp;nbsp; This namespace is also used by Mock Type frameworks such as
RhinoMocks and TypeMock.&amp;nbsp; Given a base class or interface, these generate on-the-fly
a class that can mimic the base enough to use when unit testing.&amp;nbsp; I'm sure there
are other places this is used, but suffice it to say this is one of those obscure
corners of the framework that us Morts rarely dig into.&amp;nbsp; So it's not surprising
that I would run into an obscure error that stumped even Google.
&lt;/p&gt;
&lt;p&gt;
I religiously studied the MSDN examples and wrote code to let me do something like
this:
&lt;/p&gt;
&lt;p&gt;
ICustomer concreteType = CodeGenerator&amp;lt;ICustomer&amp;gt;.GetInstance();
&lt;/p&gt;
&lt;p&gt;
You can see how freaking awesome this could be for component development- I get, at
runtime, a class that implements my interface, but I don't have to wire up goo like
INotifyPropertyChanged, IDataError, property getter/setters, etc.&amp;nbsp;&amp;nbsp; Depending
on how my tinkering goes, more on the awesomeness later.&amp;nbsp; The error I was getting
whenever I called typeBuilder.CreateType() was:
&lt;/p&gt;
&lt;p&gt;
System.TypeLoadException: Method 'get_Id' in type 'Customer' from assembly 'TypeAssembly,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation
&lt;/p&gt;
&lt;p&gt;
Except I WAS implementing 'get_Id'.&amp;nbsp; I copied the code to do it straight from
MSDN! See:
&lt;/p&gt;
&lt;p&gt;
MethodAttributes getSetAttributes = MethodAttributes.Public | 
&lt;br&gt;
MethodAttributes.SpecialName | 
&lt;br&gt;
MethodAttributes.HideBySig;&lt;br&gt;
var getMethodBuilder = typeBuilder.DefineMethod("get_" + propertyOnInterface.Name,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
getSetAttributes,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
propertyOnInterface.PropertyType,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Type.EmptyTypes); 
&lt;/p&gt;
&lt;p&gt;
ILGenerator getMethodIl = getMethodBuilder.GetILGenerator();&lt;br&gt;
getMethodIl.Emit(OpCodes.Ldarg_0);&lt;br&gt;
getMethodIl.Emit(OpCodes.Ldfld, fieldBuilder);&lt;br&gt;
getMethodIl.Emit(OpCodes.Ret); 
&lt;p&gt;
propBuilder.SetGetMethod(getMethodBuilder);
&lt;/p&gt;
&lt;p&gt;
Much googling turned up only a few unrelated posts.&amp;nbsp; After testing, I discovered
that removing a call to 'AddInterfaceImplementation' fixed the issue- though the resulting
class no longer implemented my interface.&amp;nbsp; Clearly the interface was generating
some sort of code.&amp;nbsp; Some more digging, and I figured out the solution:
&lt;/p&gt;
&lt;p&gt;
MethodAttributes getSetAttributes = MethodAttributes.Public | 
&lt;br&gt;
MethodAttributes.SpecialName | 
&lt;br&gt;
MethodAttributes.HideBySig;| &lt;strong&gt;MethodAttributes.Virtual&lt;/strong&gt;;
&lt;/p&gt;
&lt;p&gt;
I could be flawed in my understanding here, but apparently, when adding an interface,
.NET treats property get and set accessors sort of like abstract methods.&amp;nbsp; The
code I was generating &lt;em&gt;did&lt;/em&gt; implement 'get_Id', but did not mark it as overriding
the interface's definition.&amp;nbsp; So, when creating the type, there was the interfaces'
unfinished implementation of 'get_Id', and my completely unrelated 'get_Id'.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
So anyway, hopefully this post will make it into Google and help some other poor guy
who, late one night, finds themselves turning over parts of the framework better left
alone.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.lifecycle-solutions.com/aggbug.ashx?id=f3b61d4a-4aac-4654-9d0c-3d39b2884429" /&gt;</description>
      <comments>http://blog.lifecycle-solutions.com/CommentView,guid,f3b61d4a-4aac-4654-9d0c-3d39b2884429.aspx</comments>
      <category>C#</category>
      <category>Reflection</category>
    </item>
    <item>
      <trackback:ping>http://blog.lifecycle-solutions.com/Trackback.aspx?guid=5589150e-e518-45ff-a0a3-b74e8ddba757</trackback:ping>
      <pingback:server>http://blog.lifecycle-solutions.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.lifecycle-solutions.com/PermaLink,guid,5589150e-e518-45ff-a0a3-b74e8ddba757.aspx</pingback:target>
      <dc:creator>Daniel Root</dc:creator>
      <wfw:comment>http://blog.lifecycle-solutions.com/CommentView,guid,5589150e-e518-45ff-a0a3-b74e8ddba757.aspx</wfw:comment>
      <wfw:commentRss>http://blog.lifecycle-solutions.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5589150e-e518-45ff-a0a3-b74e8ddba757</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <img style="FLOAT: right; MARGIN: 1em" src="http://blog.lifecycle-solutions.com/content/binary/ReflectorScreenshot.png" border="0" />
        <p>
One of the most useful tools for .NET development is <a href="http://www.aisto.com/roeder/dotnet/">Lutz
Roeder's .NET Reflector</a>, now in version 5.  It uses reflection to peek inside
.NET assemblies and disassembles the IL back into C# or VB code for those times that
you need an in-depth look into <em>any</em> .NET library.  Ever wonder what
the code for System.String looked like? This release adds some really nice
features:
</p>
        <ul>
          <li>
Formatted code comments- doubles as a documentation browser for XML code-commented
members 
</li>
          <li>
'Expand members' in disassembler lets you see code for an entire class at once-
previously you had to look at each method separately. 
</li>
          <li>
New analyzer features shows where classes are instantiated and exposed. 
</li>
          <li>
Search Google or MSDN for a member</li>
        </ul>
        <p>
In addition to helping you debug code, this is also a great learning tool.  What
better way to understand framework development than to peek inside The Framework itself?
</p>
        <p>
 
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://blog.lifecycle-solutions.com/aggbug.ashx?id=5589150e-e518-45ff-a0a3-b74e8ddba757" />
      </body>
      <title>Essential Tool: Lutz Roeder's .NET Reflector v5</title>
      <guid isPermaLink="false">http://blog.lifecycle-solutions.com/PermaLink,guid,5589150e-e518-45ff-a0a3-b74e8ddba757.aspx</guid>
      <link>http://blog.lifecycle-solutions.com/2007/02/20/EssentialToolLutzRoedersNETReflectorV5.aspx</link>
      <pubDate>Tue, 20 Feb 2007 14:49:16 GMT</pubDate>
      <description>&lt;img style="FLOAT: right; MARGIN: 1em" src="http://blog.lifecycle-solutions.com/content/binary/ReflectorScreenshot.png" border=0&gt; 
&lt;p&gt;
One of the most useful tools for .NET development is&amp;nbsp;&lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;Lutz
Roeder's .NET Reflector&lt;/a&gt;, now in version 5.&amp;nbsp; It uses reflection to peek inside
.NET assemblies and disassembles the IL back into C# or VB code for those times that
you need an in-depth look into &lt;em&gt;any&lt;/em&gt;&amp;nbsp;.NET library.&amp;nbsp; Ever wonder&amp;nbsp;what
the code for System.String looked like?&amp;nbsp;This&amp;nbsp;release adds some really&amp;nbsp;nice
features:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Formatted code comments- doubles as a documentation browser for XML code-commented
members 
&lt;li&gt;
'Expand members' in disassembler lets you see code for&amp;nbsp;an entire class at once-
previously you had to look at each method separately. 
&lt;li&gt;
New analyzer features shows where classes are instantiated and exposed. 
&lt;li&gt;
Search Google or MSDN for a member&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
In addition to helping you debug code, this is also a great learning tool.&amp;nbsp; What
better way to understand framework development than to peek inside The Framework itself?
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.lifecycle-solutions.com/aggbug.ashx?id=5589150e-e518-45ff-a0a3-b74e8ddba757" /&gt;</description>
      <comments>http://blog.lifecycle-solutions.com/CommentView,guid,5589150e-e518-45ff-a0a3-b74e8ddba757.aspx</comments>
      <category>ASP.NET</category>
      <category>C#</category>
      <category>Documentation</category>
      <category>Patterns and Practices</category>
      <category>Training</category>
      <category>Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://blog.lifecycle-solutions.com/Trackback.aspx?guid=ec3aa5d6-58fd-4b25-9b7d-6a8e1f69fc90</trackback:ping>
      <pingback:server>http://blog.lifecycle-solutions.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.lifecycle-solutions.com/PermaLink,guid,ec3aa5d6-58fd-4b25-9b7d-6a8e1f69fc90.aspx</pingback:target>
      <dc:creator>Brian Parks</dc:creator>
      <wfw:comment>http://blog.lifecycle-solutions.com/CommentView,guid,ec3aa5d6-58fd-4b25-9b7d-6a8e1f69fc90.aspx</wfw:comment>
      <wfw:commentRss>http://blog.lifecycle-solutions.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ec3aa5d6-58fd-4b25-9b7d-6a8e1f69fc90</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the reasons I prefer C# to VB.Net is for its brevity (not true in
every case, but generally so).  Adding to the list of its syntax shortcuts, C#
2.0 introduces a new operator:  <strong>"??"</strong>, dubbed the "null coalescing"
operator.  For you SQLServer gurus out there, it is somewhat analagous to the
COALESCE() function in Transact-SQL...it evaluates a single value and returns a second
value if the first value is null (note, the type involved must be <a href="http://msdn2.microsoft.com/en-us/library/1t3y8s4s.aspx">nullable</a>).  <br /><font color="#0000ff"><br /><font face="Courier New" size="2">string</font></font><font face="Courier New"><font size="2"> customerName=<font color="#0000ff">null</font></font></font><font size="2"><font face="Courier New">; 
<br /><font color="#0000ff">string</font> newCustomerName=<font color="#0000ff">null</font></font><font face="Courier New">;</font></font></p>
        <p>
          <font face="Courier New">
            <font size="2">
              <font color="#008000">// a long way of assigning
newCustomerName<br /></font>
              <font color="#0000ff">if</font> (customerName == <font color="#0000ff">null</font></font>
          </font>
          <font face="Courier New">
            <font size="2">)
{<br />
   newCustomerName = <font color="#a31515">"Empty"</font></font>
          </font>
          <font face="Courier New">
            <font size="2">;
}<br /><font color="#0000ff">else</font></font>
          </font>
          <font face="Courier New" size="2">{<br />
   newCustomerName = customerName;}<br /><br /></font>
          <font size="2">
            <font face="Courier New">
              <font color="#008000">// a slightly
shorter approach, using ?: "ternary operator"<br /></font>newCustomerName = (customerName == <font color="#0000ff">null</font> ? <font color="#a31515">"Empty"</font></font>
            <font face="Courier New"> :
customerName);</font>
          </font>
        </p>
        <p>
          <font face="Courier New">
            <font size="2">
              <font color="#008000">// much more concise,
using the new ?? operator<br /></font>
            </font>
            <strong>newCustomerName = customerName ?? <font color="#a31515">"Empty"</font>;<br /><br /></strong>
            <font face="Times New Roman">More information </font>
            <a href="http://msdn2.microsoft.com/en-us/library/ms173224.aspx">
              <font face="Times New Roman">here</font>
            </a>
          </font>
          <font face="Times New Roman">.</font>
        </p>
        <img width="0" height="0" src="http://blog.lifecycle-solutions.com/aggbug.ashx?id=ec3aa5d6-58fd-4b25-9b7d-6a8e1f69fc90" />
      </body>
      <title>?? : The "Null Coalescing" Operator in C# 2.0</title>
      <guid isPermaLink="false">http://blog.lifecycle-solutions.com/PermaLink,guid,ec3aa5d6-58fd-4b25-9b7d-6a8e1f69fc90.aspx</guid>
      <link>http://blog.lifecycle-solutions.com/2007/01/04/TheNullCoalescingOperatorInC20.aspx</link>
      <pubDate>Thu, 04 Jan 2007 21:58:11 GMT</pubDate>
      <description>&lt;p&gt;
One of the reasons I prefer C# to VB.Net is&amp;nbsp;for its&amp;nbsp;brevity (not true in
every case, but generally so).&amp;nbsp; Adding to the list of its syntax shortcuts, C#
2.0 introduces a new operator:&amp;nbsp; &lt;strong&gt;"??"&lt;/strong&gt;, dubbed the "null coalescing"
operator.&amp;nbsp; For you SQLServer gurus out there, it is somewhat analagous to the
COALESCE() function in Transact-SQL...it evaluates a single value and returns a second
value if the first value is null (note, the type involved must be &lt;a href="http://msdn2.microsoft.com/en-us/library/1t3y8s4s.aspx"&gt;nullable&lt;/a&gt;).&amp;nbsp;&amp;nbsp;&lt;br&gt;
&lt;font color=#0000ff&gt;
&lt;br&gt;
&lt;font face="Courier New" size=2&gt;string&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=2&gt; customerName=&lt;font color=#0000ff&gt;null&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;&lt;font face="Courier New"&gt;; 
&lt;br&gt;
&lt;font color=#0000ff&gt;string&lt;/font&gt; newCustomerName=&lt;font color=#0000ff&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;&lt;font size=2&gt;&lt;font color=#008000&gt;// a long way of assigning
newCustomerName&lt;br&gt;
&lt;/font&gt;&lt;font color=#0000ff&gt;if&lt;/font&gt; (customerName == &lt;font color=#0000ff&gt;null&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=2&gt;)
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;newCustomerName = &lt;font color=#a31515&gt;"Empty"&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=2&gt;;
}&lt;br&gt;
&lt;font color=#0000ff&gt;else&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New" size=2&gt;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;newCustomerName = customerName;}&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;font size=2&gt;&lt;font face="Courier New"&gt;&lt;font color=#008000&gt;// a slightly shorter
approach, using ?: "ternary operator"&lt;br&gt;
&lt;/font&gt;newCustomerName = (customerName == &lt;font color=#0000ff&gt;null&lt;/font&gt; ? &lt;font color=#a31515&gt;"Empty"&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt; :
customerName);&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;&lt;font size=2&gt;&lt;font color=#008000&gt;// much more concise, using
the new ?? operator&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;strong&gt;newCustomerName = customerName ?? &lt;font color=#a31515&gt;"Empty"&lt;/font&gt;;&lt;br&gt;
&lt;br&gt;
&lt;/strong&gt;&lt;font face="Times New Roman"&gt;More information &lt;/font&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms173224.aspx"&gt;&lt;font face="Times New Roman"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;/font&gt;&lt;font face="Times New Roman"&gt;.&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.lifecycle-solutions.com/aggbug.ashx?id=ec3aa5d6-58fd-4b25-9b7d-6a8e1f69fc90" /&gt;</description>
      <comments>http://blog.lifecycle-solutions.com/CommentView,guid,ec3aa5d6-58fd-4b25-9b7d-6a8e1f69fc90.aspx</comments>
      <category>C#</category>
    </item>
  </channel>
</rss>