Preventing WPF Controls from Being Displayed in the Visual Studio Toolbox

In other technologies such as Windows Forms and Web Forms, you can adorn a class with the [ToolboxItem(false)] attribute and it will not appear in the Visual Studio Toolbox.

In Windows Presentation Foundation (WPF) you use the [ToolboxBrowsable(false)] attribute instead. This attribute is found in the Microsoft.Windows.Design namespace in the Microsoft.Windows.Design.dll assembly.

Best Regards,
Kevin McNeish
.NET MVP for past seven years
INETA Speaker
Chief Architect,  MM .NET Application Framework
www.oakleafsd.com

Fixing WPF TextBox Mouse Events Not Firing

If you create a handler for the WPF TextBox's mouse events, you will find that the code in your handler never fires. This is because the event is marked as "handled" in the .NET Framework, so it never reaches your code.

To get around this bad behavior, you can use the TextBox's AddHandler() method to register your handler method, passing a true for the handledEventsToo parameter. For example:

this.txtCustomerID.AddHandler(ControlMouseLeftButtonUpEvent, 
    new MouseButtonEventHandler(txtCustomerID_MouseLeftButtonUp), true);

Best Regards,

Kevin McNeish
INETA Speaker
Chief Architect, MM .NET Application Framework
http://www.oaleafsd.com

 

Fixing "Configuration System Failed to Initalize" Exception

If you see the "Configuration System Failed to Initialize" exception at run time, it is typically caused by an invalid entry in your app.config or web.config file. In my case, I encountered this exception when I had an "<add key...>" element out of place. Oddly enough, the compiler didn't warn me about this when I rebuilt my solution with the config file open (as it usually does with most other config file errors).

Best Regards,
Kevin McNeish
INETA Speaker
Microsoft .NET MVP 2002-2009
Chief Architect, MM .NET Application Framework
www.oakleafsd.com

Fixing LINQ Error: Sequence contains no elements

When you get theLINQ Error "Sequence contains no elements", this is usually because you are using the First() or Single() command rather than FirstOrDefault() and SingleOrDefault().

 Take for example the following code that uses First() on the results of the LINQ query. If there are no results, the call to First() triggers the "Sequenc contains no elements" error.:

var rel = (from r in relEnds
   where r.Contains(added.OtherEndKey(entity.EntityKey))
   select r).OfType<EntityReference>().First();

To fix the problem, all you have to do is change First() to FirstOrDefault() which returns a null value when there are no results from the select:

var rel = (from r in relEnds
   where r.Contains(added.OtherEndKey(entity.EntityKey))
   select r).OfType<EntityReference>().FirstOrDefault();

Kevin McNeish
INETA Speaker
.NET MVP 2002-2009
Chief Architect MM .NET Application Framework
www.oakleafsd.com

Entity Framework: Fixing "The number of errors in the conceptual type...does not match with the number of members on the object side type..."

You will typically get the error "The number of errors in the conceptual type...does not match with the number of members on the object side type" in version 1.0 of the Entity Framework when you have manually edited one or more of your entities. In version 1.0 of EF, all members of your conceptual model must be mapped to properties in your object model and all properties in  your entity classes adorned with the EdmScalarProperty attribute must be defined in your conceptual model.

Best Regards,
Kevin McNeish
INETA Speaker
.NET MVP 2002-2009
Chief Architect, MM .NET Application Framework
www.oakleafsd.com

Entity Framework: Programmatically determining the Entity Set name of an Entity

Here is an extension method for the Object Context that allows you to programmatically derive an Entity Set name associated with a particular entity. To put this in context, when adding a new entity object to an Object Context, you need to specify the associated entity set of the entity you are adding.

Here is an extension method for the ObjectContext class that allows you to do this:

public static string GetEntitySetFullName(this ObjectContext, EntityObject entity)
{
   // If the EntityKey exists, simply get the Entity Set name from the key

   if (entity.EntitKey != null)
   {
      return entity.EntityKey.EntitySetName;
   }
   else
   {
      string entityTypeName = entity.GetType().Name;
      var container = context.MetaDataWorkspace.GetEntityContainer(context.DefaultContainerName, DataSpace.CSpace);
      string entitySetName = (from meta in container.BaseEntitySets
                              where meta.ElementType.Name == entityTypeName
                              select meta.Name).First();

      return container.Name + "." entitySetName;

   }
}

Best Regards,
Kevin McNeish
.NET MVP 2002-2009
Chief Architect MM .NET Application Framework
INETA Speaker
www.oakleafsd.com

Understanding the Entity Framework ConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows...

When working with the Entity Framework in n-Tier applications where you are unattaching and attaching entities from an object context, you may encounter this exception:

Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.

This exception is letting you know that no rows were updated. There are several reasons why you may encounter this error.

One simple reason is that when attaching entities to an Object Context, you need to use the AddObject() method if the entity is newly created (and doesn't have an Entity Key), whereas you can use the Object Context Attach() method if the entity already exists and is being updated. Here is some code to demonstrate this (where "EntityContainerName" is the name of your Entity Framework container and "EntitySetName" is the name of the Entity Set to which you are adding the entity):

if (entity.EntityKey == null || entity.EntityKey.IsTemporary)
{
   this.ObjectContext.AddObject("EntityContainerName.EntitySetName", entity);
}
else
{
   this.ObjectContext.Attach(entity);
}

Note that you need to be careful when adding entities that are related to other entity objects because Object Services attempts to add the related objects too.

Best Regards,
Kevin McNeish
.NET MVP 2002-2009
Chief Architect, MM .NET Application Framework
INETA Speaker
www.oakleafsd.com

Using Reflection to Determine if a Property Data Type is Nullable

You can easily determine if the data type of an object property is nullable using the following code:

Type t = objectReference.GetType();
Type pt;

// Test for Nullable
bool isNullable = pi.PropertyType.IsGenericType && pi.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>);
PropertyInfo pi = t.GetProperty("MyPropertyName");

if (isNullable)
{
   // Returns the basic data type without reference to Nullable (for example, System.Int32)
   pt = pi.PropertyType.GetGenericArguments()[0];
}

Best Regards,
Kevin McNeish
Chief Architect, MM .NET Application Framework
INETA Speaker
.NET MVP 2002-2009
www.oakleafsd.com 

Silverlight 3 DataForm Edit Pencil

Here's a quick tip--if your Silverlight 3 DataForm is not dsplaying an Edit Pencil in the upper right corner, set the DataForm's AutoEdit to false (or if using the Visual Studio or Expression Blend IDE, uncheck the AutoEdit checkbox).

Best Regards,
Kevin McNeish
INETA Speaker
Chief Architect MM .NET Application Framework
www.oakleafsd.com

Silverlight 3 and the Bindable Attribute

You may see a number of videos and sample code for Silverlight 3 that uses the Bindable  attribute to specifying editing features of an entity property when working with the Silverlight DataForm control. However, the Bindable attribute (as well as the System.ComponentModel assembly) were removed from Silverlight with the Silverlight 3 RTM.

Now, if you want to specify if an entity property you are binding to should be readonly, set its Editable attribute like this:

 

[

Editable(false)]
public DateTime BirthDate { get; set; }

If you want to specify that a user interface control should not be automatically generated for a particular entity property, set its Display attribute like this:

 

[

Display(AutoGenerateField=false)]
public int EmployeeID { get; set; }

Best Regards,
Kevin McNeish
Chief Architect, MM .NET Application Framework
Oak Leaf Enterprises, Inc.
www.oakleafsd.com

Don't Miss the Silverlight Toolkit for Getting Additional Silverlight Mojo!

Regardless of whether you have installed Silverlight for VS 2008 or VS2010, you will want to install the additional Silverlight Toolkit:

http://www.codeplex.com/Silverlight

This toolkit gives you additional controls, components and utilities released outside the regular Silverlight release cycle. This is good news because Microsoft is releasing new Silverlight functionality iteratively. Rather than providing these controls with a "big bang" release, Microsoft is releasing them iteratively to get feedback from the developer community (can anyone say "user stories") before officially including them in the product.

These new controls are designated with different quality bands, indicating their level of maturity. This helps you decide whether you want to include them in your projects right now, or possibly wait until more mature versions of the controls are released. Here is a list of the four quality bands, listed in ascending order from least to most mature:

- Experimental
- Preview
- Stable
- Mature

Check out this link for a description of each quality level: http://silverlight.codeplex.com/wikipage?title=Quality%20Bands&referringTitle=Home.

This kind of iterative release is a good example for developers to follow. Software developers often have difficulty "letting go" of their code because they don't want to put something in front of end uers that isn't perfect, so they wait until they are finished to get feedback. The problem with this approach is that users can't really provide solid feedback until they have something in front of them that they can play with. So, developers who wait until their software is complete before letting users provide feedback often find themselves rewriting and refactoring their code, and ultimately delaying the release of their software.

The moral is, get feedback as early and often as possible!

Best Regards,
Kevin McNeish
INETA Speaker
Chieft Architect, MM .NET Application Framework
www.oakleafsd.com

 

Pixel Shaders and Silverlight, WPF

Recently, Silverlight 3 gained the ability to use custom pixel shaders as was already available in WPF. What exactly are custom pixel shaders?

A shader is a set of software instructions executed on your computer's Graphics Processing Unit (GPU) that performs complex per-pixel effects suh as applying a lighting value, bump mapping (a technique used to make a surface look more realistic by modeling interaction of a bumpy surface texture), shadows, highlights, translucency, and so on.

Pixel shaders are not a part of Silverlight or WPF, but are a technology used with DirectX. You define pixel shaders using a programming language called HLSL (High Level Shader Language), and this definition is stored in a text file with a .fx extension. You can create shaders using NVidia's Shader Composer Tool (http://developer.nvidia.com/object/fx_composer_home.html)  or other similar tools.

Here is an example of a Negative effect:

sampler2D implicitInput : register(s0);

float4 PS(float2 uv : TEXCOORD) : COLOR
{
    float4 color = tex2D(implicitInput, uv);
  
    float4 result; 
 
    result.r=1-color.r;
    result.g=1-color.g;
    result.b=1-color.b;
    result.a=color.a;
 
  
return result;
}

Note: You can add a text file to your project, give it a .fx extension and then past the above code into it. However, before this code can be compiled properly, you need to change its format to US ASCII. To do this:

- Select the .fx file in the Solution Explorer
- From the Visual Studio File menu, select Advanced Save Options...
- In the Encoding drop down, select US-ASCII

Setting up the Development Environment

Before you can use a pixel shader definition, you must compile the pixel shader .fx source code file into byte code stored in a .ps file. To do this, you need to install the DirectX SDK on  your computer (http://www.microsoft.com/downloads/details.aspx?FamilyID=24a541d6-0486-4453-8641-1eee9e21b282&displaylang=en).

The DirectX SDK has a shader compiler called fxc.exe. By default, it's stored in the following folder on your computer (the month changes as new versions are released):

C:\Program Files\Microsoft DirectX SDK (November 2008)\Utilities\bin\x86\fxc.exe

You need to set up Visual Studio so it knows how to use the fxc.exe tool. To do this:

- In the Visual Studio Tools menu, select External Tools which launches the External Tools dialog.
- Click the Add button, and enter the following information:

        - Title: Microsoft &Shade Compiler (fxc.exe)
        - Command:  C:\Program Files\Microsoft DirectX SDK (November 2008)\Utilities\bin\x86\fxc.exe
        - Arguments: /DWPF /Od /T ps_2_0 /E $(ItemFileName)PS /Fo$(ProjectDir)$(ItemFileName).ps $(ItemPath)
        - InstallDirectory:  $TargetDir

- Select the Use Output Window checkbox, then click OK to add the new external tool entry

Now to run the compiler against a .fx file, select the .fx file in the Solution Explorer, then go to the Tools menu and select Microsoft Shader Compiler (fcx.exe). In the Visual Studio Output Window, you should see a "compilation succeeded" message, and the compiler should produce a .ps file with the same stem name as the .fx file. You should include this new file in your project, then set its Build Action property to Resource.

In order to use the new compiled shader effect, you need to create a ShaderEffect class. that loads the pixel shader. First, in your WPF or Silverlight project, you create a subclass of the .NET Framework's ShaderEffect class.  Here's an example:

 

 

public class SwirlEffect :

ShaderEffect

{

 

 

private static PixelShader _pixelShader = new PixelShader()

{

UriSource =

 

new Uri("MyVideoProject;component/Swirl.ps",

 

 

UriKind.Relative)

};

 

 

public SwirlEffect()

{

PixelShader = _pixelShader;

UpdateShaderValue(InputProperty);

UpdateShaderValue(FactorProperty);

}

 

 

public static readonly DependencyProperty InputProperty =

 

 

ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(SwirlEffect), 0);

 

 

public Brush Input

{

 

 

get { return (Brush)GetValue(InputProperty); }

 

 

set { SetValue(InputProperty, value); }

}

 

 

public static readonly DependencyProperty FactorProperty =

 

 

DependencyProperty.Register("Factor",

 

 

typeof(double), typeof(SwirlEffect),

 

 

new PropertyMetadata(0.0, PixelShaderConstantCallback(0)));

 

 

public double Factor

{

 

 

get { return (double)GetValue(FactorProperty); }

 

 

set { SetValue(FactorProperty, value); }

}

 

 

 

Best Regards,
Kevin McNeish
INETA Speaker
Chief Architect, MM .NET Application Framework
www.oakleafsd.com

Handling Trailing Spaces with VFP Data and ADO.NET

When working with Visual FoxPro data in ADO.NET, you may be surprised to see trailing spaces at the end of your character data. Visual FoxPro automatically trims these trailing spaces in BROWSE windows and when binding to user interface controls, but .NET does not.

To address this issue, you can change your character fields to varchar fields (introduced in VFP 9.0). You can then write a quick utility to remove the trailing spaces from the character data.

If you can't remove the extra spaces due to requirements in your Visual FoxPro applications that are accessing the same data, you can remove the spaces programmatically in your .NET applications by adding RTRIM() commands to your ADO.NET SELECT statements. For example:

SELECT employeeid, lastname, RTRIM(firstname) as FirstName, title, titleofcourtesy, birthdate, hiredate, address, city, region, postalcode, country, homephone, extension, photo, notes, reportsto FROM Employees

Best Regards,
Kevin McNeish
Chief Architect MM .NET Application Framework
www.oakleafsd.com

 

.NET Framework 4.0 Beta 2 Installation Error: Unable to create or save new files in the folder...

When trying to install the .NET Framework 4.0 Beta 2 on the Windows partition of my Macbook Pro, I encountered this error:

Unable to create or save new files in the folder into which
the files are being extracted. Please check the folder properties
to ensure you have permission on the folder to
write files and that the folder is not read-only.

Apparently, Visual Studio 2010 Beta 2 is trying to extract files into my Mac partition--even though i didn't tell it to do this!

To fix this problem:

1. Launch Control Panel
2. Select System and Security
3. Select Administrative Tools
4. Double-click Computer Management to launch the Computer Management Console
5. Select the Disk Management node in the left pane
6. In the right pane, right-click the Mac drive (E: in my case)
7. Select Change Drive Letter and Paths... from the shortcut menu
8. In the Change Drive Letter and Paths dialog, select the Mac drive and click the Remove button
9. When the Disk Management dialog is displayed, click Yes to the confirmation question.
10. When the second Disk Management dialog is displayed, click Yes again to continue.

Now .NET Framework Beta 2 installs without a hitch!

Best Regards,
Kevin McNeish
iNETA Speaker
Chief Architect, MM .NET Application Framework
www.oakleafsd.com

Visual Studio 2010 Version Comparison

It's official that Microsoft plans to release Visual Studio 2010 / .NET 4.0 in March 2010. I found this link helpful in determining the difference between the VS 2010, Professional, Premium and Ultimate versions:

http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx

Best Regards,

Kevin McNeish
Chief Software Architect - MM .NET Application Framework
INETA Speaker
www.oakleafsd.com

Fixing the MS Office SP2 "Outlook cannot connect to your incoming POP3 account" error

Bad Outlook Juju

So, when I got up this morning, I noticed my computer had rebooted--my main development machine is a MacBook Pro, and I was booted into Mac OSX rather than Windows Vista where I had left it last night.

Step 1: Uninstalling Microsoft Office SP2

I then realized I couldn't send or receive mail--the last mail I received was from last night--so I immediately suspected a problem with a Windows Update. Sure enough, after a quick Google search I determined that others were experiencing the same problem. Fortunately, Googled "Uninstall Microsoft Offfice SP2" andI came across a link that mentioned an uninstall tool for Office 2007 that allows you roll back the service pack:

http://download.microsoft.com/download/3/9/A/39A9BC06-AB8C-4097-80D7-755012D9B9C3/office2007spuninstall.exe

UNFORTUNATELY, this didn't work for me, but it's definitely worth a try if you are experiencing the same problem, because it definitely did fix the problem for others...

The caveats in the readme.txt file mentioned that this uninstall tool only works for MS Office Service Pack 2 or higher. Here are the other conditions:

- Assists in uninstalling client patches only; Does not install server patches
- Command Line tool so help can be accessed by running "oarpman /help" from the command line. This will describe each of the available commands
- Using the /log switch with the /report switch provides some extra information in the log that is not output to the console.
- A “release” is a collection of patches. To see what releases are available for uninstall, use the /report switch. The 2007 SP Uninstall Tool will remove all of a given release. It does not uninstall per patch, or per product.  For example, if you have Microsoft Visio Service Pack 2, Microsoft SharePoint Designer Service Pack 2, and Microsoft Office Professional Service Pack 2 on the computer, the tool will attempt to uninstall all three.
-The /report switch will only display patches that are part of a release that the tool can uninstall.
-When logging is enabled with /remove, the MSI logs are also copied into the same directory as the oarpman log.

The Readme.txt file also contains the following basic workflow for uninstalling:

1 - User installs (or has already installed) Service Pack 2 or higher.
2 - User downloads the 2007 SP Uninstall Tool and expands the package to a working directory.
 Please Note: You must choose a subfolder for expanding the tool (e.g., c:\subdir). You cannot expand the tool into the root directory of the drive (e.g., c:\).
3 - User opens a command prompt under administrator context and navigates to oarpman.exe.
4 - User wants to see what the tool can do, so types:  “oarpman /help”
 Help is shown, describing the tool and switches.
5 - User wants to see what can be uninstalled, so types: “oarpman /report /log c:\logfolder\logname.log”
 The /log switch is optional, but does provide extra information that is not displayed to the console window.
6 - User now looks at the console window, or opens the log, and notes what patches are installed. Also, identifies what releases are installed by looking at the “Release” column.
7 - User wants to remove the Service Pack from the machine, so types: “oarpman /remove <release name> /log c:\logfolder\logname.log”
 This will begin removing the Service Pack release from the computer, create an oarpman log, and copy the MSI logs to the path specified with the /log switch. The time it takes to uninstall will vary, based on how many products are installed, how many Service Pack updates are installed, the speed of your processor, etc. Uninstall may take as long, or slightly longer, than it took to install the Service Pack updates.
8 - User may run “oarpman /report” again to verify that all releases have been removed.

When you run the uninstaller, you will see a number of messages that look something like this:

<Guid> <Guid>
Success

Don't close the Command Window yet! When Service Pack 2 has been successfully removed, you will see a message in the command window that says:

UninstalDon't rebott yourl successful. Please reboot..

At that point, I rebooted and Outlook and am STILL not able to send/receive e-mail...now I'll try completely uninstalling Outlook and installing it again!

Step 2: Completely Uninstalling and Reinstalling Microsoft Office

Unfortunately, although this step didn't work for me. After uninstalling and reinstalling, I was STILL unable to send/receive e-mail and was STILL getting the "Outlook cannot connect to your incoming POP3 account" error!

Step 3: Uninstalling individual updates

At this point--still trying for the minimal approach, I rolled back individual updates that had been applied to my machine the night before.To determine which updates were applied, you can do the following:

1. Go to the Windows Control Panel
2. Open up the Windows Update section of the Control Panel
3. At the top of the Window is an option to uninstall updates. Click on that...
4. In the list of installed updates, select an update and then click Uninstall

This took a few hours to complete...again, unfortunately I was still getting the same error in Outlook!

Step 4: Install Windows 7

Well, I had meaning to install Windows 7 anyway, so, left with little options, I downloaded and installed Windows 7 on my machine. I decided to do an upgrade rather than a fresh install, and the installation actually went very well! My laptop was mostly functioning, but now I couldn't access the Internet through Internet Explorer or from Outlook.

Step 5: Install the new Snow Leopard OSX Operating System and Parallels Desktop 4.0

As I mentioned earlier, I'm running both Windows and OSX on my Macbook Pro. I thought it best to get the latest OSX drivers (Bootcamp drivers) that work with Windows 7. As it turns out I needed to upgrade OSX from Leopard to Snow Leopard. Since my wife and I were headed out that day to Richmond, VA, I stopped at the Apple Store and picked up a copy of Snow Leopard as well as the latest version of Parallels Desktop--this is the tool I use to run Windows applications from within the Mac OSX.

The installation of Snow Leopard worked without a hitch, as did the installation of Parallels Desktop 4.0. I could now run a Windows 7 virtual machine from OSX. I set up Parallels desktop so my Windows virtual machine could share an Internet connection with OSX. However, even though I could access the Internet from OSX, I was still unable to access it from Windows 7--whether I ran it from an OSX virtual machine or if I booted directly into Windows 7 at startup.

Step 6: Installed the New Version of Norton Internet Security

Interestingly enough, I was able to access the Internet on Windows 7 by using the Safari browser--worked without a hitch, so I knew my Internet connection was working well. Also, I tried booting into Windows 7 with Safe Mode, and I was able to access the Internet using Internet Explorer, Safari, and Outlook...I was almost there. When you have problems accessing the Internet, it is often caused by an anti-virus or firewall program. So, I checked out the Norton web site and discovered there was a new version of Norton Internet Security that works well with Windows 7. I purchsed the upgrade, downloaded and installed and....it worked! Now I am completely up and running with MacBook Pro running OSX and Windows 7.

This is certainly more fun than one person should have!

Best Regards,

Kevin McNeish
INETA Speaker
.NET MVP from 2002-2009
Chief Architect MM .NETApplication Framework
www.oakleafsd.com

 

Visual Studio 2010, .NET 4.0, C# and VB .NET 4 - What's New?

I'm starting a series of blog posts today on what's new in the following technologies:

- Visual Studio 2010
- .NET 4.0
- C# and VB .NET 4

I'll be giving my take on these technologies, grading them, and talk about how they can and should impact your software development.

Here's the big picture for Visual Studio 2010...in subsequent posts we will dive down into details of the new features.

Visual Studio 2010

Visual Studio itself has changed more than any of the other technologies. Working with the beta, I'm amazed at how stable it is. Here are some of the big changes (note that I'm only listing changes for VS 2010 at design time--I'll be talking about other changes to core technologies such as WPF, WF, ASP.NET, and so on in a future post):

WPF and Silverlight

If you are a WPF or Silverlight developer, you need to use Expression Blend less because:

- Data Binding is now supported for WPF and Silverlight applications - you can even use Drag and Drop to quickly create and bind a user interface
- You can now lay out a user interface in Silverlight - in VS 2008, there was only support for WPF UI layout

Entity Framework Enhancements

- Model-First is now supported - in VS 2008, EF design was bottom up - you could only create an Entity Data Model from a database. Now you can create a database from an Entity Data Model

- Greater control over how foreign keys are handled

- It's easier to test Entity Framework applications

- You can use Plain-Old-CLR objects (POCO) with the EF. You don't need to subclass your entity objects from a .NET entity type or implement an interface - unless you want to

- It's easier to create n-tier apps with EF

- It's easier to customize the code generated by the EF

- The Model Browser window allows you to delete objects from the storage model

- You can now search the conceptual and storage models for a specific string

- Automatic pluralization / singularization of class names when generating from a database

- Lazy loading and more stored procedure mapping abilities

- Better LINQ support

- Improved T-SQL performance and improved readability of generated queries

ASP.NET

- Clean web.config files contain less information by default

- New project templates that provide more functionality out of the box

- ASP.NET Code Snippets now work for HTML, ASP.NET markup, and JavaScript

- New field templates for URLs and e-mail addresses

- New dynamic hyperlink control

- Client template rendering

- Improved CSS Compatability

- JScript IntelliSense enhancements

- Deployment improvements including:

- Web packaging (creates a deployment zip file with everything you need to install)
- Web configuration-file transformation (Transform a web.config file from development to production settings)
- Database deployment - (VS includes SQL Scripts and optionally data in the deployment package which it can run at installation time)
- One-cick publishing (Use IIS remote management service to publish a Web application to a remote server)

- Support for the MVC-Based Web Applications

- Enhancements to ASP.NET Multitargeting

Visual Studio 2010 Editor

- Enhanced docking behavior, including support for multiple monitors

- Zoom in/out of any code editing window or or text editing window

- Call hierarchy for C# is available at design time (vs. stack trace available at run time) that allows you to explore execution paths by examining compex chains of method calls.

- Navigate To - Allows you to search for a symbol or file in the source code

- Highlighting References - When you click a symbol in source code, all instances of that sybol are automatically highlighted

- Generate from usage - allows you to use classes and members before you define them

- IntelliSense now has two modes--standard and consume-first. You use consume-first if you are using classes and members before they are defined (Type Ctrl+At+Space to switch to consume-first mode). This is useful when doing Test-Driven-Development and you are writing tests first.

Team System Architecture

- New architecture explorer

- New Model Explorer

- New Diagrams support for UML 2.1.1

- Layer diagrams
- UML Class diagrams (different than the class diagrams introduced in VS 2005 - now there are two kinds of class diagrams)
- UML Activity diagrams
- UML Use case diagrams
- UML Sequence diagrams
- UML Component diagrams

- New Modeling Project which contains your UML diagrams

- Generate Sequence, Class, and Layer Diagrams from code

Office Business Applications

- Build Office applications that span multiple versions of Office

- New designer support for building flexible UI's in WPF or Fluent

- Easier to consume data with LINQ and enhanced data-binding capabilities

Visual Studio Extensions

Extension Manager lets users easily add and remove Visual Studio Extensions

Quality / Testing

- Test Impact View - Identify and run only tests impacted by specific code

- Test Runner Tool - New tool that a test users to guide them through a series of steps to complete a test case. It can take snapshots of test environment, appication screen shots an video for assistance in reproducing bugs

Soure Control

- New enhanced version control features including gated check-in, branch visualization and build workflow

- Can now perform constraint checks on code during check-in based on the Architecture Layer Diagram

Project Management

- New integation with Project Server for enterprise-wide project management

- New features for Agile project scheduling with Excel

Best Regards,
Kevin McNeish
INETA Speaker
Chief Architect - MM .NET Application Framework

ASP.NET: Storing JavaScript in a separate .js file
Rather than hard-coding your JavaScript into an aspx page, you can store you JavaScript functions in a separate .js file. This allows your furnctions to be used from multiple pages.

For example, you could add a .js file to your project (right-click your project and select Add New Item | JScript File) from the shortcut menu) and place the following function in it:

 

function isValidEmail(emailAddressControl) 
{
    var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
    var emailid = emailAddressControl.value;
    var matchArray = emailid.match(emailPat);
    if (matchArray == null) {
        alert("Invalid e-mail address");
        emailAddressControl.focus();
        return false;
    }
    return true;    
}

In your web form Page_Load, you can add the following code

 

if (!Page.ClientScript.IsClientScriptIncludeRegistered(typeof(pgOrders), "MyScript"))
{
    Page.ClientScript.RegisterClientScriptInclude(typeof(pgOrders), "MyScript", "JScript.js");
}

The call to IsClientScriptIncludeRegistered() checks if the JavaScript file has already been included. The call to RegisterClientScriptInclude() actually registers the script.

From within your .aspx page, you can call this JavaScript function after the user leaves the e-mail field by doing something like this:

 

<asp:TextBox ID="txtEmail" runat="server" Width="265px" onblur="isValidEmail(this)"></asp:TextBox>

 


Note: The first parameter of RegisterClientScriptInclude() accepts a type object which it uses to uniquely key the registered script. The MSDN documentation samples for this method use a call to this.GetType() to get the current page type dynamically at runtime--however, this can be a problem if you ever subclass your web page. The call to this.GetType() will return a different class than the class in which this code is actually defined. I's best to specify the actual type of the page itself by doing something like this:

 

typeof(pgOrders)

In this example, pgOrders is the actual type of the page in which the JavaScript is being included. This works better, because you are statically typing the reference to the page at compile time rather than dynamically determining the type of the page at runtime.

 

Kevin McNeish
Chief Architect MM .NET Applicatoin Framework
INETA Speaker
www.oakleafsd.com 


Last Updated: 10/3/2009

Entity Framework "Problem in Mapping Fragments" Error

If you add an entity to the Entity Data Model, then later add another entity that is related in the database to the first entity, Visual Studio will give you a "Problem in Mapping Fragments" error.

For example, if you add a Northwind database Orders table using the EDM Update Wizard, it produces an entity that looks has an EmployeeID property that corresponds to the EmployeeID foreign key column of the Orders table.

Next, if you add a Northwind database Employees table using the EDM Update Wizard, an Employees property gets added to the bottom of the Orders entity under Navigation Properties and a relationship between the Orders and Employees entities is shown on the diagram. However, there is still an EmployeeID property on the Orders entity. This is what causes the "Problem in Mapping Fragments" error.

In order to get around this error, you can simply remove the redundant EmployeeID property from the Orders entity by right-clicking it in the designer and selecting Delete from the shortcut menu.

Kevin McNeish
Microsoft .NET MVP
Chief Architect, MM .NET Application Framework
www.oakleafsd.com

 

Problem: "Mapping URI" errors with WPF Assembly Names that include spaces

This is a somewhat insidious bug. As it turns out, if you have spaces in your WPF project's assembly name, you can get "Mapping URI" errors in your project's XAML (even if the solution itself builds properly). As you might imagine, you can get around this bug by changing the namespace. For example:

Change this:

OakLeaf MM WPF

To:

OakLeaf.MM.WPF

Kevin McNeish
Microsoft .NET MVP
INETA Speaker
Chief Architect, MM .NET Application Framework
http://www.oakleafsd.com

More Posts Next page »