Visual Studio suckiness

28. February 2011

Do you suffer from VSSS (Visual Studio Suckiness Syndrome)?  There’s help.  If you’ve noticed your devenv.exe process swelling up to around 2gb and then getting really slow, buggy and freezing up, try a few things:

  1. Disable extensions or 3rd party addons that don’t manage their memory well.  VS doesn’t use any process isolation for hosting these addons which means if your vendor’s product doesn’t behave well, VS won’t.  Telerik’s JustCode turned out to be a big offender for me.
  2. Enable more user mode memory for VS using instructions detailed here.


Hopefully this will help you keep the sanity -- happy coding!

Development

Networking in Silverlight 4 presentation

20. August 2010

I had the special opportunity today to speak to around 90 developers from Bank of America about building connected applications with Silverlight 4 today.  I’ve done this demo a few times before in front of different groups (code camps, etc.) and it always seems to get a positive response.  As a matter of fact, I’ll be presenting it again next Thursday night at Microsoft’s office in Tampa for IASA (register here if you’re interested).

In case you dialed in, and you’d like the PowerPoint deck, here it is:

 

Also, somebody asked about my Chalkboard theme for Visual Studio, and I thought it’d be a good time to post an update for Visual Studio 2010. 

Community Events, Development

A little story about .GetType()

21. May 2010

Last week I was writing some code with a co-worker and a line of code similar to the following came up:

if (object.GetType() == typeof(T))
{
	// ... more code here.
}


The question came up, “doesn’t this use Reflection”?  My response was that the .GetType() method itself doesn’t use reflection, but instead evaluates the object’s metadata from the CLR at runtime and produces the relevant type information.

Then, I ran across this from TweetDeck today:

To the guy ("who is always right") that said GetType() doesn't use reflection: http://msdn.microsoft.com/en-us/library/ms173183(VS.80).aspx

Now, let’s not kid ourselves here, I’m certainly not the guy who is always right.  So, ready and willing to be wrong I started reading the rather innocuous post from MSDN on the subject:

Here's a simple example of reflection using the static method GetType - inherited by all types from the Object base class - to obtain the type of a variable:

C#

// Using GetType to obtain type information:
int i = 42;
System.Type type = i.GetType();
System.Console.WriteLine(type);
 

Indeed, MSDN does say that invoking .GetType() is an example of using Reflection.  My original comment that .GetType() didn’t use Reflection was based on my (inaccurate) definition of reflection – that an object is reflected upon when it becomes loaded into memory for the sole purpose of achieving this reflection.  I suppose the difference is one of perception, really, but here it’s clearly caused confusion.

Then I ran across this post supporting my assertion, that calling .GetType() in fact constructed the type information at runtime directly using a hook into the CLR.  Is this the same as reflection?  My original point that this wasn’t reflection was really one more of performance than the syntax.  I wonder what Ritchie Swann would say now regarding his original comments on the matter:

As for how it works - the GetType() function is marked with the special attribute [MethodImpl(MethodImplOptions.InternalCall)]. This means its method body doesn't contain IL but instead is a hook into the internals of the .NET CLR. In this case, it looks at the binary structure of the object's metadata and constructs a System.Type object around it.

The question of performance, in my mind, can really only be answered by doing a comparative analysis.  How much work does .GetType() do anyway, and is it the same as other methods of Type checking?  I decided to check it out.  Consider the following rather simple class:

namespace TypeReferenceChecking
{
    class Program
    {
        static void Main(string[] args)
        {
            TestIs();
            TestGetTypeIs();
            TestGetTypeEquals();
        }

        static bool TestIs()
        {
            var newObject = new SampleType();

            return newObject is SampleType;
        }

        static bool TestGetTypeIs()
        {
            var newObject = new SampleType();

            return newObject.GetType() is SampleType;
        }

        static bool TestGetTypeEquals()
        {
            var newObject = new SampleType();

            return newObject.GetType() == typeof(SampleType);
        }
    }

    class SampleType
    {
    }
}

Looking at the disassembled C# source for this assembly with Reflector, you’ll see the following:

internal class Program
{
    // Methods
    private static void Main(string[] args)
    {
        TestIs();
        TestGetTypeIs();
        TestGetTypeEquals();
    }

    private static bool TestGetTypeEquals()
    {
        SampleType newObject = new SampleType();
        return (newObject.GetType() == typeof(SampleType));
    }

    private static bool TestGetTypeIs()
    {
        new SampleType().GetType();
        return false;
    }

    private static bool TestIs()
    {
        SampleType newObject = new SampleType();
        return (newObject != null);
    }
}

At first glance, it appears that calling .GetType() in your code, in fact, calls the runtime method .GetType(), which MSDN says is reflection.  But what about the argument that .GetType() retrieves information from the CLR hooks itself, not from an image of the assembly containing the type.  I was dying to find out, so I used Reflector on the .GetType() method itself:

[MethodImpl(MethodImplOptions.InternalCall), SecuritySafeCritical]
public extern Type GetType();

Sure enough, it’s exactly what Ritchie Swann eluded to.  Then I started thinking about the real question.  If .GetType() gets type information from the CLR and constructs a new instance of System.Type, how expensive is that construction? 

[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
protected Type()
{
}

It would be lovely to say that we get more answers here, but we don’t.  There is a static constructor on Type that initializes empty types, filters, etc. but no instance constructor.

So, the million dollar question, that really only Microsoft can say is:

For purposes of evaluating type comparison, is using .GetType() for an object that’s already in memory at runtime the same as evaluating type information from a type that’s not already loaded in memory?  If not, do you call both reflection?  This was the distinction that I really wanted to make the other day in my conversation with my coworker, that doing this runtime check is harmless and doesn’t cause excess work for the CLR (despite what it may be called).

I look forward to some great chats at TechEd with folks who will likely gladly weigh in.  Got your own opinion?  Comment below.

Development

Using SharePoint 2010 Beta 1 REST services on Windows 7 or Windows Server 2008 R2

27. February 2010

Today, I’m presenting this session from PDC at a local code camp.  In setting up my demo, I’ve been trying to get the SharePoint 2010 beta 1 server setup so that it can be queried using WCF Data Services (formerly ADO.Net Data services).  Whatever I try, I continue getting the following error:

WebHost failed to process a request.

Sender Information: System.ServiceModel.Activation.HostedHttpRequestAsyncResult/40906347
Exception: System.ServiceModel.ServiceActivationException: The service '/_vti_bin/listdata.svc' cannot be activated due to an exception during compilation.  The exception message is: Could not load file or assembly 'Microsoft.Data.Services, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified..

The good news is that there is a solution for this problem.  The ADO.Net Data Services 1.5 CTP 2 runtime needs to be installed as well as a patch.

The runtime can be found at: http://www.microsoft.com/downloads/details.aspx?FamilyID=a71060eb-454e-4475-81a6-e9552b1034fc&displaylang=en#filelist

The patch is available at:
http://www.microsoft.com/downloads/details.aspx?familyid=79d7f6f8-d6e9-4b8c-8640-17f89452148e&displaylang=en#filelist

Development ,

Welcome to BlogEngine.NET 1.6.0

23. January 2010

If you see this post it means that BlogEngine.NET 1.6.0 is running and the hard part of creating your own blog is done. There is only a few things left to do.

Write Permissions

To be able to log in to the blog and writing posts, you need to enable write permissions on the App_Data folder. If you’re blog is hosted at a hosting provider, you can either log into your account’s admin page or call the support. You need write permissions on the App_Data folder because all posts, comments, and blog attachments are saved as XML files and placed in the App_Data folder. 

If you wish to use a database to to store your blog data, we still encourage you to enable this write access for an images you may wish to store for your blog posts.  If you are interested in using Microsoft SQL Server, MySQL, VistaDB, or other databases, please see the BlogEngine wiki to get started.

Security

When you've got write permissions to the App_Data folder, you need to change the username and password. Find the sign-in link located either at the bottom or top of the page depending on your current theme and click it. Now enter "admin" in both the username and password fields and click the button. You will now see an admin menu appear. It has a link to the "Users" admin page. From there you can change the username and password.  Passwords are hashed by default so if you lose your password, please see the BlogEngine wiki for information on recovery.

Configuration and Profile

Now that you have your blog secured, take a look through the settings and give your new blog a title.  BlogEngine.NET 1.4 is set up to take full advantage of of many semantic formats and technologies such as FOAF, SIOC and APML. It means that the content stored in your BlogEngine.NET installation will be fully portable and auto-discoverable.  Be sure to fill in your author profile to take better advantage of this.

Themes and Widgets

One last thing to consider is customizing the look of your blog.  We have a few themes available right out of the box including two fully setup to use our new widget framework.  The widget framework allows drop and drag placement on your side bar as well as editing and configuration right in the widget while you are logged in.  Be sure to check out our home page for more theme choices and downloadable widgets to add to your blog.

On the web

You can find BlogEngine.NET on the official website. Here you'll find tutorials, documentation, tips and tricks and much more. The ongoing development of BlogEngine.NET can be followed at CodePlex where the daily builds will be published for anyone to download.

Good luck and happy writing.

The BlogEngine.NET team

,

Presenting today: Behind the Scenes of SalesForce.com and Microsoft Dynamics CRM 4.0: The Developer’s Story

12. November 2009

I’m doing a webinar today for my company, Tribridge, entitled “Behind the Scenes of SalesForce.com and Microsoft Dynamics CRM 4.0: The Developer’s Story”.  Long titles aside, I’m super excited about delivering this content to a technical audience. 

This is actually a follow-up presentation from a webinar that my colleague Seth Kircher did a few months back.  If you didn’t see the first part, you may want to watch it before attending today’s webinar.

Register for today’s webinar.

Community Events, Development

Silverlight 3 Linkapalooza

23. September 2009

So I’ve been a very, very busy bee with a bunch of projects, and there’s been no lack of well-deserved teasing for not posting to this blog in 8 months.  I guess the best way to silence the critics would be a good-old-fashioned link-off.  Here’s my list of high quality Silverlight 3 content that you’ve got to check out.

Showcase Sites & Samples

Expression Blend & SketchFlow

Interactivity & Behaviors

Application Lifecycle & Composition

Navigation

DataForm

Data Binding / Data Services (not RIA Services)

RIA Services

WPF / XAML cross-breeds

Connecting with the Silverlight Team

Development , ,

Where in the world is Brandon Kelly?

27. January 2009

I can’t believe February 2009 is already here.  Seems like only yesterday I was intently waiting on my flying car like the rest of us, and now I’m living in the future!  In case you’re not up to speed, there’s several great community events coming up – and I’ll be doing my usual code singing, beer slinging routine.

February 7 – South Florida Code Camp
I’ll be presenting on writing Line of Business applications with Visual Studio 2008 and Silverlight 2.  This presentation will be an end-to-end demo of data design/maintenance using VSTS Database Edition, modeling with ADO.NET Entity Framework, building a business layer and then UI with Silverlight 2.  If you didn’t make Tampa Code Camp in December this is the show to see.

February 17 – Sarasota DEV User’s Group
I’ll be in Sarasota the night of the 17th presenting on Visual Studio Team System 2010.  This will be the demo that I did at MDC (MSDN Developer Conference) in December, so if you missed the conference, PDC and still want to see some hands on VSTS 2010, I’ll see you in Sarasota!

Looking forward to a great month, quarter and then year with the local developer communities.

Community Events

My “Chalkboard” Visual Studio 2008 Theme

27. January 2009

Many people around the office have taken notice of my Visual Studio 2008 theme, which I’ve affectionately called “Chalkboard”.  I put together this theme and then tweaked it over the past few months to make hours in front of Visual Studio 2008 easier on my eyes.  Here’s a screen grab.

The high-contrast colors (dark background, light foreground) take some getting used to, but they’re much easier on the eyes after you do.  For those who are interested, I’ve exported my Font and Color settings as a Visual Studio 2008 theme.

Download my Visual Studio 2008 “Chaklboard” theme.

Technorati Tags: ,

Development

Using Help Filters in Visual Studio

21. January 2009

Last night I was at the Tampa SQL Server User’s Group attending a good intro on VSTS Database Edition GDR presented by Catapult Systems.  After the session, one of the attendees asked me if there was any way to get rid of the SQL Server Compact Edition help from his Visual Studio help collection.  One way to do this is to use the provided help filters, which allow users to set preferences on what content they would like to see in help.  Here’s the link to MSDN that explains the filters:

Using Help Filters in Visual Studio (MSDN)

Another way to do this is to uninstall the specific content that you want removed from the collection.  Simply run the MSDN uninstaller from the Control Panel and modify your installation.

Development