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 ,

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 , ,

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

Timeout and Workflow issues when using the Deployment Manager in Dynamics CRM 4.0

12. January 2009

I've been trying to re-deploy a CRM 4.0 installation from a client's site into our development domain so that I can work with some of the data in the system.  Using the provided CRM 4.0 Deployment Manager is pretty easy (instructions found here), but wasn't working. 

The deployment manager would run for a good 30+ minutes and eventually come back to me with a SQL Server Timeout error.  The details of this error follow:

Import Organization (Name={Name}, Id={ID} failed.

The changes made during Import Organization could not be rolled back. Please manually delete the Organization database from the 'SBCRM01' SQL Server if it was not successfully deleted.

System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
… 
   at Microsoft.Crm.Tools.Admin.ImportOrganizationInstaller.Import(Guid organizationId, String organizationUniqueName, String organizationFriendlyName, String sqlServerName, String databaseName, Uri reportServerUrl, String privilegedUserGroupName, String sqlAccessGroupName, String userGroupName, String reportingGroupName, String privilegedReportingGroupName, ICollection`1 users, MultipleTenancy multipleTenancy)

I Googled, hooked up SQL Server Profiler and searched Microsoft’s knowledge base – desperate for some sort of answer to this problem.  I finally found a forum post online that described a similar scenario being resolved by installing Microsoft Dynamics CRM 4.0 Update Rollup 1

It wasn’t until I looked at the deployment log file that I realized that the timeout expired error was really just a symptom of another problem.  Turns out that below the Timeout exception I found another exception message that describes what’s really going on.

Import Organization (Name={Name}, Id={ID}) failed with Exception:

Microsoft.Crm.CrmException: Unable to find metadata information for attribute {attribute_name}
   at Microsoft.Crm.Workflow.ObjectModel.MetadataProvider.GetAttributeMetadata(EntityMetadata entityMetadata, String attributeName)

   at Microsoft.Crm.Tools.Admin.ImportOrganizationInstaller.Import(Guid organizationId, String organizationUniqueName, String organizationFriendlyName, String sqlServerName, String databaseName, Uri reportServerUrl, String privilegedUserGroupName, String sqlAccessGroupName, String userGroupName, String reportingGroupName, String privilegedReportingGroupName, ICollection`1 users, MultipleTenancy multipleTenancy)

What the heck is this?  Turns out, the issue is caused by having workflow in CRM that references an attribute that is subsequently deleted.  Per Joel CustomerEffective (forum post), here’s some things you can do to resolve the issue:

1. Recreate the missing attribute (you can delete after import).
2. Delete any rows that reference that attribute from the workflowdependencybase table
3. Import the organization into an environment that is pre-rollup 1
4. Wait for KB958571 to be released--they are testing it now.  If you search for it, you will find the KB article for it, but the hotfix has been redacted pending further testing.

Of course, KB958571 talks about a hotfix that isn’t publically available.  Sad – really sad, but have no fear!  After wasting 6 hours today working on this problem, I’m still waiting on getting an answer from Microsoft about the availability of the patch.  I’ve attempted solution #2 (removing the dependencies from the source database before performing the import) without success.  Options #1 and #3 aren’t available to me at the moment.  If you know of a better solution, please post a comment to this blog!

Development ,

Troubleshooting guide for TFS installation

7. January 2009

Looks like the good folks in Redmond got some time to write up a much-needed troubleshooting guide for TFS server installations.  You can find the guide on MSDN using the following link:

Troubleshooting installation of Team Foundation

The guide goes over how to interpret the installer log files, as well as diagnosis for many common TFS errors.  Here's a list:

  1. Error 32000. The Commandline ‘[1]’ returned non-zero value: [2]
  2. Error 29112. Team Foundation Report Server Configuration: Either SQL Reporting Services is not properly configured, or the Reporting Services Web site could not be reached. Use the Reporting Services Configuration tool to confirm that SQL Reporting Services is configured properly and that the Reporting Service Web site can be reached, and then run the installation again. For more information, see the Team Foundation Installation Guide.
  3. Error 29109. Team Foundation Report Server Configuration: SQL Reporting Services configuration encountered an unknown error. Verify that you have sufficient permissions to configure SQL Reporting Services, and try again.
  4. Error 28806. An unexpected error occurred. Verify that SQL Server Reporting Services is installed and running on the Team Foundation app tier and that you have sufficient privileges to access it. For more information, see the setup log.
  5. Error 29000. An unexpected error occurred. Verify that SQL Server Reporting Services is installed and running on the Team Foundation app tier and that you have sufficient privileges to access it. For more information, see the setup log.
  6. Error 28805. The setup program cannot complete the request to the server that is running SQL Server Reporting Services. Verify that SQL Server Reporting Services is installed and running on the Team Foundation app tier and that you have sufficient permissions to access it. For more information, see the setup log.
  7. There is an error with the collation settings for SQL Server. The collation settings are not compatible with Team Foundation Server.


There are also sections for troubleshooting the installation of Team Build or Team Explorer in Visual Studio, as well as some helpful hints for post-installation pains.  This article has now taken the place of a dozen of my favorites -- thanks Microsoft!

Technorati Tags: ,,

Development , ,