<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" 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:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>C#</title>
        <link>http://geekswithblogs.net/plundberg/category/9772.aspx</link>
        <description>C#</description>
        <language>sv-FI</language>
        <copyright>plundberg</copyright>
        <managingEditor>per.lundberg@ecraft.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Instantiating a Dictionary from a LINQ projection, part 2</title>
            <link>http://geekswithblogs.net/plundberg/archive/2009/04/29/instantiating-a-dictionary-from-a-linq-projection-part-2.aspx</link>
            <description>(This posting is a continuation of &lt;a href="javascript:void(0);/*1240987479017*/"&gt;this&lt;/a&gt; blog posting.)&lt;br /&gt;
&lt;br /&gt;
If you want to implement this the OOP way, here you have the subclass code (which I'll use myself).&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;using System.Collections.Generic;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;// Remember to set this to your proper namespace (or use a using statement in&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;// the class with the LINQ projection)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;namespace MyNamespace&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;{&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    /// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    /// Extension methods for the Dictionary generic class.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    /// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    public class ImprovedDictionary&amp;lt;T1,T2&amp;gt;: Dictionary&amp;lt;T1,T2&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// Add a key/value pair to the dictionary and return the dictionary reference.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// &amp;lt;param name="key"&amp;gt;the key&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// &amp;lt;param name="value"&amp;gt;the value&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// &amp;lt;returns&amp;gt;the dictionary&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        public &lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;ImprovedDictionary&lt;/span&gt;&lt;span style="font-family: Courier New;"&gt;&amp;lt;T1, T2&amp;gt; AddWithReturn(T1 key, T2 value)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            this[key] = value;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            return this;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131563"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131563" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/plundberg/aggbug/131563.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>plundberg</dc:creator>
            <guid>http://geekswithblogs.net/plundberg/archive/2009/04/29/instantiating-a-dictionary-from-a-linq-projection-part-2.aspx</guid>
            <pubDate>Wed, 29 Apr 2009 14:43:40 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/plundberg/comments/131563.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/plundberg/archive/2009/04/29/instantiating-a-dictionary-from-a-linq-projection-part-2.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/plundberg/comments/commentRss/131563.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Instantiating a Dictionary from a LINQ projection</title>
            <link>http://geekswithblogs.net/plundberg/archive/2009/04/29/instantiating-a-dictionary-from-a-linq-projection.aspx</link>
            <description>Ever needed to instantiate a Dictionary from a LINQ projection? It is certainly doable, although not extremely straightforward. My first thought was to try and do this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;var result = from o in ctx.Orders&lt;br /&gt;             where o.ID = OrderID&lt;br /&gt;             select new MyOrderClass&lt;br /&gt;             {&lt;br /&gt;                 ID = o.ID,&lt;br /&gt;                 Created = o.Created,&lt;br /&gt;                 ExtraData = new Dictionary&amp;lt;string,string&amp;gt;().&lt;br /&gt;                     Add("key1", o.Value1).&lt;br /&gt;                     Add("key2", o.Value2")&lt;br /&gt;             };&lt;/pre&gt;
If this would work, it would probably be the most clean-looking solution. The only problem with this though is that the Add() method in the Dictionary class doesn't return the Dictionary object itself... so unfortunately, this makes it unusable from within a LINQ projection.&lt;br /&gt;
&lt;br /&gt;
So, what do we do? If you've done your C# 3.0 homework, the answer should be fairly obvious: An extension method!&lt;br /&gt;
&lt;br /&gt;
Extensions method, albeit not 100% OOP-pure, are a convenient way to be able to "inject" new methods into an existing class. Of course, this is mostly "syntactic sugar". The methods aren't really inserted into the existing class, but the C# compiler lets you call the methods &lt;span style="font-style: italic;"&gt;as if&lt;/span&gt; they were a part of the original class.&lt;br /&gt;
&lt;br /&gt;
When writing this blog posting, I realize that in this specific case, we don't actually have to use an extension method. We could just subclass the Dictionary&amp;lt;string,string&amp;gt;, and add our own method to this subclass. If you want to do it the OOP way, this is preferrable. On the other hand, if you want to practice your C# 3.0 skills, keep reading. :-)&lt;br /&gt;
&lt;br /&gt;
Create a new class, with this content:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;using System.Collections.Generic;&lt;br /&gt;&lt;br /&gt;// Make sure the namespace below is the same for both your extension method class and the class &lt;br /&gt;// where you are writing the LINQ projection, or use a using statement in the latter one.&lt;br /&gt;namespace MyNamespace&lt;br /&gt;{&lt;br /&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// Extension methods for the Dictionary generic class.&lt;br /&gt;    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;    public static class DictionaryExtension&lt;br /&gt;    {&lt;br /&gt;        /// &amp;lt;summary&amp;gt;&lt;br /&gt;        /// Add a key/value pair to the dictionary and return the dictionary reference.&lt;br /&gt;        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;        /// &amp;lt;param name="dictionary"&amp;gt;the dictionary to add the key/value pair to&amp;lt;/param&amp;gt;&lt;br /&gt;        /// &amp;lt;param name="key"&amp;gt;the key&amp;lt;/param&amp;gt;&lt;br /&gt;        /// &amp;lt;param name="value"&amp;gt;the value&amp;lt;/param&amp;gt;&lt;br /&gt;        /// &amp;lt;returns&amp;gt;the dictionary&amp;lt;/returns&amp;gt;&lt;br /&gt;        public static Dictionary&amp;lt;string, string&amp;gt; AddWithReturn(this Dictionary&amp;lt;string, string&amp;gt; dictionary, string key, string value)&lt;br /&gt;        {&lt;br /&gt;            dictionary[key] = value;&lt;br /&gt;            return dictionary;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;
&lt;br /&gt;
That's it. Now, change the above LINQ query to this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;var result = from o in ctx.Orders&lt;br /&gt;             where o.ID = OrderID&lt;br /&gt;             select new MyOrderClass&lt;br /&gt;             {&lt;br /&gt;                 ID = o.ID,&lt;br /&gt;                 Created = o.Created,&lt;br /&gt;                 ExtraData = new Dictionary&amp;lt;string,string&amp;gt;().&lt;br /&gt;                     AddWithReturn("key1", o.Value1).&lt;br /&gt;                     AddWithReturn("key2", o.Value2")&lt;br /&gt;             };&lt;/pre&gt;
&lt;br /&gt;
Convenient, huh? So, when should we use the extension method approach, and when should we adhere to the OOP standard way of doing it? Well, I'd say like this: If we need to do this on different types of dictionaries (with different key/value types), the extension method approach might be better. I'm not sure if you can subclass a generic class (and have the subclass be generic as well). Maybe you can, and if so, this might be the most elegant way to do it.&lt;br /&gt;
&lt;br /&gt;
If you want to do it OOP (which you should strive for, if possible), only use the approach above when you have to (i.e. when subclassing isn't possible, because the parent class is sealed or similar).&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131562"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131562" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/plundberg/aggbug/131562.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>plundberg</dc:creator>
            <guid>http://geekswithblogs.net/plundberg/archive/2009/04/29/instantiating-a-dictionary-from-a-linq-projection.aspx</guid>
            <pubDate>Wed, 29 Apr 2009 14:37:36 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/plundberg/comments/131562.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/plundberg/archive/2009/04/29/instantiating-a-dictionary-from-a-linq-projection.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/plundberg/comments/commentRss/131562.aspx</wfw:commentRss>
        </item>
        <item>
            <title>ASP.NET 3.5/AJAX.NET-enabled datepicker snippet using the ASP:Calendar control</title>
            <link>http://geekswithblogs.net/plundberg/archive/2009/03/24/asp.net-3.5ajaxnet-enabled-datepicker-snippet-using-the-aspcalendar-control.aspx</link>
            <description>Looking for a &lt;span style="font-weight: bold;"&gt;simple&lt;/span&gt; datepicker that uses AJAX.NET (to avoid full-page postbacks), for your date fields? Look no further! I was on the same "hunt", and ended up writing my own code for it (inspired by other examples/code I was looking at).&lt;br /&gt;
&lt;br /&gt;
The code does all the work using ASP:NET, nothing is done using JavaScript. Below is the code for the solution. This could (and should) be made into a UserControl if you need to use in more than one place&lt;br /&gt;
&lt;br /&gt;
In the .aspx file, put this: (As you see, I am referencing a calendar icon here - use your own icon for this)&lt;br /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                &amp;lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                    &amp;lt;ContentTemplate&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                        &amp;lt;asp:TextBox ID="requestedDeliveryDateTextBox" runat="server" Width="100" /&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                        &amp;lt;asp:ImageButton id="imageButton" runat="server" ImageUrl="~/Images/IconCalendar.png" AlternateText="calendar" &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                            OnClick="ImageButton_Click" CausesValidation="false" /&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                        &amp;lt;br /&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                        &amp;lt;div id="calendar" class="calendar" visible="false" runat="server"&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                            &amp;lt;asp:Calendar ID="requestedDeliveryDateCalendar" runat="server" OnSelectionChanged="RequestedDeliveryDateCalendar_SelectionChanged" /&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                        &amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                    &amp;lt;/ContentTemplate&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                &amp;lt;/asp:UpdatePanel&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In the code-behind (aspx.cs file):&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// The calendar icon was clicked.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        protected void ImageButton_Click(object sender, EventArgs eventArgs)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            // Toggle visibility of the calendar.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            calendar.Visible = !calendar.Visible;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// The selected date in the calendar was changed. This method is called via AJAX.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        protected void RequestedDeliveryDateCalendar_SelectionChanged(object sender, EventArgs eventArgs)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            requestedDeliveryDateTextBox.Text = BOMisc.GetDatePart(requestedDeliveryDateCalendar.SelectedDate);&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;&lt;br /&gt;
            // We hide the calendar here. You can disable this hiding by removing the following line.&lt;br /&gt;
            calendar.Visible = false;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;            // Move the focus to the textbox below the calendar, to make things convenient for the user filling in the form.&lt;br /&gt;
            // Remove this line or change it to reference your own control instead.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            someTextBox.Focus();&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
And finally, the .css portion. We don't do very much styling of the actual calendar here, we just place it on top of the rest (the z-index part), with a white background to make sure the stuff below doesn't "shine through". We also make the calendar be absolutely positioned so that it becomes a true "dropdown" calendar (it will appear "on top" of everything else on the page).&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;.calendar&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;{&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    position: absolute;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    width: 250px;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    padding: 5px;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    background-color: White;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    border: 1px solid #858585;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    z-index: 10;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
That's it for now, hope this helps. Happy datepicking! :-&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130348"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130348" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/plundberg/aggbug/130348.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>plundberg</dc:creator>
            <guid>http://geekswithblogs.net/plundberg/archive/2009/03/24/asp.net-3.5ajaxnet-enabled-datepicker-snippet-using-the-aspcalendar-control.aspx</guid>
            <pubDate>Tue, 24 Mar 2009 13:50:02 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/plundberg/comments/130348.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/plundberg/archive/2009/03/24/asp.net-3.5ajaxnet-enabled-datepicker-snippet-using-the-aspcalendar-control.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/plundberg/comments/commentRss/130348.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Trouble getting TargetInvocationException on your ASP.NET web application?`</title>
            <link>http://geekswithblogs.net/plundberg/archive/2009/03/19/trouble-getting-targetinvocationexception-on-your-asp.net-web-application.aspx</link>
            <description>Sometimes, you get pretty unclear exception messages. The message below is one example of such:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;    Exception type: TargetInvocationException &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    Exception message: Exception has been thrown by the target of an invocation. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;    [...some stuff removed...]&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    Stack trace:    at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct&amp;amp; sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object&amp;amp; instance)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.ListView.PerformSelect()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.ListView.CreateChildControls()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Control.EnsureChildControls()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Control.PreRenderRecursiveInternal()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Control.PreRenderRecursiveInternal()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Control.PreRenderRecursiveInternal()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Control.PreRenderRecursiveInternal()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Control.PreRenderRecursiveInternal()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)&lt;/span&gt;&lt;br /&gt;
 &lt;br /&gt;
I mean, this doesn't tell you anything about where &lt;span style="font-weight: bold;"&gt;in your code&lt;/span&gt; the problem occured. Or does it?&lt;br /&gt;
&lt;br /&gt;
Well, actually, it doesn't. But by experience, you can learn that when working on stuff in an ASP.NET context, this &lt;span style="font-style: italic;"&gt;usually&lt;/span&gt; (in my experience) means that the problem was caused by an ObjectDataSource. It might happen with other controls as well, but this is one case where I have seen it.&lt;br /&gt;
&lt;br /&gt;
The ObjectDataSource "invokes" the method on the class you are telling it to get the data from (or perform the update, etc). The problem with this is that the "real" exception is not shown. My guess is that it would be in the "inner" exception in IIS, and this is not shown here, in the event viewer.&lt;br /&gt;
&lt;br /&gt;
Anyway, when debugging the project inside Visual Studio, I still didn't get any exception information (maybe since I have a custom error handler page set up, that could be removed but it turned out not to be necessary). But, what I did get was this:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;'WebDev.WebServer.EXE' (Managed): Loaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\ff657321\e4c5c948\App_Web_vtrilm_y.dll', Symbols loaded.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;'WebDev.WebServer.EXE' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Diagnostics.ServiceModelSink\3.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Diagnostics.ServiceModelSink.dll'&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New; background-color: rgb(255, 255, 255); color: rgb(255, 0, 0);"&gt;A first chance exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.Web.dll&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;A first chance exception of type 'System.Web.HttpUnhandledException' occurred in System.Web.dll&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;A first chance exception of type 'System.Web.HttpUnhandledException' occurred in System.Web.dll&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;The thread 0x2bb4 has exited with code 0 (0x0).&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The red line at least gives you the &lt;span style="font-style: italic;"&gt;name&lt;/span&gt; of the exception, which in this case was enough to lead me to the real cause of the problem.&lt;br /&gt;
&lt;br /&gt;
Anyway, that's all for now!&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130219"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130219" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/plundberg/aggbug/130219.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>plundberg</dc:creator>
            <guid>http://geekswithblogs.net/plundberg/archive/2009/03/19/trouble-getting-targetinvocationexception-on-your-asp.net-web-application.aspx</guid>
            <pubDate>Thu, 19 Mar 2009 18:26:42 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/plundberg/comments/130219.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/plundberg/archive/2009/03/19/trouble-getting-targetinvocationexception-on-your-asp.net-web-application.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/plundberg/comments/commentRss/130219.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>