quick fix for Beta 2 VB sample problems

If you’ve installed the Beta 2 samples for VB Orcas 2008, then you will likely find the solutions don’t open.  Problem is they are marked as being for “Orcas” not “2008”.  This quick and dirty code will fix the problem:

 

With My.Computer.FileSystem

   Dim samplesPath = .SpecialDirectories.MyDocuments & “\VB Samples Beta2”

   For Each file In .GetFiles(samplesPath, FileIO.SearchOption.SearchAllSubDirectories, “*.sln”)
      Dim contents = .ReadAllText(file)
      contents = contents.Replace(“# Visual Studio Codename Orcas”, “# Visual Studio 2008”)
      .WriteAllText(file, contents, False)
   Next

End With



3 Comments so far

  1.   Roger Jennings on July 31st, 2007          

    Hi, Bill,

    A bit off topic, but I found that ‘Into identifier = Group’ compiles for Group Join and Group By but the Group By implementation throws a runtime error regarding a type conflict. See updates to http://oakleafblog.blogspot.com/2007/07/strange-change-to-vb-join-and-group-by.html for details.

    –rj

  2.   Roger Jennings on July 31st, 2007          

    Hi, Bill,

    Yes, your sample code ran fine in ‘Sample Queries.’ The problem was that I reused the Query## variable in both cases. Here’s the Group Join example that compiles and runs correctly:

    Dim Query11 = From c In CustomerList _
    Where c.Country = “USA” _
    Group Join o In OrderList _
    On c.CustomerID Equals o.CustomerID Into Group _
    From d In Group.DefaultIfEmpty(EmptyOrder) _
    Select New With {c, d}

    ‘Alternative Into identifier = Group syntax

    Query11 = From c In CustomerList _
    Where c.Country = “USA” _
    Group Join o In OrderList _
    On c.CustomerID Equals o.CustomerID Into co = Group _
    From d In co.DefaultIfEmpty(EmptyOrder) _
    Select New With {c, d}

    Here’s what I did for the Group By test:

    Dim Query16 = From c In CustomerList _
    Order By c.Country, c.CustomerID _
    Group c By c.Country Into Group _
    Select Country, Group ‘Optional

    ‘Following throws a runtime error
    Query16 = From c In CustomerList _
    Order By c.Country, c.CustomerID _
    Group c By c.Country Into g = Group _
    Select New With {Country, g} ‘Not optional

    In the Group By case, the data type differs between the implementations because both don’t use New With.

    Assigning a new variable for the second version solved the problem. I’m correcting the post now.

    I do prefer your ‘Group c By cntry = c.Country Into g = Group’ syntax, so am adding it as a third option.

    Thanks much for your help.

    –rj

  3.   bill on July 31st, 2007          

    yes the difference is the New With{ …} syntax will create a mutable anonymous type wehreas the impied Select, or simple Select specifying just the properties, creates an immutable anonymous type.