Archive for the “Visual Studio” Category

There seems to be a problem with the default keyboard mapping of the so called ‘Align Assignments’ found in the Visual Studio 2010 Pro Power Tools.

The default shortcut is mapped to Control + Alt + ]. While this is not a problem on a QWERTY these keystrokes are used to type a square bracket on a AZERTY keyboard:

Azerty keyboard

As you can see the character on the lower right corner needs to be accessed with Ctrl + Alt + key or the Alt Gr + key. This way you trigger the ‘Edit.AlignAssignments’ on your keyboard. Thus the ‘]’ doesn’t appears on screen, it merely aligns the current line.

Edit.AlignAssignments shortcut

Solution: remove or remap the shortcut.

Thanks to Gill Cleeren for pointing out this problem.

Comments No Comments »

I created this class to make life a little bit easier for me.

You are free to use it as you wish!

How to use:

Override this class, override ReleaseManaged() and ReleaseUnmanaged() with the appropriate code, and you are good to go.

namespace SuperDisposeImplementation
{
    using System;

    /// <summary>
    /// Override this class for easy releasing of managed and unmanaged code.
    /// </summary>
    /// <remarks>
    /// By Kristof Mattei
    /// Use as you wish
    /// I don't hold the copyright
    /// Combined from code I found everywhere.
    /// </remarks>
    public abstract class SuperDispose : IDisposable
    {
        /// <summary>
        /// True if managed resources are already cleaned up, false if not
        /// </summary>
        private bool _disposed;

        #region IDisposable Members

        /// <summary>
        /// Implementation of IDisposable.Dispose(). Don't make virtual
        /// </summary>
        public void Dispose()
        {
            this.Dispose(true);
            // This object will be cleaned up by the Dispose method.
            // Therefore, you should call GC.SupressFinalize to
            // take this object off the finalization queue
            // and prevent finalization code for this object
            // from executing a second time.
            GC.SuppressFinalize(this);
        }

        #endregion

        /// <summary>
        /// Dispose(bool disposing) executes in two distinct scenarios.
        /// If disposing equals true, the method has been called directly
        /// or indirectly by a user's code. Managed and unmanaged resources
        /// can be disposed.
        /// If disposing equals false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference
        /// other objects. Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing">True when called from the Dispose, false when called from the ~. Don't call yourself</param>
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this._disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    this.ReleaseManaged();
                }

                // Dispose unmanaged resources.
                this.ReleaseUnmanaged();

                // disposing has been done, make sure we don't dispose the managed ones again.
                this._disposed = true;
            }
        }

        /// <summary>
        /// Override this method, and release unmanaged resources in that method
        /// </summary>
        protected abstract void ReleaseUnmanaged();

        /// <summary>
        /// Override this method, and release managed resources in that method
        /// </summary>
        protected abstract void ReleaseManaged();

        /// <summary>
        /// Use C# destructor syntax for finalization code.
        /// This destructor will run only if the Dispose method
        /// does not get called.
        /// It gives your base class the opportunity to finalize.
        /// Do not provide destructors in types derived from this class.
        /// </summary>
        ~SuperDispose()
        {
            // make sure we don't dispose managed resources, hence the false
            // this is because we can't control the called order of
            this.Dispose(false);
        }
    }
}

Comments No Comments »

When you want to build an Azure application, but you don’t have SQL Express installed the build action in Visual Studio will fail.

You will receive the following message in your output window:

Windows Azure Tools: Failed to initialize the Development Storage service. Unable to start Development Storage. Failed to start Development Storage: the SQL Server instance ‘localhost\SQLExpress’ could not be found. Please configure the SQL Server instance for Development Storage using the ‘DSInit’ utility in the Windows Azure SDK.

To fix this you open the Windows Azure SDK Command Prompt:

Windows Azure SDK Command Prompt

And enter the following text:

dsinit /sqlinstance:.

dsinit /sqlinstance:.

This will cause Azure to use the default instance (with no name). You can switch this to whatever you like, just replace the . (dot) by the appropriate MS SQL instance.

The result will look like this:

Development Storage Initialization

Good luck, happy coding.

Comments No Comments »

image

Check the ‘Insert attribute value quotes when typing under Text Editor > HTML > Format :)

Comments No Comments »

When creating one to many relationships one might bump into the following problem:

Consider the following database design:

Tables:

Customers
-Id
-FirstName
-LastName
-…snip…
-City

Cities
-Id
-Name
-Zip

With a many to one relation from Customers.City to Cities.Id

While this is easy to do in SQL, the LINQ to Entities syntax might seem a bit different.

Consider the following piece of code:

City c = (from city in ctx.CitySet
where city.Name == cityName && city.Zip == cityZip
select city).FirstOrDefault();

This selects the city (if it exists) or null.

Now the problem is: IF the city exists, how do I point the current customer’s city to that particular city.

I tried this:

//customer is a customer object
customer.City = c;

But that resulted in duplicate cities in the database.

The solution was actually quite easy, I browsed through all the properties (Intellisense!) and found this:

customer.CityReference.EntityKey = c.EntityKey;

This resulted in the one to many relationship I had in mind. No duplicate cities in my database.

I love database normalization!

Comments No Comments »

First of all: for those who think that there is an easy solution. I’m sorry, there is not.

The problem is located in the .edmx file, and not in the designer.cs file as I suspected first.

When you add an .edmx and take a look at it with notepad you’ll see this:



	
	
		
		
			
				
				
			
		
		
		
			
				
				
			
		
		
		
			
				
				
			
		
	
	
	
		
			
				
			
		
		
			
				
			
		
		
		
			
			
		
	

Now you add a table:



	
	
		
		
			
				
					
				
				
					
						
					
					
					
					
				
			
		
		
		
			
				
					
				
				
					
						
					
					
					
					
				
			
		
		
		
			
				
					
						
							
								
								
								
							
						
					
				
			
		
	
	
	
		
			
				
			
		
		
			
				
			
		
		
		
			
				
			
		
	

As you can see I’ve added a table ‘Users’ with ‘UserID’, ‘Name’ and ‘Birthday’.

You can also see the difference between the 2.

Now when you delete the table again from the design surface this is what ‘junk’ that stays behind:



	
	
		
		
			
				
					
				
				
					
						
					
					
					
					
				
			
		
		
		
			
				
				
			
		
		
		
			
				
				
			
		
	
	
	
		
			
				
			
		
		
			
				
			
		
		
		
			
			
		
	

As you can see lines 9 and 12-17 weren’t there in the original -empty- model. You’ll need to clean those up manually.

diff

Removing those lines will give you the possibility to re-add your previously deleted table.

Comments No Comments »

Does not work.

Outlook.Application and Outlook._Application are both interfaces. And I want to use them as a class in my program (I don’t know how they made that work).

I wanted to extend Outlook.Application and add a simple method to create a new email. But that does not work since you have to implement a bunch of methods which I hardly understand.

Thank Microsoft for creating extension methods, so here is my solution:

using System;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace SendToExtended
{
	static class OutlookExtensions
	{
		///

		/// Creates and returns an Microsoft Outlook MailItem
		/// 

		///
an instantiated Outlook application
		/// A new MailItem object
		public static Outlook.MailItem CreateMailItem(this Outlook.Application outlook)
		{
			if (outlook == null)
				throw new ArgumentException("outlook parameter cannot be null");

			return (Outlook.MailItem)outlook.CreateItem(Outlook.OlItemType.olMailItem);
		}
	}
}

Comments No Comments »

A while ago I wrote this (Dutch) article on how to perform LINQ to SQL for your SQL Compact databases, since Visual Studio did not understand this, we had to do it manually, as described in the article just mentioned.

But since the release of .NET Framework 3.5 SP1, and the therein included ADO.NET Entity Framework, it is now possible to generate a model out of a SQL Compact database!

Unfortunately this is not (yet) possible for Smart Device applications (Windows Mobile), but who knows what the future might bring!

Comments 1 Comment »

(I quote):

Developer Express and Microsoft are proud to announce a new version of CodeRush licensed exclusively for C# developers working in Visual Studio. The new product is called CodeRush Xpress, and it includes a fresh selection of hand-picked features taken from CodeRush and Refactor! Pro.

And I love it! It has very handy functions for refactoring your code very fast!

I recommend it for everyone!

Usefull links (both contain the downloads):

If you are interested in learning the features you can access these movies:

Dustin Campbell also presented a video on this tool, among other useful Visual Studio 2008 shortcuts  on PDC 2008, you can find it here (click below for wmv-hd download).

Comments 2 Comments »

I just downloaded the Visual Studio 2010 CTP (you can get it here) (an easier way to download the CTP is described here).

When you have downloaded everything you will end op with an VHD (Virtual HardDisk) and VMC (Virtual Machine Configuration). The first one contains the actual C drive of the VM, and the VMC some (default) configuration.

These files are useless in VMware, because you can’t load the VMC, nor can you use the VHD.

But you can convert the VHD (the hard disk) to a VMware-readable format.

These are the steps:

  1. Download WinImage trial here (choose your flavor).
  2. Install/extract (depending on your flavor).
  3. Open the VHD with WinImage: winimage
  4. Open your VHD (you might need to change the filter).
  5. Select Dynamically expanding disk: winimage-dyn
  6. Choose where to save your file.
  7. Now create a new VM in VMware, a Server 2008. And when it asks to create a new Hard Drive you select: Use an Existing Virtual Disk, and point it to your newly created vmdk.

Good luck!

Problems? Leave a comment :)

Comments 1 Comment »

And shepherds we shall be, for thee my Lord for thee, power hath descended forth from thy hand, that our feet may swiftly carry out thy command. We shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine Patris, et Filii, et Spiritus Sancti.