Blog posts

  • Unknown server tag 'asp:LinqDataSource'

    June 18, 2012 | Tags: ASP.NET, Database, C#, Troubleshooting, LINQ
    If you're getting an error saying that the asp:LinqDataSource is unknown, you most likely is missing the declaration in your web.config file. To fix this:

    1. Open your web.config file and locate the <controls> block.
    2. Add the following element: <add assembly="System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.UI.WebControls" tagprefix="asp"> into the <controls&gt; block.
    3. Reload the page and see it working :)

  • C# classes created from XML with XSD.EXE

    June 07, 2012 | Tags: Tools, XML, C#
    The XSD.EXE tool that is included in Visual Studios command line tools is a bit flawed.

    Running the command first generating an XSD scheme out of your XML file and then creating classes from it:
    xsd MyXml.xml
    xsd MyXml.xsd /classes /n:MyNameSpace.Serialization

    First of all, most likely your array elements will be declared as multi dimensional arrays. If so you'll end up with a "Unable to generate a temporary class" exception and plenty of "error CS0030: Cannot convert type 'Data[]' to 'Data'". (Data is an example return type, yours will probably be named something else, Row is an example element name.)

    The code in the generated class would look something like this:
    [System.Xml.Serialization.XmlArrayItemAttribute("Data", typeof(Data), IsNullable=false)]
    public Data[][] Row ...

    If you actually use multi dimensional arrays, it should really be using typeof(Data[]) instead, like this:
    [System.Xml.Serialization.XmlArrayItemAttribute("Data", typeof(Data[]), IsNullable=false)]
    public Data[][] Row ...

    But if you're just looking for normal one dimensional arrays it's the return type that needs to be flattened to Data[] instead of Data[][]:
    [System.Xml.Serialization.XmlArrayItemAttribute("Data", typeof(Data), IsNullable=false)]
    public Data[] Row ...

    Read the original solution post here.

    The second problem you may face is if your XML doesn't contains namespaces. It would occur like "<yourrootelement xmlns=""> was not expected.". To fix this, remove the empty Namespace parameters from the XmlRootAttribute in your generated classes. You'll find some alternative fixes for this problem here.

  • C# check if type is nullable

    May 07, 2012 | Tags: C#, Snippet
    This is a nice little snippet to check if a type is nullable:

    public static bool IsNullableType(Type type) {
    if(!type.IsGeneric) {
    return false;
    if(type.GetGenericTypeDefinition() == typeof(Nullable<>)) {
    return true;
    else {
    return false;

    This is a restructured version of Snippet: Check if type is Nullable (C# 2.0) or not (C#)

  • Generating GUID value with ReSharper

    May 07, 2012 | Tags: Tools, C#
    Do you need to have a new GUID generated for your code i Visual Studio? If you have ReSharper installed it´s a piece of cake.

    In your code, just write nguid and hit tab. You should now be looking at a selection of string formats for your new GUID value!

    If you do not yet have ReSharper head over and download a trial, you won't regret it :)

  • Store TFS credentials for CodePlex

    May 06, 2012 | Tags: Team Foundation Server, Open source
    Tired of always having to rewrite you credentials when starting up you CodePlex hosted project in Visual Studio? If so, just follow these steps (assuming you're using Windows 7):

    1.  Go to the Control Panel and select User Accounts and Manage your credentials.
    2. Add a Windows credential, enter and your login criteria (username/password). Be sure to include the domain prefix for your username.
    3. Click OK and you're done!
    Next time you go online with Visual Studio you'll be automatically logged in.

    This will also work for any other TFS, you just need to put the correct address instead of when adding the Windows credential.