Blog

ASP.net: CS0012: The type ‘System.Data.Objects.DataClasses.EntityObject’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.

If you are using the .Net Entity Framework and you are passing those Entity Framework objects through controls in your UI (.aspx, .ascx) pages such as a Repeater control (using the ) you will most likely see the following error message:

CS0012: The type ‘System.Data.Objects.DataClasses.EntityObject’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.

You may have added the assembly to your web application’s References but I guess this is not enough. You must also add the reference to your web.config file. You can do this by adding the following line to your ‘compilation/assemblies’ section so it looks like the following:

           
               
               
               
               
       
           
       

.Net: Difference Between WCF Service and Silverlight-Enabled WCF Service

The following are the differences between a regular WCF Service and a Silverlight-Enabled WCF Service.

WCF Services

  • Utilize the ‘wsHttpBinding’ as their default binding
  • Are generated with an Interface

Silverlight-Enabled WCF Services

  • Utilize ‘basicHttpBinding’ as their default binding
  • have no interface generated when they are created
  • have the following added to the class

    • [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  • the following element is added to the

ASP.net: Custom Web.config Sections and Elements

On occasion you will find it necessary to add your own configuration sections to your web application’s web.config configuration file. This allows you to encapsulate configuration options needed by your components into a manageable section within your applications configuration. The information you place in the custom configuration section should be items that may change frequently.

By adding configuration information used by your components to the web,config file you can at any time without recompiling your application code alter the behavior and functionality of your components by changing these configuration options. This is because the web.config file is monitored by the ASP.net worker process and when ever it is altered the application is restarted and the configuration is re-read so that all components utilizing the configuration will receive the updates.

Here is what the config section definition looks like. This is added to the ‘configSections’ portion of the web.config files (at the top usually). This section defines what other sections are within the rest of the configuration file and which can be read by the web application. It takes a name which is the name of th e


<section name="myconfigsection" type="MyAssembly.MyConfigSection, MyAssembly, Version=1.0.0.0, Culture=neutral" requirePermission="false"/>

Here is what the config section we will be working from looks like


<myconfigsection>
    <mylistoffoods>
        <add name="bacon" enjoy="true" />
<
add name="steak" enjoy="true" />
<add name="celery" enjoy="false" /> </mylistoffoods>

</myconfigsection>
The first thing to do is create what I call a ‘Configuration Helper’ class which is responsible for pulling our configuration section and exposing it to our component as a public property which our code can access. Here is the class:


using System;
using System.Configuration;
namespace MyAssembly
{
    /// 
    /// This class is used to retrieve most important settings from web.config
    /// 
    public class ConfigurationHelper
    {

#region Private Fields private static MyConfigSection _myConfigSection =

            (MyConfigSection)ConfigurationManager.GetSection("myconfigsection");
        #endregion
        #region Public Properties
        /// 
        /// Gets the client admin logging section.
        /// 
        /// The client admin logging section.
        public static MyConfigSection MyConfigSection
        {
            get{ return _MyConfigSection; }
        }
        #endregion
    }
}

Next you create the class which represents the actual configuration section you introduced to the web.config. It is through this class that you will be able to access your Foods collection.


using System.Configuration;
namespace MyAssembly
{
    /// 
    /// Represents the section within
    /// the web.config.
    /// 
    public class MyConfigSection : ConfigurationSection
    {
        #region Public Properties
        /// 
        /// Returns a collection of event handler configurations
        /// 
        /// The event handlers.
        [ConfigurationProperty("mylistoffoods")]
        public FoodCollection MyListOfFoods
        {
            get
            {
                return this["mylistoffoods"] as FoodCollection;
            }
        }
        #endregion
    }
}

Next we need to create a class which will represent a food in the collection. Here is the class:


using System.Configuration;
namespace MyAssembly
{
    /// 
    /// Represents the configuration for an event handler 
    /// within the web.config
    /// 
    public class Food : ConfigurationElement
    {
        #region Public Properties
        /// 
        /// Gets the name of the event handler.
        /// 
        /// The name.
        [ConfigurationProperty("name", IsRequired = true)]
        public string Name
        {
            get
            {
                return this["name"] as string;
            }
        }
        /// 
        /// Gets a value indicating whether  I like the food
        /// 
        /// true if like; otherwise, false.
        [ConfigurationProperty("enjoy", IsRequired = true)]
        public bool Enjoy
        {
            get
            {
                return (bool) this["enabled"];
            }
        }
        #endregion
    }
}

Next we create a class to represent a collection of foods. Here is the class:


using System.Configuration;
namespace MyAssembly
{
    /// 
    /// Represents a collection of event handlers pulled
    /// from the web.config
    /// 
    public class FoodCollection : ConfigurationElementCollection
    {
        #region Overrides of ConfigurationElementCollection
        /// 
        /// When overridden in a derived class, creates a new .
        /// 
        /// 
        /// A new .
        /// 
        protected override ConfigurationElement CreateNewElement()
        {
            return new EventHandler();
        }
        /// 
        /// Gets the element key for a specified configuration element when overridden in a derived class.
        /// 
        /// 
        /// An  that acts as the key for the specified .
        /// 
        /// The  to return the key for. 
        ///                 
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((EventHandler) element).Name;
        }
        #endregion
    }
}

Well that’s all there is to it now within your components code you simply call your Configuration Helper and pull the food collection and use the foods as you need to.

Silverlight: Passing InitParams to your Application from the Page

To pass initialization parameters (InitParams) to your Silverlight application at its startup you can simply add a new  ‘initParams’ element to the Silverlight Object markup within your page. The ‘initParams’ element contains for its value a hash of key value pairs you wish to pass into the application in the for “key=value”.
Example:

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
    <param name="source" value="ClientBin/JoxStrap.Silverlight.Home.xap"/>
    <param name="onError" value="onSilverlightError" />
    <param name="background" value="white" />
    <param name="minRuntimeVersion" value="3.0.40624.0" />
    <param name="autoUpgrade" value="true" />
    <param name="initParams" value="baseUri=http://local.joxstrap.com" />
    <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
      <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
    </a>
     </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

After adding the ‘initParam’ element to the object markup you then read in these parameters in the Application_Startup method located in your App.xaml.cs file.

private void Application_Startup(object sender, StartupEventArgs e)
        {
            StartUpParameters startup = StartUpParameters.Instance;

            try
            {
                string uriString = e.InitParams["baseUri"];
                if (!string.IsNullOrEmpty(uriString))
                {
                    Uri baseUri = new Uri(uriString);
                    startup.BaseUri = baseUri;
                }
            }
            catch
            {
                startup.BaseUri = null;
            }

            RootVisual = new MainPage();
        }

Silverlight 3: HTML dropdown menus fall behind Silverlight

If when you hover over the dropdown menus in your website and find that they are disappearing behind your Silverlight media elements in the page making it impossible to click on the hidden menu items, there is a simple solution. You need to activate the ‘windowless’ mode for all Silverlight media elements which are within reach of your dropdowns.
To do this just add the following parameter to your object markup for the Silverlight element.

<param name="windowless" value="true"/>

Your object markup should now look something like this:

 <object data="data:application/x-silverlight-2," type="application/x-silverlight-2"
            width="950px" height="665px">
            <param name="windowless" value="true"/>
            <param name="source" value="URI_TO_SILVERLIGHT_FILE" />
            <param name="onError" value="onSilverlightError" />
            <param name="minRuntimeVersion" value="3.0.40624.0" />
            <param name="autoUpgrade" value="true" />
            <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration: none">
                <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight"
                    style="border-style: none" />
            </a>
        </object>
        <iframe id="_sl_historyFrame" style="visibility: hidden; height: 0px; width: 0px; border: 0px"></iframe>

Silverlight 3: Using Built-in Behaviors and Triggers to Reduce Code

With the addition of Behaviors in Silverlight 3 we have the opportunity to reduce a lot of the code we write in order to create interactivity within our application. Expressions Blend 3 comes with several built-in behaviors right at your fingertips. You can find them in the Assets panel (left side) under the Behaviors group.

  • ChangePropertyAction
  • ControlStoryboardAction
  • FluidMoveBehavior
  • GoToStateAction
  • HyperlinkAction
  • MouseDragElementBehavior
  • PlaySoundAction
  • RemoveElementAction

In this example we will be building a simplistic sound playing app using the ChangePropertyAction as well as the PlaySoundAction Behaviors. By utilizing these 2 built-in Behaviors we can completely eliminate writing a single line of code.