Opening Solution File Won’t Start Visual Studio


If you are running Windows Vista or Windows 7 with UAC enabled and Visual Studio set to Run as Administrator and you try to open a Solution File through Windows Explorer, Visual Studio will not open. If you check the “Choose default program” for SLN files you will see that is set to use Microsoft Visual Studio Version Selector, which is the source of the problem. What I think is happening is that the version selector recognizes the right program to open, but since it is not running in elevated trust (Run as Admin) it doesn’t have enough permissions to run another program (Visual Studio) as an Admin and Windows kills it.

image

The solution is to change the Microsoft Visual Studio Version Selector to run as an admin. To do so navigate to %ProgramFiles%\Common Files\Microsoft Shared\MSEnv or %ProgramFiles(x86)%\Common Files\Microsoft Shared\MSEnv (64-bit), right click on VSLauncher.exe and select Properties. Go to the Compatibility tab and check “Run this program as an Administrator”.

Thanks Gene Merlin for the tip!

author: Jonas Stawski | posted @ Monday, August 23, 2010 9:23 AM | Feedback (0)

Windows Phone 7 Developer Tools Beta Released


Windows Phone 7 Developer Tools Beta have been released.

Tools

Download the Windows Phone Developer tools beta to get started creating Windows Phone 7 applications today. This download includes: Visual Studio 2010 Expression For Windows Phone beta; Windows Phone Emulator beta; Silverlight for Windows Phone beta; Expression Blend for Windows beta; and XNA Game Studio 4.0 beta.

http://www.microsoft.com/downloads/details.aspx?FamilyID=c8496c2a-54d9-4b11-9491-a1bfaf32f2e3&displaylang=en

 

Training

Jump start your development of Windows Phone 7 applications by attending Windows Phone 7 JumpStart. This free virtual live class, comprised of four instructor-led 3 hour sessions, will guide you in developing applications for the Windows Phone 7 platform using Silverlight and XNA. Register today by visiting: https://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032455932&EventCategory=2&culture=en-US&CountryCode=US.

Course sessions:

July 20 – 8am (PDT): Session One: Getting Started with Microsoft Windows Phone and Silverlight
July 20 – 1pm (PDT): Session Two: Programming Game Applications with XNA
July 22 – 8am (PDT): Session Three:  Programming Applications with Silverlight
July 22 – 1pm (PDT): Session Four:  Review and Wrap Up

author: Jonas Stawski | posted @ Thursday, July 15, 2010 11:43 AM | Feedback (0)

Geospatial Article Part 1 on Simple Talk


Part 1 of my Mapping Your Data with Bing Maps and SQL Server 2008 article is now published on Simple-Talk. Go read it and learn how to integrate Bing Maps into your existing or new apps to solve business needs.

Happy Reading!

author: Jonas Stawski | posted @ Wednesday, March 24, 2010 5:13 PM | Feedback (2)

Restart your Elevated Trust, Out-Of-Browser (OOB) Silverlight App


With the release of Silverlight 4 RC you can now close your app programmatically, but unfortunately, you can’t restart it. Why would you want to restart it? Because when the app finds a new update, the update won’t take place until the next restart of the application. In some cases that is ok, but with all the new features of Silverlight 4 for OOB and the support for touch, more and more people are utilizing Silverlight for Kiosk applications, where the application shouldn’t rely on a user to restart it.

Fortunately when you are running on Elevated Trust and OOB you can use the AutomationFactory, which “provides access to the Automation servers.” In Windows that means you get access to COM+, therefore allowing you to do anything COM+ can do. As of this writing, this feature is not available for Mac.

So to restart our app we can use the AutomationFactory to execute a WScript.Shell command by calling the SLLauncher. Unfortunately for us, the SLLauncher requires some arguments that are unknown at runtime and you can see those arguments if you right click on your desktop shortcut – Properties. The big number is a random number that Silverlight generates when the app is first installed and there is no API to retrieve it, so before we can call the SLLauncher command we need to retrieve it by using… yep, you guessed it, the AutomationFactory. Bellow is the code:

image

   1: private string GetSLLauncherCommand()
   2: {
   3:     string desktopPath;
   4:     string SLLauncherCommand = "";
   5:     using (dynamic wShell = AutomationFactory.CreateObject("WScript.Shell"))
   6:     {
   7:         desktopPath = wShell.SpecialFolders("Desktop");
   8:     }
   9:     using (dynamic shell = AutomationFactory.CreateObject("Shell.Application"))
  10:     {
  11:         dynamic folder = shell.NameSpace(desktopPath);
  12:         dynamic items = folder.Items();
  13:         foreach (dynamic item in items)
  14:         {
  15:             if (item.IsLink)
  16:             {
  17:                 string fileName = item.Name.ToLower();
  18:                 if (fileName.Contains("appname"))
  19:                 {
  20:                     dynamic link = item.GetLink();
  21:                     SLLauncherCommand = "\"" + link.Path + "\" " + link.Arguments;
  22:                 }
  23:             }
  24:         }
  25:     }
  26:  
  27:     return SLLauncherCommand;
  28: }

WARNING: note that this code takes into account that the desktop shortcut of the application will always be there. If you can’t count on that then you should check the start menu. Don’t forget to add more robust checking.

So we first use WScript.Shell to get the user’s desktop path by calling the SpcialFolders method. once we have that, we use the Shell.Application objects to get a hold of the desktop shortcut by iterating over all icons and selecting the apps shortcut (.lnk). Once we find the file we use the GetLinkmethod to be able to retrieve the path and the arguments of the shortcut. Since this operation is very expensive, I recommend saving the command in IsolatedStorage or in memory. The next step is the actual restart and we do so with the following code:

   1: public static void StartAgain(string SLLauncherCommand)
   2: {
   3:     if (!String.IsNullOrEmpty(SLLauncherCommand))
   4:     {
   5:         try
   6:         {
   7:             using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
   8:             {
   9:                 shell.Run(SLLauncherCommand);
  10:             }
  11:  
  12:         }
  13:         catch { } //eat the exception
  14:     }
  15: }

Don’t forget to close your app after calling the StartAgain() method by calling

   1: Application.Current.MainWindow.Close();

Happy Programming!

author: Jonas Stawski | posted @ Friday, March 19, 2010 4:22 PM | Feedback (1)

South Florida Code Camp 2010


This year was another great year for the South Florida Code Camp. Lots of people, sessions, speakers, books, software, food, water, sodas, and a great atmosphere. Both of my Programming Web 101 and 201 sessions went great. I had a small problem with time for my 201 session as I was told by a person I had to end by 10:50, when in reality I had until 11. I apologize to everyone who was at my 201 session for not being able to cover the entire presentation.

You can download both the presentation and the project files from the following links:

Programming Web 101

Programming Web 201

Happy Programming!

author: Jonas Stawski | posted @ Monday, March 01, 2010 11:33 AM | Feedback (3)

Silverlight, WCF, and Cross Domain


Last night I was trying to consume a WCF service using Silverlight and I ran into the Cross Domain problem that a lot of people have already ran into. Here’s the message of the exception:

An error occurred while trying to make a request to URI 'http://localhost:1292/WASService/Service.svc/Service'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.

I have already heard about this error and I knew that it could easily be solved by adding clientaccesspolicy.xml and/or crossdomain.xml to the root of the application. You can find a very detail description of when you are attempting to go across domains in this forum: http://forums.silverlight.net/forums/p/24005/86700.aspx (look for sladapter answer). You can also find more info on by reading the Network Security Access Restrictions in Silverlight. The problem I was having is that both of the files were already in the root of the application.

image

I decided to use firebug to see what was going on:

image

and that’s when it hit me. Silverlight is trying to access the xml files on the root of the webserver, not on the root of the application. My files are located on http://localhost:1292/WASService/clientaccesspolicy.xml and http://localhost:1292/WASService/crossdomain.xml. “Easy fix,” I thought, “just change the files to the root.” The problem is that this is hosted using the WebDevServer (Cassini) and there is no root folder. It turns out that Scott Guthrie wrote about running the app as a root with the local web server. So All I had to do was to bring the properties of the project (F4 on the project) and change the Virtual path from “/WASService” to “/”.

image

Now all I had to do was change the service reference on the Silverlight app and I was up and running in no time.

image

Happy programming!

author: Jonas Stawski | posted @ Friday, February 05, 2010 10:07 AM | Feedback (3)

Problem Creating a Localized, Embedded Script


I was following this tutorial and was getting the error: Assembly 'AssemblyName' contains a Web resource with name 'ResourceName', but does not contain an embedded resource with name 'ResourceName'. Everything seemed to be perfect except that I forgot to set the JS file to build as an Embedded Resource:

image

Happy Programming!

author: Jonas Stawski | posted @ Saturday, January 16, 2010 3:42 PM | Feedback (1)

Follow All Microsoft MVPs through Twitter


Scott Dorman created a list where you can follow all Microsoft MVPs through Twitter. Go ahead and follow us. If you’re an MVP and are not in the list you can let @sdorman know.

Happy Twitting!

author: Jonas Stawski | posted @ Tuesday, January 05, 2010 7:09 PM | Feedback (1)

Windows Phone Camp 2009 – Tampa Bay


The first Windows Phone Camp 2009 in Tampa is around the corner. I wouldn’t miss it if I were you. The idea is to be similar to a Code Camp, but for Windows Mobile development. You get 8 sessions one after the other from getting started, to using the GPS, to building games. There will be free lunch and lots of prizes.

The date is December 5th, mark your calendars…

Happy WM Programming!

author: Jonas Stawski | posted @ Monday, November 30, 2009 12:28 PM | Feedback (1)

Powershell Script for Compressing DB Backups


The following Powershell script compresses all the .BAK files using winrar.

   1: cd D:\MSSQL\MSSQL.1\MSSQL\Backup
   2: $dirs = get-childitem|where{$_.PSIsContainer}
   3: foreach ($dir in $dirs) {
   4:     cd $dir
   5:     $files = get-childitem *.bak
   6:     foreach ($file in $files) {
   7:         #Check for null
   8:         if ($file -ne $NULL){
   9:             #write-host $file.Name.Replace(".bak", "")
  10:             & "c:\program files\winrar\rar" a $file.Name.Replace(".bak", "") $file.Name
  11:             remove-item $file
  12:         }
  13:     }
  14:     cd ..
  15: }

Walk through:

1. Change directory to the backup root directory
2. Get all the subdirectories and iterates through each one
3. Get all *.BAK files and iterate through them
4. Use the winrar command line to compress the file
5. remove the .BAK file

Happy Powershelling!

author: Jonas Stawski | posted @ Monday, November 16, 2009 1:43 PM | Feedback (1)