Skip Ribbon Commands
Skip to main content

Quick Launch

Home
Engineering Director at Vertigo Software
November 10
Upgrading LINQ Beta 2 Code
  1. Change the Add(), AddAll(), Remove(), and RemoveAll() methods. Please see Petar's blog post for more info.


    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2060651&SiteID=1

       

Previous Method

Renamed Method

Add()

InsertOnSubmit()

AddAll()

InsertAllOnSubmit()

Remove()

DeleteOnSubmit()

RemoveAll()

DeleteAllOnSubmit()

   

   

2.  Update the LINQ to SQL .dbml files encoding to utf-8:

<?xml version="1.0" encoding="utf-16"?>

   

- to -

   

<?xml version="1.0" encoding="utf-8"?>

   

3.  Web.Config changes:

   

<add assembly="System.Data.DataSetExtensions,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=B77A5C561934E089
"/>

   

- to -

   

<add assembly="System.Data.DataSetExtensions,
Version=3.5.0.0, Culture=neutral,
PublicKeyToken=B77A5C561934E089
"/>

November 08
Microsoft Line of Code Counter

Microsoft has released a nice line of code counter application. The application is available for download here.

When you start the app for the first time, it shows a blank list of counter tasks:

The first step to using the application is to create a New Counter Task which can pull code from source control or examine files on disk:

Once that it is finished, you can hit the play button to run the code count:

Once the Counter Engine finishes processing, the Result dialog is shown with a nice Task Summary:

Clicking on the View Report button generates a nice summary of the code count:

October 23
C# 3.0 Language Enhancements

While attending TechEd 2007 in Orlando, FL I attended a great session on the new language features in C# 3.0. While I was in college (at Harvey Mudd College), I took a course on Programming Languages and study such languages as Scheme, Lisp, and Standard ML. It is great to see advancements in commercial programming languages that Academia has had for years. You can check out the official C# 3.0 at the MSDN Visual C# Developer Center.

  

  

For all of the code snippets below I am using Visual Studio 2008. I started by creating a new C# Console Application and then I added a new class named Customers. Here is a recap of the new language enhancements:

1. Auto-Implemented Properties

It is always tedious to provide the getter and setters for properties. Visual Studio 2005 made life a bit easier with the Refactor -> Encapsulate Field feature, but it was still a lot of work to clean up the code to get everything organized nicely.

Auto-Implemented Properties allows you to define public data type and the compiler will take care of automatically generate a Public read/write property.

C# 2.0

C# 3.0

private int? _customerId = null;

   

public int? CustomerId

{

get { return _customerId; }

set { _customerId = value; }

}

public int? CustomerId { get; set; }

   

If you compare the IL that is generated using ildasm.exe, you can see how the property is managed

Standard Property (backed by a defined private data member)

Auto-Implemented Property

   

2. Object-Initializers

Often we need to set a bunch of properties once we new up an object from our class definition. In C# 3.0, we no longer have to use the object name dot notation to initialize the Properties. Instead we can use curly braces after the instantiation as shown below:

C# 2.0

C# 3.0

Customers c = new Customers();

c.CustomerId = 1;

c.Name = "Mike Hanley";

Customers c = new Customers()

{

CustomerId = 1,

Name = "Mike Hanley"

};

   

   

3. Collection-Initializers

As mentioned in the Object-Initializers enhancement above, the same is also true for Collections.

C# 2.0

C# 3.0

List<Customers> customers =

new List<Customers>();

   

customers.Add(c1);

customers.Add(c2);

customers.Add(c3);

List<Customers> customers =

new List<Customers>()

{

c1, c2, c3

};

   

What is also nice is that Visual Studio 2008 provides full Intelli-Sense support as well.

   

4. local variable type reference (var)

The var keyword is one of the coolest new features in C# 3.0 and enables very elegant code. The compiler is able to determine the intended by evaluating the right hand side of the expression.

C# 2.0

C# 3.0

List<Customers> customers =

new List<Customers>();

var customers = new List<Customers>();

   

In the example above, the compile is able to determine that the customers data member is a List<T> where T is of type Customers. The scope of the var keyword is limited to a method. This ensures that the compiler can still ensure type safety. If it was allowed as a parameter in a method, there would be no way to determine what the type is at compile time.

   

5. Query Expressions (LINQ)

Query Expressions build upon the var keyword and Microsoft has provided a whole query framework named Language Integrated Query or LINQ. Query Expressions provide a convenient way to data projection and transformations in code.

C# 3.0

var query = from c in customers

where c.Name == "Mike Hanley"

select c;

   

If you have ever used T-SQL, the syntax will look very familiar with one notable exception: the placement of the select clause. The from clause needs to be first in order to determine the type and to enable scenarios like Intelli-Sense support in Visual Studio 2008.

Let's consider the following code to print out a list of customers

C# 3.0

var c1 = new Customers() { CustomerId = 1, Name = "Mike Hanley" };

var c2 = new Customers() { CustomerId = 2, Name = "Kevin Hanley" };

var c3 = new Customers() { CustomerId = 3, Name = "Scott Stanfield" };

   

var customers = new List<Customers>() { c1, c2, c3 };

   

var query = from c in customers

where c.CustomerId > 0

select c;

   

foreach (Customers c in query)

{

Console.WriteLine(c.Name);

}

   

The output of the code above will print out the names of the customers in the order in which they were added to the Customers list.

Now let's add an orderby clause to transform the data:

C# 3.0

var query = from c in customers

where c.CustomerId > 0

orderby c.Name.Split(' ')[0]

select c;

   

Now the customers are sorted by first name:

   

6. Anonymous Types

It is possible to create a new instance of an object without specifying the class that should be used to create the type.

C# 3.0

// strongly typed Customer

Customer c1 = new Customer() { CustomerId = 1, Name = "Mike Hanley" };

var c2 = new Customer() { CustomerId = 2, Name = "Kevin Hanley" };

   

// anonymous type

var c3 = new { CustomerId = 1, Name = "Mike Hanley" };

   

   

7. Lamda Expressions

A Lamda Expression appears to be the evolution of the Anonymous Delegate feature that was implemented in C# 2.0. In C# 3.0, a Lamda Expression provides an easier way to write an anonymous method. A Lamda Expression has its roots deep in Programming Language theory—it appears very similar to the functor construct in Standard ML. It is essentially a way to store a function like a piece of data. Data members can then be applied to the Lamda Expression to produce a result. Lamda Expressions are strongly typed. They derive their type inference based on their usage.

January 23
SharePoint 2007 Search Never Stops Crawling

We recently deployed Microsoft SharePoint Office Server 2007 (MOSS) and ran into an issue with the Office SharePoint Search Service. The Search service was stuck in the "Crawling Full" state. After about 1 week of troubleshooting with Microsoft Product Support, we have resolved our problem. In a nutshell, our Database Maintenance plan included a task to rebuild indexes which had a side effect of removing the ability to allow duplicate keys in the index which SharePoint Search requires. The lesson I learned here is to not include any index maintenance as part of your database back strategy for SharePoint 2007. For more details and how to fix the problem, please read on.

Problem

The problem appeared when we first noticed that our default Content Source for SharePoint Search was stuck in the "Crawling Full" state. During normal operation, once a crawl is complete, the status should change back to Idle.

The problem occurred because our Database Maintenance plan included a Rebuild Index Task that did not preserve the duplicate keys in the index when it was being rebuilt:

Fix

To fix the issue, we had to recreate the 2 indexes that were impacted. One is in the Shared Services Search database and the other is in the WSS 3.0 Search database. Please exercise caution when making these changes and make sure to have database backups before your start.

  1. Shared Services Search Database

    In the SharedServices Search Database, you must ensure that the IX_MSSAnchorPendingChangeLog index in the MSSAnchorPendingChangeLog table ignores duplicate values:

    If this is not enabled, you can follow the steps below to allow duplicate keys:

    1. In SQL Server Management Studio, navigate to the SSP Search database -> dbo.MSSAnchorPendingChangeLog -> IX_MSSAnchorPendingChangeLog index:

    2. Script out the index
    3. Delete the index
    4. Modify the SQL to set IGNORE_DUP_KEY = ON. Here is what our index script looked like (you will need to modify this script to use the appropriate database):

      -- TODO: change this to match the name of your SharedServices Search DB!
      USE [SharedServices_Search_DB]
      G
      O

      CREATE UNIQUE CLUSTERED INDEX [IX_MSSAnchorPendingChangeLog] ON [dbo].[MSSAnchorPendingChangeLog]

          [CrawlId] ASC
          [TargetDocId] ASC
      )WITH (PAD_INDEX = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = ON, ONLINE = OFF) ON [PRIMARY]

  2. WSS 3.0 Search Database

    In the WWS 3.0 Search Database, you must do the same as the SSP Search database and ensure that the IX_MSSAnchorPendingChangeLog index in the MSSAnchorPendingChangeLog table ignores duplicate values. If this is not enabled, you can follow the steps below:

    1. In SQL Server Management Studio, navigate to the WSS 3.0 Search database -> dbo.MSSAnchorPendingChangeLog -> IX_MSSAnchorPendingChangeLog index:

       

    2. Script out the index
    3. Delete the index
    4. Modify the SQL to set IGNORE_DUP_KEY = ON. Here is what our index script looked like:

      -- TODO: change this to match the name of your WSS Search Database Search DB!USE [WSS_Search_MOSSWEB01]
      GO

      CREATE UNIQUE CLUSTERED INDEX [IX_MSSAnchorPendingChangeLog] ON [dbo].[MSSAnchorPendingChangeLog]

          [CrawlId] ASC
          [TargetDocId] ASC
      )WITH (PAD_INDEX = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = ON, ONLINE = OFF) ON [PRIMARY]

  3. The final step, to ensure a clean Shared Services database, we created a new Shared Services Provider and removed the old one. We also removed the offending database maitenance plans.
January 23
DCOM Error with SharePoint 2007/WSS 3.0 Service Account

If you running SharePoint 2007 or WSS 3.0 with a Domain Service Account, and you run into a DCOM Error in the System Log with an Event ID of 10016 and an error description of:

The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID {61738644-F196-11D0-9953-00C04FD919C1} to the user VERTIGO\mossservice SID (removed). This security permission can be modified using the Component Services administrative tool.

You can fix this by following the steps below:

  1. Click Start, click Run, type dcomcnfg in the Open box, and then click OK.
  2. Expand Component Services, expand Computers, expand My Computer, and then click DCOM Config.
  3. Right-click IIS WAMREG admin Service, and then click Properties.
  4. Click the Security tab.
  5. Under Launch and Activation Permissions, click Edit.
  6. In the Launch Permission dialog box, click Add.
  7. In the Select Users, Computers, or Groups dialog box, type the domain user account that you specified as the Windows SharePoint Services 3.0 service account, click Check Names, and then click OK.
  8. In the Permissions for UserName list, click to select the Allow check box that is next to Local Activation, and then click OK two times.

The source for the fix came from Microsoft KB article 920783:

Event ID 10017 error messages are logged in the System log after you install Windows SharePoint Services 3.0
http://support.microsoft.com/kb/920783

The only difference is the Event ID.