<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tallan&#039;s Technology Blog &#187; General</title>
	<atom:link href="http://blog.tallan.com/category/enterprise-dot-net/general/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tallan.com</link>
	<description>Tallan&#039;s Top Technologists Share Their Thoughts on Today&#039;s Technology Challenges</description>
	<lastBuildDate>Mon, 06 Feb 2012 02:15:46 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Three .NET Best Practices to Keep in Mind</title>
		<link>http://blog.tallan.com/2011/06/29/three-net-best-practices-to-keep-in-mind/</link>
		<comments>http://blog.tallan.com/2011/06/29/three-net-best-practices-to-keep-in-mind/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 19:37:54 +0000</pubDate>
		<dc:creator>Michael Gerety</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Best Practices]]></category>

		<guid isPermaLink="false">http://blog.tallan.com/?p=1173</guid>
		<description><![CDATA[Practice #1: Catch Exceptions at the Highest Possible Level (Tier)
In general, exceptions should be bubbled up to the highest possible level to be caught and processed.  For example, in our project, a search goes through the following logical tiers:
UI -&#62; Services -&#62; Data/SharePoint/Refinement -&#62; Web Services
There are quite a few instances where we’re catching exceptions [...]]]></description>
			<content:encoded><![CDATA[<h1>Practice #1: Catch Exceptions at the Highest Possible Level (Tier)</h1>
<p>In general, exceptions should be bubbled up to the highest possible level to be caught and processed.  For example, in our project, a search goes through the following logical tiers:</p>
<p>UI -&gt; Services -&gt; Data/SharePoint/Refinement -&gt; Web Services</p>
<p>There are quite a few instances where we’re catching exceptions in the Data or Services layer, logging them using common logging components or configurations, and then swallowing the exception one way or another.</p>
<p>This is a bad practice for few reasons:</p>
<ul>
<li>This behavior is not transparent to developers that may be using the DLL but do not have access to the source code.</li>
<li> Logging from lower tier components is generally a bad idea, as it either requires a static logging location embedded in the dll or creates a dependency on the UI to provide pre-determined logging mechanism (i.e. EntLib).   (This can get especially ugly with EntLib, and EntLib Logging and ExceptionHandling blocks generally use named “policies” for handling and logging exceptions, and referencing them from a middle-tier component requires any UI consuming it to implement the exact same logging configuration.</li>
<li>Applications consuming the DLL do not know about or are not given the ability to choose how to react to exceptions in the code.</li>
<li>Swallowing exceptions dilutes the effectiveness of unit tests testing these functions, as tests can’t explicitly test for scenarios that might cause specific exceptions,</li>
<li>Swallowing exceptions can make debugging issues a nightmare (if not impossible) for developers that might consume this middle-tier component and not have access to the source code.</li>
<li>Catch blocks have an inherent performance cost.  Catching exceptions unnecessarily results in unnecessary performance degredataion.</li>
</ul>
<p>There are a few legitimate cases where this best practice might not be followed:</p>
<p><strong>1. </strong><strong>The Exception contains potentially sensitive information</strong></p>
<p>If the exception or exception message contains potentially sensitive information such as user credentials, server names, or any other sensitive information, it likely makes sense to catch the exception, create an exception that accurately describes the issue without the sensitive information, then throw that exception.  <em>Note however, there are very few scenarios where this should not occur at the UI layer.</em></p>
<p><em> </em></p>
<p>2. <strong>The exception is too vague or needs more metadata to be meaningful to the code consuming it.</strong></p>
<p>If the exception by itself is too vague or requires rebadging or augmented metadata to be useful to the code consuming it, it generally makes sense to wrap the exception by creating an exception that allows the original exception to be set as an “InnerException”, and augments the original exception with more information.  This new exception should then be thrown.</p>
<p><strong>3. </strong><strong>The exception that was caught should not affect the execution of the code</strong></p>
<p>If an exception occurs that should not affect the execution of the code, it may be swallowed or ignored in limited cases.  However, exceptions really should not be being thrown unless there is a severe enough issue to potentially interrupt program execution, so I’d suggest reviewing the code throwing the exception you are swallowing in this case.</p>
<p>4. <strong>The Exception Occurs At A Physical Tier Boundary</strong></p>
<p>Your multi-tier applications may not only contain multiple logical tiers, but physical tiers as well.  (for example, your web application may rely on a web service layer on a separate physical server).  While your web service layer may be “middle-tier” as far as the overall application is concerned, exceptions should be caught, processed, and logged at the boundary to that physical tier.  Logging on the machine where the services resides aides in issue resolution, and it gives an opportunity to review exceptions for sensitive information before sending them over the network, where they may be intercepted.</p>
<h1>Practice #2: You Should (Almost Never) Catch System.Exception</h1>
<p>You should almost never write the following:</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<div style="border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt">
<div style="background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd;overflow: auto">
<ol style="background: #ffffff;margin: 0 0 0 2em;padding: 0 0 0 5px">
<li><span style="color: #0000ff">try</span></li>
<li>{</li>
<li> <span style="color: #008000">//Some code here.</span></li>
<li>}</li>
<li><span style="color: #0000ff">catch</span> (System.<span style="color: #2b91af">Exception</span> ex)</li>
<li>{</li>
<li> <span style="color: #008000">//Do something with this exception</span></li>
<li>}</li>
</ol>
</div>
</div>
</div>
<p>This code says that you don’t know what type of exception to expect, so catch them all.</p>
<p>Any exception that the code is not expecting is, by definition, an unexpected or unhandled exception.  <em>You probably want your application to crash (or gracefully exit) with an “Unhandled Exception” message if an unexpected exception occurs! </em>How can you be certain of the stability of the currently running instance of your code if an exception occurred somewhere that you didn’t expect?</p>
<p>Also, catching specific exceptions helps greatly in diagnosing issues, and displaying useful and meaningful error messages to your users.  I think we all know how frustrating a generic error message such as “An error occurred.” can be.</p>
<p>If you think an exception might occur but you don’t know the type, either determine the type and catch it or don’t implement a handler at all!   If you need to throw an exception and there’s not an exception type available that is specific to the error that occurred, create a new one.</p>
<p><strong><em> </em></strong></p>
<p><strong> </strong></p>
<h1>Practice #3: Always Null-Check Objects Returned from a Function Call</h1>
<p>Review the 5 lines of code below.</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<div style="border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt">
<div style="background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd;overflow: auto">
<ol style="background: #ffffff;margin: 0 0 0 2em;padding: 0 0 0 5px">
<li><span style="color: #0000ff">var</span> result = SomeFunctionThatReturnsAnObject();</li>
<li></li>
<li> <span style="color: #0000ff">if</span> (!<span style="color: #2b91af">String</span>.IsNullOrEmpty(result.SomeValue))</li>
<li> {</li>
<li> <span style="color: #008000">//Do Something</span></li>
<li> }</li>
</ol>
</div>
</div>
</div>
<p>What’s wrong with this picture?</p>
<p>If you said <strong><em>Null Reference Exception</em></strong> you’re right.  <strong><em>Never</em></strong>,<strong><em> ever</em></strong> access any member of any object that has been returned from a function without checking for null.  You should <strong><em>never</em></strong> assume that a function will return an instantiated object.</p>
<p><strong><em>Never. </em></strong></p>
<p><em> </em></p>
<p><strong><em>Even if you wrote the function you’re calling.</em> </strong></p>
<p>We all work on projects with multiple developers, and at any given time another developer (or even you) may alter the code and end up returning a null object without realizing that there is some expectation that an instantiated object be returned by some callers.</p>
<p>Taking the extra time to type 15-20 extra characters can mean the difference between stable software and buggy, error-prone code.</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<div style="border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt">
<div style="background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd;overflow: auto">
<ol style="background: #ffffff;margin: 0 0 0 2em;padding: 0 0 0 5px">
<li><span style="color: #0000ff">var</span> result = SomeFunctionThatReturnsAnObject();</li>
<li></li>
<li> <span style="color: #0000ff">if</span> (result != <span style="color: #0000ff">null</span> &amp;&amp; !<span style="color: #2b91af">String</span>.IsNullOrEmpty(result.SomeValue))</li>
<li> {</li>
<li> <span style="color: #008000">//Do Something</span></li>
<li> }</li>
</ol>
</div>
</div>
</div>
<h2>Conclusion</h2>
<p>I wrote this as an e-mail to my team after doing some refactoring and realized that it could be beneficial to a wider audience being that violations of these practices are so common.  I’ve made these mistakes (as I’m sure many of us have) numerous times in the past, so writing this up was a good reminder for me to focus on these points when writing code.</p>
<p>Please feel free to post additions, corrections, questions, and concerns in the comments section below!  The dialogue will benefit all involved!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tallan.com/2011/06/29/three-net-best-practices-to-keep-in-mind/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multi Tenant Architecture via Dependency Injection: Part 3</title>
		<link>http://blog.tallan.com/2010/07/21/multi-tenant-architecture-via-dependency-injection-part-3/</link>
		<comments>http://blog.tallan.com/2010/07/21/multi-tenant-architecture-via-dependency-injection-part-3/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 13:56:01 +0000</pubDate>
		<dc:creator>Nathaniel Engelsen</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Enterprise .NET]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[IoC]]></category>

		<guid isPermaLink="false">http://blog.tallan.com/?p=606</guid>
		<description><![CDATA[Using Ninject and Dependency Injection to enhance your ASP.Net MVC application's Multi-Tenant Application.]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://blog.tallan.com/2010/07/11/multi-tenant-architecture-via-dependency-injection-part-1/">Part 1</a> we discussed web application Multi Tenant Architecture, and briefly discussed how dependency injection can allow us to manage our client customizations.  In <a href="http://blog.tallan.com/2010/07/16/multi-tenant-architecture-via-dependency-injection-part-2/">Part 2</a>, we explored how to wire up Ninject to our ASP.Net MVC application and begin to use its dependency injection features.</p>
<p>In Part 3 we will look at how to utilize Ninject&#8217;s features within our application, along with what kind of functionality can be delivered.  At this point, let&#8217;s revisit our goals from Part #1:</p>
<ol>
<li>dynamically set which service object(s) we are using to perform our application logic</li>
<li>dynamically set which view we are returning</li>
<li>dynamically set which partial views we are using</li>
</ol>
<p>Hypothetically, let our application be a standard transactional system, with header records at the top level and child records below it. Furthermore, let it be an order entry system, so we will need to know about quantities, prices, have subtotals, etc.  Our standard interface can be for Work Orders, and look something like the following:</p>
<p>WorkOrders.aspx:<br />
<img src="http://blog.tallan.com/wp-content/uploads/2010/07/work-orders.png" alt="Sample Work Orders Screenshot" /><br />
We have some header information (Work Order #, etc.) and child records, and the ability to interact with the application to modify child records and add new ones.  At this point, a large customer likes what you&#8217;ve done so far and wants to use your application to manage their shop.  But instead of work orders, they need to use Purchase Orders.  You need to make some major modifications without affecting your existing functionality, so you create a new page and use Ninject to inject the right functionality into the application.  Because we implemented Goal #2 in Part 2, we merely need to modify our source repository to provide the PurchaseOrders.aspx page instead of WorkOrders.aspx.</p>
<p>From CompanyConfigProvider.cs:</p>
<pre class="brush: csharp;">
                // construct our list of Views to be used throughout the application
                // for Goals #2 and #3
                foreach (KeyValuePair&lt;string, string&gt; item in r.getViews())
                {
                    cc.Views.Add(item.Key, item.Value);
                }
</pre>
<p>In addition, because these Purchase Orders are between your client and their own customers and not intra-company Work Orders, there are potential tax implications &#8212; as such, you will need to introduce a method of keeping track of tax when necessary.  It will utilize the existing Purchase Orders functionality, but will need to augment it &#8212; the perfect usage of partial views.</p>
<p>TotalNoTax.ascx:</p>
<pre class="brush: csharp;">
&lt;%@ Control Language=&quot;C#&quot; Inherits=&quot;System.Web.Mvc.ViewUserControl&quot; %&gt;
&lt;p&gt;Non-Profit Tax Code: &lt;input type=&quot;text&quot; name=&quot;taxinfo&quot; /&gt;&lt;/p&gt;
</pre>
<p>TotalWithTax.ascx:</p>
<pre class="brush: csharp;">
&lt;%@ Control Language=&quot;C#&quot; Inherits=&quot;System.Web.Mvc.ViewUserControl&quot; %&gt;
&lt;p&gt;Tax Amount: &lt;input type=&quot;text&quot; id=&quot;taxinfo&quot; name=&quot;taxinfo&quot; /&gt;&lt;/p&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
    function updateTax() {
        var qty = parseFloat($(&quot;#quantity&quot;).val());
        $(&quot;#taxinfo&quot;).val(qty * 150 * .06);
    }

    $(document).ready(function() {
        $(&quot;#quantity&quot;).blur(updateTax);
        $(&quot;#itemType&quot;).change(updateTax);
    });
&lt;/script&gt;
</pre>
<p>Very simply, we will use jQuery to manage a new form element that will include tax when necessary.  Let&#8217;s start putting it all together.  First, let&#8217;s take a look at our controller:</p>
<p>From OrdersController.cs:</p>
<pre class="brush: csharp;">
using {etc}

namespace MultiTenantNinject.Controllers
{
    [HandleError]
    [ProvideCompanyConfig]
    public class OrdersController : Controller
    {
</pre>
<p>As you can see, we inherit from Controller like normal and utilize our ProvideCompanyConfig attribute so that we can be assured we have access to our company config upon rendering.  Let&#8217;s take a look at an Action:</p>
<pre class="brush: csharp;">
        public ActionResult Index()
        {
            ViewResult v = View(_companyConfig.Views[&quot;Order Management&quot;]);

			// add view data items for the header and children;

			// add item to be used for determining if it's a taxable or non-taxable transaction:
			v.ViewData.add(&quot;taxState&quot;,repository.TaxState);

            return v;

        }
</pre>
<p>The first step in rendering the View to the user is ensuring we have an &#8220;Order Management&#8221; entry in our Views collection that establishes what type of major functionality to use.  Our repository would load the config file with a text entry like &#8220;WorkOrders&#8221; or &#8220;PurchaseOrders&#8221; to correspond with &#8220;WorkOrders.aspx&#8221; or &#8220;PurchaseOrders.aspx&#8221;, respectively.  We can set our ViewData at this point, perhaps using a service object (which we will explore soon) and then return the view.  At this point, we have a solid understanding of achieving Goal #2, so let&#8217;s take a look at the few lines necessary to achieve Goal #3:</p>
<p>From PurchaseOrders.aspx:</p>
<pre class="brush: csharp;">
    &lt;% var configSettings = (MultiTenantNinject.Models.ICompanyConfig)ViewData[&quot;companyConfigSettings&quot;];  %&gt;
	&lt;h3&gt;Purchase Orders&lt;/h3&gt;
	... etc ...
    &lt;p&gt;&lt;% Html.RenderPartial(configSettings.Views[string.Format(&quot;Taxes_{0}&quot;,ViewData[&quot;taxState&quot;])]); %&gt;
</pre>
<p>By utilzing the correct entry in our repository for the user&#8217;s state, we can provide the correct tax functionality.  If the company&#8217;s location was in Florida, the repository could provide &#8220;TotalWithTax&#8221; for the &#8220;Taxes_FL&#8221; binding, and &#8220;TotalNoTax&#8221; for the other states.  Obviously we can take it up a level of abstraction and determine whether or not this transaction is taxable in the controller or service object, but this serves as an adequate example of Goal #3.  Lastly, let&#8217;s take a look at our solution for Goal #1 &#8212; it&#8217;s all well and good when we can provide custom front-end functionality for our users, but at some point we will need to implement logic and manipulate data.  Let&#8217;s revisit the module where we inject our services:</p>
<p>From OrderModule.cs:</p>
<pre class="brush: csharp;">
        public override void Load()
        {
            // use reflection to bind a list of types (from our Config's &quot;Bindings&quot; collection)
            // to be used when called upon during injection
            string serviceLocationPrefix = &quot;MultiTenantNinject.Services.&quot;;
            foreach (KeyValuePair&lt;string,string&gt; item in _config.Bindings)
            {
                Bind(Type.GetType(serviceLocationPrefix + item.Key)).To(Type.GetType(serviceLocationPrefix + item.Value));
            }
        }
</pre>
<p>We will need to provide an interface and an implementation for our service(s).  Firstly, the interface:</p>
<pre class="brush: csharp;">
IOrderService.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Web.Mvc;

namespace MultiTenantNinject.Services
{
    public interface IOrderService
    {
        string Process(ViewDataDictionary viewdata);
        DataTable Orders { get; set; }
    }
}
</pre>
<p>and one of the implementations:</p>
<pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.Mvc;

namespace MultiTenantNinject.Services
{
    public class VideoCardOrderService: IOrderService
    {

        #region IService Members

        public string Process(ViewDataDictionary viewdata)
        {
            // here we do transactions pertaining to video cards
            return &quot;Thanks for buying a video card!&quot;;
        }

        #region Orders
        private DataTable _Orders;
        public DataTable Orders
        {
            get
            {
                return _Orders;
            }
            set
            {
                if (_Orders == value) return;
                _Orders = value;
            }
        }
        #endregion

        #endregion

    }
}
</pre>
<p>Service objects can perform most of the functionality of your application, and do not need to be gone over in great detail, as they are as varied as anything else can be.  Suffice it to say that it&#8217;s a standard interface/implementation pattern of development.  Ninject allows you to set it up for injection, as we did in Part 2, so that whenever you call a particular interface for this user a particular implementation is used.  &#8220;VideoCardOrderService&#8221; could easily be &#8220;MotherboardOrderService&#8221; or &#8220;CarOrderService&#8221;:</p>
<p>From OrdersController.cs:</p>
<pre class="brush: csharp;">
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Save()
        {
            _orderService.Process(ViewData);
            return new RedirectResult(&quot;Index&quot;);
        }
</pre>
<p>Our controller, in the end, is completely agnostic of our major functionality, our minor (partial view) functionality, and our domain logic:</p>
<p>OrdersController.cs:</p>
<pre class="brush: csharp;">
using {etc}
using Ninject;

namespace MultiTenantNinject.Controllers
{
    [HandleError]
    [ProvideCompanyConfig]
    public class OrdersController : Controller
    {
        ICompanyConfig _companyConfig;
        IOrderService _orderService;

        public OrdersController(ICompanyConfig pCompanyConfig, IOrderService pOrderService)
        {
            _companyConfig = pCompanyConfig;
            _orderService = pOrderService;
        }

        public OrdersController()
        {
        }

        public ActionResult Index()
        {
            ViewResult v = View(_companyConfig.Views[&quot;Order Management&quot;]);

			// add view data items for the header and children;

			// add item to be used for determining if it's a taxable or non-taxable transaction:
			v.ViewData.add(&quot;taxState&quot;,repository.TaxState);

            return v;
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Save()
        {
            _orderService.Process(ViewData);
            return new RedirectResult(&quot;Index&quot;);
        }
    }
}
</pre>
<p>Thus, the conclusion to our series about utilizing dependency injection within ASP.Net MVC to enhance a Multi-Tenant Architecture.  We can provide service objects without our controller (or anything else) performing logic switches, we can provide major changes to functionality without creating a new codebase, and we can provide in-place customizations truly in-place.  In addition, we&#8217;ve created our application such that we can utilize any kind of data layer or repository and we can utilize testing frameworks to test our code without having to rewrite anything.  And lastly, although it&#8217;s taken a moderate level of effort to get to this point, we can be secure in the knowledge that additional changes can be implemented without affecting existing functionality, and we can easily swap out functionality when the situation arises with very little additional effort.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tallan.com/2010/07/21/multi-tenant-architecture-via-dependency-injection-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multi Tenant Architecture via Dependency Injection: Part 2</title>
		<link>http://blog.tallan.com/2010/07/16/multi-tenant-architecture-via-dependency-injection-part-2/</link>
		<comments>http://blog.tallan.com/2010/07/16/multi-tenant-architecture-via-dependency-injection-part-2/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 12:37:17 +0000</pubDate>
		<dc:creator>Nathaniel Engelsen</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Enterprise .NET]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[IoC]]></category>

		<guid isPermaLink="false">http://blog.tallan.com/?p=570</guid>
		<description><![CDATA[Using Ninject and Dependency Injection to enhance your ASP.Net MVC application's Multi-Tenant Application.]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://blog.tallan.com/2010/07/11/multi-tenant-architecture-via-dependency-injection-part-1/">Part 1</a> we discussed Multi Tenant Architecture as it pertains to web development, along with how dependency injection (specifically with Ninject) can allow us to manage our necessary customizations a bit cleaner.</p>
<p>To start off with, let&#8217;s talk about using Ninject with ASP.Net MVC.  You&#8217;ll need to download the appropriate Ninject version for your .NET framework.  Our example will use Ninject 2.0 with ASP.Net MVC 1.  Download Ninject from the homepage at <a href="http://ninject.org/">http://ninject.org/</a> and visit the <a href="http://ninject.org/learn">dojo</a> and <a href="http://wiki.github.com/ninject/ninject/">github</a> to learn the basics. Ninject will manage our controllers for us (it needs to, so it can monitor for injection points) and so will need to be tightly integrated into our application.  For starters, we&#8217;re going to need to change our global.asax.cs file.  Take a look:</p>
<p>Global.asax.cs:</p>
<pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject.Web.Mvc;
using Ninject;
using Ninject.Modules;
using MultiTenantNinject.Controllers.Components;
using MultiTenantNinject.Models;

namespace MultiTenantNinject
{
  // Inherit from NinjectHttpApplication instead of HttpApplication
  public class MvcApplication : NinjectHttpApplication
  {
    public static void RegisterRoutes(RouteCollection routes)
    {
      routes.IgnoreRoute(&quot;{resource}.axd/{*pathInfo}&quot;);

      // hack for visual studio's web server
      routes.IgnoreRoute(&quot;{*favicon}&quot;, new { favicon = @&quot;(.*/)?favicon.ico(/.*)?&quot; });

      routes.MapRoute(
        &quot;Default&quot;, // Route name
        &quot;{controller}/{action}/{id}&quot;, // URL with parameters
        new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = &quot;&quot; } // Parameter defaults
      );

    }

    // we use OnApplicationStarted, because Ninject is using Application_Started
    protected override void OnApplicationStarted()
    {
      // no big surprise here -- register our routes.
      RegisterRoutes(RouteTable.Routes);
      // register every controller in our application for injection
      RegisterAllControllersIn(Assembly.GetExecutingAssembly());
    }

    // this is called automatically from within the Ninject framework
    protected override IKernel CreateKernel()
    {
      // create a Kernel to manage injections.
      // have the Kernel process our &quot;SetupModule&quot; class
      IKernel k = new StandardKernel(new SetupModule());
      // have the Kernel process our &quot;ConfigModule&quot; class
      k.Load(new ConfigModule());
      // have the Kernel process our &quot;OrderModule class
      // pass an instance of our company config that our ConfigModule calls for
      k.Load(new OrderModule(k.Get&lt;ICompanyConfig&gt;()));
      return k;
    }
  }
}
</pre>
<p>You can see how the CreateKernel() method loads a number of Modules to manage our Dependency Injection.  Let&#8217;s take a look at these modules. The first module to investigate will provide bindings for our .NET MVC dependencies.</p>
<p>SetupModule.cs:</p>
<pre class="brush: csharp;">
using {etc}
using Ninject;
using Ninject.Modules;
using Ninject.Web.Mvc;

namespace MultiTenantNinject.Controllers.Components
{
    // inherit from NinjectModule
    public class SetupModule : NinjectModule
    {
        // NinjectModule is an implementation of the Strategy design pattern and must implement &quot;Load()&quot;
        public override void Load()
        {
            // Let's inject .NET MVC framework dependencies, wow!
            Bind&lt;IFormsAuthentication&gt;()
                .To&lt;FormsAuthenticationService&gt;();
            Bind&lt;IMembershipService&gt;()
                .To&lt;AccountMembershipService&gt;();
            Bind&lt;MembershipProvider&gt;()
                .ToMethod(ctx =&gt; Membership.Provider);
        }
    }
}
</pre>
<p>Our next module will bind the heart of our Multi Tenant Architecture, the &#8220;Company Config&#8221;. This configuration object will be lightweight, cached server-side (ideally once for each company) and will be available during most operations of the page lifecycle.</p>
<p>ICompanyConfig.cs:</p>
<pre class="brush: csharp;">
using {etc}

namespace MultiTenantNinject.Models
{
    public interface ICompanyConfig
    {
        // Task #1 -- provide service objects
        Dictionary&lt;string, string&gt; Bindings { get; set; }
        // Task #2 &amp; #3 -- provide views and partial views
        Dictionary&lt;string, string&gt; Views { get; set; }

        String CompanyName { get; set; }

    }
}
</pre>
<p>ConfigModule.cs:</p>
<pre class="brush: csharp;">
using {etc}

namespace MultiTenantNinject.Controllers.Components
{
    public class ConfigModule : NinjectModule
    {
        public override void Load()
        {
            // Ninject.Activation.Provider is a factory object.
            CompanyConfigProvider Provider = new CompanyConfigProvider(WebConfigurationManager.AppSettings);

            // Bind our service (ICompanyConfig) to its implementation using the
            // aforementioned Provider.  Bind it so that each request uses the same
            // instance of the service.
            Bind&lt;ICompanyConfig&gt;()
                .ToProvider(Provider)
                .InRequestScope();

        }
    }
}
</pre>
<p>Our next module will control the functionality for our example customizations revolving around Purchase Orders.  In practice we could have multiple modules, perhaps one for each functional area of our application, but our single module will serve our purposes here:</p>
<p>OrderModule.cs:</p>
<pre class="brush: csharp;">
using {etc}

namespace MultiTenantNinject.Controllers.Components
{
    public class OrderModule : NinjectModule
    {
        private readonly ICompanyConfig _config;

        // We see our first &quot;Inject&quot; attribute.
        // Here we will take an instance of our company config
        // and later use it to bind our application services
        [Inject]
        public OrderModule(ICompanyConfig companyConfig)
        {
            _config = companyConfig;
        }

        public override void Load()
        {
            // use reflection to bind a list of types (from our Config's &quot;Bindings&quot; collection)
            // to be used when called upon during injection
            string serviceLocationPrefix = &quot;MultiTenantNinject.Services.&quot;;
            foreach (KeyValuePair&lt;string,string&gt; item in _config.Bindings)
            {
                Bind(Type.GetType(serviceLocationPrefix + item.Key)).To(Type.GetType(serviceLocationPrefix + item.Value));
            }
        }
    }
}
</pre>
<p>Let&#8217;s briefly revisit our goals from Part #1:</p>
<ol>
<li>dynamically set which service object(s) we are using to perform our application logic</li>
<li>dynamically set which view we are returning</li>
<li>dynamically set which partial views we are using</li>
</ol>
<p>At this point we can see the pattern unfolding.  We use our Modules to dictate to the Kernel what strategies to use when binding implementations to our services.  We can use reflection, we can use strings and types, and we can use Providers inside of our Modules during binding.  We will be coming back to OrderModule.cs, as that is part of our implementation for Goal #1.  Let us take a look now at our Provider from our ConfigModule:</p>
<p>CompanyConfigProvider.cs:</p>
<pre class="brush: csharp;">
using {etc}
using Ninject.Activation;

namespace MultiTenantNinject.Models
{
    // inherit from Ninject.Activation.Provider
    public class CompanyConfigProvider: Provider&lt;CompanyConfig&gt;
    {
        // these settings are provided by our web.config in this example
        public CompanyConfigProvider(NameValueCollection settings)
        {
            Settings = settings;
        }

        protected NameValueCollection Settings { get; set; }

        // build and return an instance of our CompanyConfig using the specific context
        // IProvider is a Factory that will have its CreateInstance() method called
        // the first time that a CompanyConfig is injected
        protected override CompanyConfig CreateInstance(IContext context)
        {
            // use a caching mechanism to store our company config.  we cannot
            // cache in the Application cache because we have a Multi Tenant Application.
            // we can use Session in a pinch, although depending on your application's traffic,
            // you might need to use something else
            System.Web.SessionState.HttpSessionState Session = HttpContext.Current.Session;
            CompanyConfig cc = null;

            // if we don't have a cached company config:
            if (Session == null || Session[&quot;cc&quot;] == null)
            {
                cc = new CompanyConfig();
                // our repository is extremely unsophisticated, but you should
                // get the idea of how this works.  it may very well be passed in
                // via constructor injection
                MultiTenantNinject.Models.Repository r = new Repository();

                // construct our list of Views to be used throughout the application
                // for Goals #2 and #3
                foreach (KeyValuePair&lt;string, string&gt; item in r.getViews())
                {
                    cc.Views.Add(item.Key, item.Value);
                }
                // construct our list of service bindings to be used throughout the application
                // for Goal #1 (previously seen in OrderModule.cs
                foreach (KeyValuePair&lt;string, string&gt; item in r.getBindings())
                {
                    cc.Bindings.Add(item.Key, item.Value);
                }
                // if we can cache our company config:
                if (Session != null &amp;&amp; Session[&quot;cc&quot;] == null)
                {
                    Session[&quot;cc&quot;] = cc;
                }
                // set company name (normally would be from the repository)
                cc.CompanyName = &quot;Widgets, Inc.&quot;;
            }
            else  // we have a previously cached company config
            {
                cc = (CompanyConfig)Session[&quot;cc&quot;];
            }

            return cc;
        }
    }
}
</pre>
<p>To make our lives a little easier and yet more structured, let&#8217;s create an ActionFilterAttribute to inject our CompanyConfig into our Views:</p>
<p>From ProvideCompanyConfigAttribute:</p>
<pre class="brush: csharp;">
    public class ProvideCompanyConfigAttribute : ActionFilterAttribute
    {
        [Inject]
        public ICompanyConfig Settings { get; set; }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            filterContext.Controller.ViewData.Add(&quot;companyConfigSettings&quot;, Settings);
        }
    }
</pre>
<p>We use Ninject&#8217;s &#8220;Inject&#8221; attribute to provide the CompanyConfig to our Attribute, and then inject the config into the controller as a matter of course.</p>
<p>At this point we&#8217;ve seen how Ninject positions itself within our application (a controller factory and application superclass) and how we can use Ninject&#8217;s modularity to manage our bindings.  We&#8217;ve touched upon Goals #1, 2, and 3, and can see it taking shape before us.  We have a company configuration that encapsulates the customizations for the currently logged in user and provides the customized bindings and views for that logged in user.  We have basically everything we need to begin working with our customized functionality.</p>
<p>To get this far we have made the following assumptions:</p>
<ol>
<li>Your repository works.</li>
<li>You have an ASP.Net MVC application in otherwise working order.</li>
<li>You have downloaded and referenced the Ninject libraries.</li>
</ol>
<p>In Part 3 we will look at our application controllers and views, and then explore what we can do to provide customized functionality to our users.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tallan.com/2010/07/16/multi-tenant-architecture-via-dependency-injection-part-2/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Multi Tenant Architecture via Dependency Injection: Part 1</title>
		<link>http://blog.tallan.com/2010/07/11/multi-tenant-architecture-via-dependency-injection-part-1/</link>
		<comments>http://blog.tallan.com/2010/07/11/multi-tenant-architecture-via-dependency-injection-part-1/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 20:51:34 +0000</pubDate>
		<dc:creator>Nathaniel Engelsen</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Enterprise .NET]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[IoC]]></category>

		<guid isPermaLink="false">http://blog.tallan.com/?p=421</guid>
		<description><![CDATA[Discover how to use Inversion of Control and Dependency Injection to enhance your web application's Multi-Tenant Application.]]></description>
			<content:encoded><![CDATA[<p>Chances are, if you&#8217;ve been developing web applications for a number of years, you&#8217;ve noticed a few ways of provisioning your application for your users.</p>
<ol>
<li>Your users all log into a single codebase.  It might be load balanced, cached, the whole nine yards, but everybody is on the same build and accesses the same data.</li>
<li>Your users log into multiple codebases and/or multiple databases.  Perhaps you have some high-powered customers who want custom functionality, and so you forked your codebase and created them their own functionality.   Most likely, you can update your customer&#8217;s builds independently of one another.</li>
<li>Your users all log into a single codebase, but you use flags, connection strings, config files, etc., to logically separate out your users from one another.  Your high-powered customers see their custom functionality, but it&#8217;s part of the main codebase and you are able to update your application in one fell swoop.</li>
</ol>
<p>We&#8217;re going to talk more about option #3 &#8212; the Multi-Tenant Architecture.  There is <a href="http://lmgtfy.com/?q=multi+tenant+architecture">PLENTY of reading material</a> out there for you to learn more about multi-tenancy.  Suffice it to say that it allows you to satisfy multiple sets of requirements for your multiple customers via one codebase, and your customers, most likely, are logically separate in the database(i.e. they use one schema and one top-level data store) instead of physically separate.</p>
<p>In the past, (and present, for novice developers), it was a usual practice to utililze config files, database flags, etc., to turn on and off functionality. Your code may have looked something like:</p>
<pre class="brush: csharp;">
&lt;% if (showThisFunctionality) %&gt;
&lt;-- this widget is shown --&gt;;
&lt;% else %&gt;;
&lt;-- this other widget is shown --&gt;
&lt;% end if %&gt;
</pre>
<p><strong>Fig 1: Classic ASP</strong></code></p>
<p>By utilizing a dependency injection framework you can provide features to your users, based on configuration and setup, without having to use logic switches inside of your application.  This is above and beyond the existing benefits of using a dependency injection framework, which is not the scope of this essay but can be enumerated <a href="http://misko.hevery.com/2009/01/14/when-to-use-dependency-injection/">here</a>, for instance.  Our example will use <a href="http://ninject.org/">Ninject</a> and ASP.NET MVC, although you could use any DI and application frameworks.</p>
<p>Our challenge for this example will be to:</p>
<ol>
<li>dynamically set which service object(s) we are using to perform our application logic</li>
<li>dynamically set which view we are returning</li>
<li>dynamically set which partial views we are using</li>
</ol>
<p>Our example will utilize dependency injection to provide order fulfillment functionality for our customers.  For goal #1, we will use Ninject's MVC integration to provide service objects for our controllers.  Once Ninject is wired up, we can have our service objects perform our application logic against our Model, and as a matter of fact, Behavioral design patterns are a good fit here.  Goal #2 is achievable fairly easily with ASP.Net MVC.  Setting which view you're returning via any MVC framework is often a very simple operation and comes down to returning a string variable which represents the view in question.  For ASP.NET MVC we can '<code><span style="color: #0000ff">return</span><span>View(</span><span style="color: #a31515">"viewName"</span><span>)'</span></code> where "viewName" is the name of the view we wish to return.  There is also the obvious <code>"<span style="color: #0000ff">return </span><span>View(viewNameVariable)</span>"</code> override.  Our example will use a configuration object to set which view is being called.  Accomplishing goal #3 can be thought of as an extension of #2, but "finer grained". Where you have general and reusable functionality within your view, your partial views allow you to have specific customizations exposed to your user in a consistent fashion.</p>
<p>In Part 2 we will investigate both integrating Ninject with ASP.Net MVC as well as what shape our framework will take.  In Part 3 we will finish up our framework architecture and explore how to use it to provide features to our users.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tallan.com/2010/07/11/multi-tenant-architecture-via-dependency-injection-part-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Learning WPF</title>
		<link>http://blog.tallan.com/2010/07/01/learning-wpf/</link>
		<comments>http://blog.tallan.com/2010/07/01/learning-wpf/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 01:47:30 +0000</pubDate>
		<dc:creator>Craig Vallee</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.tallan.com/?p=499</guid>
		<description><![CDATA[As a .net developer that has recently spent over a year helping to design and build a SCSF winforms application, I have been looking to branch out into different techniques and technologies to improve my skill set.  With Visual Studio 2010 coming out, the latest support for WPF and a push, by Microsoft, toward its [...]]]></description>
			<content:encoded><![CDATA[<p>As a .net developer that has recently spent over a year helping to design and build a SCSF winforms application, I have been looking to branch out into different techniques and technologies to improve my skill set.  With Visual Studio 2010 coming out, the latest support for WPF and a push, by Microsoft, toward its advancement in the development community, I am intrigued to say the least to check it out. I do not consider myself a UI designer, and lack the artistic skills to become one, so learning WPF seems like a daunting task.<br />
I did find the following website to help with my desire to learn WPF: <a href="http://www.wpftutorial.net/">www.wpftutorial.net</a>. There is a great Getting Started section which will get you on your way to understanding the basics.  From learning XAML and basic MVVM concepts, the tutorial is presented in an easy-to-understand format.  There is also plenty of information that advanced users may find useful.<br />
Stay tuned for additional info as I learn WPF.</p>
<p>-Craig</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tallan.com/2010/07/01/learning-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transform System.Drawing.ContentAlignment property to System.Drawing. StringFormat Alignment property</title>
		<link>http://blog.tallan.com/2009/12/31/transform-systemdrawingcontentalignment-property-to-systemdrawing-stringformat-alignment-property/</link>
		<comments>http://blog.tallan.com/2009/12/31/transform-systemdrawingcontentalignment-property-to-systemdrawing-stringformat-alignment-property/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 20:10:19 +0000</pubDate>
		<dc:creator>Craig Vallee</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blogs.tallan.com/dotnetreflections/2009/12/31/transform-systemdrawingcontentalignment-property-to-systemdrawing-stringformat-alignment-property/</guid>
		<description><![CDATA[
Recently we had the need to transform System.Drawing.ContentAlignment property to System.Drawing. Stringformat alignment property for creating a Graphic object with text drawn on it inside a given rectangle.  Assuming that you want the text printed from left to right, you can use the ContentAlignment Enum values to obtain the desired StringAlignment Enum value.  For example:


 [...]]]></description>
			<content:encoded><![CDATA[<div id="codeSnippetWrapper">
<div id="codeSnippet" class="csharpcode">Recently we had the need to transform System.Drawing.ContentAlignment property to System.Drawing. Stringformat alignment property for creating a Graphic object with text drawn on it inside a given rectangle.  Assuming that you want the text printed from left to right, you can use the ContentAlignment Enum values to obtain the desired StringAlignment Enum value.  For example:</div>
<div id="codeSnippetWrapper">
<div id="codeSnippet" class="csharpcode">
<pre><span class="lnum">   1:</span> <span class="kwrd">public</span> StringFormat TransformProperty(ContentAlignment alignment)
<!--CRLF-->
<span class="lnum">   2:</span>         {
<!--CRLF-->
<span class="lnum">   3:</span>             StringFormat myStringFromat  = <span class="kwrd">new</span> StringFormat();
<!--CRLF-->
<span class="lnum">   4:</span>             <span class="kwrd">switch</span>(alignment)
<!--CRLF-->
<span class="lnum">   5:</span>             {
<!--CRLF-->
<span class="lnum">   6:</span>                 <span class="kwrd">case</span> ContentAlignment.MiddleLeft:
<!--CRLF-->
<span class="lnum">   7:</span>                     myStringFromat.Alignment = StringAlignment.Near;
<!--CRLF-->
<span class="lnum">   8:</span>                     <span class="kwrd">break</span>;
<!--CRLF-->
<span class="lnum">   9:</span>                 <span class="kwrd">case</span> ContentAlignment.MiddleRight:
<!--CRLF-->
<span class="lnum">  10:</span>                     myStringFromat.Alignment = StringAlignment.Far;
<!--CRLF-->
<span class="lnum">  11:</span>                     <span class="kwrd">break</span>;
<!--CRLF-->
<span class="lnum">  12:</span>                 <span class="kwrd">default</span>:
<!--CRLF-->
<span class="lnum">  13:</span>                     myStringFromat.Alignment = StringAlignment.Center;
<!--CRLF-->
<span class="lnum">  14:</span>                     <span class="kwrd">break</span>;
<!--CRLF-->
<span class="lnum">  15:</span>             }
<!--CRLF-->
<span class="lnum">  16:</span>             <span class="kwrd">return</span> myStringFromat;
<!--CRLF-->
<span class="lnum">  17:</span>         }
</pre>
<p>Craig<br />
<!--CRLF--></div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.tallan.com/2009/12/31/transform-systemdrawingcontentalignment-property-to-systemdrawing-stringformat-alignment-property/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding SQLite to a Windows Mobile Application</title>
		<link>http://blog.tallan.com/2009/12/31/adding-sqlite-to-a-windows-mobile-application/</link>
		<comments>http://blog.tallan.com/2009/12/31/adding-sqlite-to-a-windows-mobile-application/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 19:10:56 +0000</pubDate>
		<dc:creator>Craig Vallee</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blogs.tallan.com/dotnetreflections/2009/12/31/adding-sqlite-to-a-windows-mobile-application/</guid>
		<description><![CDATA[Using SQLite in a Windows Mobile Application provides a simple way to add pre-populated data for consumption by the application.&#160; There are a couple of configuration considerations when adding the database to the project.
1. Adding reference to SQLite.dll. After installing SQLite there will be a Compact Framework folder in the following path :C:\ProgramFiles\SQLite.NET\bin.&#160; This folder [...]]]></description>
			<content:encoded><![CDATA[<p>Using SQLite in a Windows Mobile Application provides a simple way to add pre-populated data for consumption by the application.&#160; There are a couple of configuration considerations when adding the database to the project.</p>
<p>1. Adding reference to SQLite.dll. After installing SQLite there will be a Compact Framework folder in the following path :C:\ProgramFiles\SQLite.NET\bin.&#160; This folder contains the System.Data.SQLite.dll that needs to be referenced.</p>
<p>2 The same path will also contain the dll which Windows Mobile will need to invoke the methods contained in the SQLite.dll.&#160; The following file needs to be added to the project which contains the main executable,&#160; SQLite.Interop.065.DLL.</p>
<p>Once the interop dll is in the project you can start using SQLite in the Mobile Application just as you would for any other application.</p>
<p>Craig</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tallan.com/2009/12/31/adding-sqlite-to-a-windows-mobile-application/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Could not load file or assembly &#8216;AjaxControlToolkit&#8217; or one of its dependencies. Access is denied.</title>
		<link>http://blog.tallan.com/2009/09/01/could-not-load-file-or-assembly-ajaxcontroltoolkit-or-one-of-its-dependencies-access-is-denied/</link>
		<comments>http://blog.tallan.com/2009/09/01/could-not-load-file-or-assembly-ajaxcontroltoolkit-or-one-of-its-dependencies-access-is-denied/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 23:28:10 +0000</pubDate>
		<dc:creator>kadasani</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blogs.tallan.com/dotnetreflections/?p=185</guid>
		<description><![CDATA[Problem: Recently i came across this problem while switching to a new Windows 7 64 bit m/c. The web site at hand was working fine on my previous m/c Windows 7 64 bit RC1. The error and the event log were basically not very helpful either.
Resolution:
So here is what I did to fix the issue [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem: </strong>Recently i came across this problem while switching to a new Windows 7 64 bit m/c. The web site at hand was working fine on my previous m/c Windows 7 64 bit RC1. The error and the event log were basically not very helpful either.</p>
<p><strong>Resolution:</strong></p>
<p>So here is what I did to fix the issue (to get it to work using IIS):</p>
<p>1. Make sure that the dll in question is either set to &#8220;Copy to: Local). Go to References, right click on AjaxControlToolkit and select properties. In my case it was already set to Copy Local. So that was not the issue</p>
<p>2. Open IIS Manager, browse to the AppPool (in my case it was the DefaultAppPool&#8230; it is just a Dev box, ok!). Go to Advanced Settings, and set Enable 32-bit Applications to true. Now that did fix the problem I was having.</p>
<p>For Cassini:</p>
<p>1. I had to give modify rights on the asp.net temp folder  to the Apppool identity (in my case IIS users group).</p>
<p><strong>Discussion</strong></p>
<ul>
<li>On further research (i.e. &#8220;google&#8221;), I came to the conclusion that it was a permissions error related to the Temporary ASP.NET Files folder (C:\Windows\Microsoft.NET\Framework64\v2.0.50727). Some of the other fixes for this problem can be found on other blogs. They relate to the access permissions on the ASP.NET folder, Trust level Settings on the Website, and Anti-virus settings. Here is a link to some of them:</li>
<li>What I found was that the main focus while resolving this error should be on the later part of the error that says &#8216;Access is denied&#8217; or &#8220;Invalid Argument&#8217; etc.. that will help you in attacking the issue. In my case it was the fact that I was running a 32 bit app on a 64 bit mc and a permissions issue as well on the Temporary ASP.NET folder.</li>
<li>If you get an &#8216;Access Denied&#8217;..try checking the permissions on the Temp ASP.NET folder.</li>
<li>If you get &#8216;Invalid Argument&#8217; try cleaning the temp asp.net folder and restarting the web site.</li>
</ul>
<p><a href="http://lichao.net/eblog/fix-access-is-denied-exception-from-hresult-0x80070005-e_accessdenied-on-local-machines-200905307.html">http://lichao.net/eblog/fix-access-is-denied-exception-from-hresult-0&#215;80070005-e_accessdenied-on-local-machines-200905307.html</a></p>
<p><a href="http://weblogs.asp.net/joshuajohnson/archive/2008/12/22/could-not-load-file-or-assembly-ajaxcontroltoolkit-or-one-of-its-dependencies-the-parameter-is-incorrect-exception-from-hresult-0-215-80070057-e-invalidarg.aspx">http://weblogs.asp.net/joshuajohnson/archive/2008/12/22/could-not-load-file-or-assembly-ajaxcontroltoolkit-or-one-of-its-dependencies-the-parameter-is-incorrect-exception-from-hresult-0-215-80070057-e-invalidarg.aspx</a></p>
<p><a href="http://msforums.ph/forums/t/46678.aspx">http://msforums.ph/forums/t/46678.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tallan.com/2009/09/01/could-not-load-file-or-assembly-ajaxcontroltoolkit-or-one-of-its-dependencies-access-is-denied/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>WCF Exception Shielding Error</title>
		<link>http://blog.tallan.com/2009/07/01/wcf-exception-shielding-error/</link>
		<comments>http://blog.tallan.com/2009/07/01/wcf-exception-shielding-error/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 15:47:14 +0000</pubDate>
		<dc:creator>Craig Vallee</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blogs.tallan.com/dotnetreflections/2009/07/01/wcf-exception-shielding-error/</guid>
		<description><![CDATA[While using the WCF Exception Shielding policy in Enterprise Library’s Exception Handler Block to shield exceptions and return Fault Contracts I came across an error. I named the shielding policy “WCF Shielding Policy” and implemented a FaultContract for each type of desired or expected exception.
While testing the policy, we were unable to return a proper [...]]]></description>
			<content:encoded><![CDATA[<p>While using the WCF Exception Shielding policy in Enterprise Library’s Exception Handler Block to shield exceptions and return Fault Contracts I came across an error. I named the shielding policy “WCF Shielding Policy” and implemented a FaultContract for each type of desired or expected exception.</p>
<p>While testing the policy, we were unable to return a proper FaultContract from the WCF Service.  The only error that we received was the generic Communication Error:</p>
<pre>System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to (path of service).
 This could be due to the service endpoint binding not using the HTTP protocol.
This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down).
See server logs for more details. ---&gt;  System.Net.WebException: The underlying connection was closed:
An unexpected error occurred on a receive.
  System.IO.IOException: Unable to read data from the transport connection: An existing connection was
forcibly closed by the remote host.
 System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host.</pre>
<p>This error is incredibly deceiving and led to many dead ends while trying to track down the root cause of the error. I re-wrote the app.config file and removed and re-added the service references, all to no avail.</p>
<p>The cause of the problem was simply in the name of the policy. If you don’t name your shielding policy “WCF Exception Shielding” verbatim then the policy will not be found and the error above will be thrown.  If you do name your policy something different or you implement different policies for different types of exceptions then you have to explicitly state in the ExceptionShielding attribute the name of the policy as follows:</p>
<pre>C#:[ExceptionShielding("MyPolicy")]
VB: &lt;ExceptionShielding ("MyPolicy")&gt;</pre>
<p>I renamed the policy to the default name and started receiving the Fault Contracts as expected.</p>
<p>Hope this helps eliminate some headaches for someone.</p>
<p>-Craig</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tallan.com/2009/07/01/wcf-exception-shielding-error/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Write iPhone Applications in C# using MonoTouch</title>
		<link>http://blog.tallan.com/2009/06/30/write-iphone-applications-in-c-using-monotouch/</link>
		<comments>http://blog.tallan.com/2009/06/30/write-iphone-applications-in-c-using-monotouch/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 13:24:09 +0000</pubDate>
		<dc:creator>Michael Gerety</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blogs.tallan.com/dotnetreflections/2009/06/30/write-iphone-applications-in-c-using-monotouch/</guid>
		<description><![CDATA[The mono project has released a new Mono edition for Apple’s iPhone and iPod Touch.&#160; This allows you to write full featured applications for the iPod touch using C#.&#160; 
This is not a JIT Compiler, but is a static compiler that turns .NET executables into native applications.&#160; 
For more information, check out the project at [...]]]></description>
			<content:encoded><![CDATA[<p>The mono project has released a new Mono edition for Apple’s iPhone and iPod Touch.&#160; This allows you to write full featured applications for the iPod touch using C#.&#160; </p>
<p>This is not a JIT Compiler, but is a static compiler that turns .NET executables into native applications.&#160; </p>
<p>For more information, check out the project at : <a title="http://www.mono-project.com/MonoTouch" href="http://www.mono-project.com/MonoTouch">http://www.mono-project.com/MonoTouch</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tallan.com/2009/06/30/write-iphone-applications-in-c-using-monotouch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

