Jesse Johnston
{ ironic tagline here }

Windows Azure: Where is my stuff?

Wednesday, 3 August 2011 06:17 by jesse

So you’ve deployed an application to Azure.  If you login to the deployment with Remote Desktop, your first question might be “Where is my application installed?”.

There are three disk drives in the deployment.

  • Drive C: contains your local storage folders
  • Drive D: is the operating system
  • Drive E: contains your application files

Local Storage Folders

In C:\Resources\Directory, you will see each of your local storage folders.  These are prefixed with a generated Id.  Note that you will not have permissions to open any of the files in these folders unless you added permissions via a startup task.  See my previous post for an example of how to do this.

Your Deployment

Your uploaded application files are located in E:\approot.  You can refer to this location in your code with the RoleRoot environment variable (RoleRoot will resolve to “E:\”, so you’ll need to append “approot”).

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Tags:  
Categories:   .NET | Windows Azure
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Windows Azure Deployment Tips & Tricks

Wednesday, 3 August 2011 05:48 by jesse

I’ve run into a few gotchas when deploying to Azure.

  • Missing DLLs. Not all “system” libraries are included in the Windows Azure run-time environment.  If you use any of these, make sure to mark them as CopyLocal=true in your project.  The one I always forget is EntityFramework.dll.
  • Folder permissions.  If you add local storage folders to your deployment, you might be surprised to find that when logged in to the deployment machine with Remote Desktop, you won’t have even read permission to files in local storage folders.  Fortunately, you can easily add a startup task to grant permissions.  In my deployments, I use a batch file to launch a PowerShell script to do this.  The batch file (fixPermissions.cmd) looks like this:

    powershell -ExecutionPolicy Unrestricted .\FixFolderAccess.ps1

    The PowerShell script (FixFolderAccess.ps1) looks like this:

    Add-PSSnapin Microsoft.WindowsAzure.ServiceRuntime
    
    while (!$?)
    {
        echo "Failed, retrying after five seconds..."
        sleep 5
    
        Add-PSSnapin Microsoft.WindowsAzure.ServiceRuntime
    }
    
    echo "Added WA snapin."
    
    $localresource = Get-LocalResource "myLocalStorageFolderName"
    $folder = $localresource.RootPath
    
    $acl = Get-Acl $folder
    
    $rule1 = New-Object System.Security.AccessControl.FileSystemAccessRule(
      "Administrators", "FullControl", "ContainerInherit, ObjectInherit", 
      "None", "Allow")
    $rule2 = New-Object System.Security.AccessControl.FileSystemAccessRule(
      "Everyone", "FullControl", "ContainerInherit, ObjectInherit", 
      "None", "Allow")
    
    $acl.AddAccessRule($rule1)
    $acl.AddAccessRule($rule2)
    
    Set-Acl $folder $acl
    
    echo "Done changing ACLs."
  • Startup tasks.  When adding a startup task, you need to do two things: first, add the task to the role in your .csdef file.  This will look something like this:

      <WorkerRole name="MyWorkerRole">
        <Imports>
          <Import moduleName="Diagnostics" />
          <Import moduleName="RemoteAccess" />
        </Imports>
        <Startup>
          <Task commandLine="startup.cmd" executionContext="elevated" taskType="background" />
        </Startup>
      </WorkerRole>

    The execution context can be “elevated” if the command you’re running requires administrative privileges, or “limited” to use the same privileges as the role itself.  The task type can be “simple”, where other tasks (and the role itself) are not started until the task finishes, or “background”, in which other tasks and the role can be started before the task completes.  A third type, “foreground” allows other tasks to start before it is finished, but the role is not started until the task finishes.

    The second part of creating a startup task is to create the batch file that is referenced in the <Task> element above.  In this case, it is startup.cmd.  It is essential that you save this file without a byte order mark.  To do this from Visual Studio, when saving the batch file, use Save As, and select the option Save with Encoding from the Save button dropdown.  Select Unicode (UTF-8 without signature) – Codepage 65001.  If you prefer, you can just create the batch file with Notepad, which will also save it without the offending byte order mark.

    A final note about startup tasks:  If you use PowerShell in a startup task, you need to set your ExecutionPolicy to allow unsigned scripts (as shown in the example above: -ExecutionPolicy Unrestricted).  This is only supported in PowerShell 2.0, which means that you need a Windows Server 2008 R2 run-time environment.  This is not the default in Azure.  To enable this, set the <ServiceConfiguration> tag in your .cscfg file to specify osFamily=”2”.  This requests the Windows Server 2008 R2 environment instead of the default Windows Server 2008 SP2.
  • Custom performance counters.  They are supported in Azure.  You do have to create the performance counter category in an elevated startup task, as the role itself does not have the required permissions.
  • Can a Worker Role handle HTTP requests?  Sure it can.  Just make sure that you add an inbound rule to the Windows Firewall allowing traffic on port 80.  Note that this rule will be deleted if you stop the deployment or reboot

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Tags:  
Categories:   .NET | Windows Azure
Actions:   E-mail | del.icio.us | Permalink | Comments (1) | Comment RSSRSS comment feed

PDX Code Camp Session: WP7 Tips & Tricks

Sunday, 23 May 2010 15:18 by jesse

Chow I presented the Windows Phone 7 Tips & Tricks session with Allen Newton yesterday at Portland Code Camp.  Good times.  In our talk we showed a sample application "PDX Chow" that demonstrates a number of phone development concepts:

  • MVVM architecture with Laurent Bugnion's MVVM Light
  • Panorama control
  • Inversion of Control / Dependency Injection
  • Navigation using commanding and context
  • Page orientation events
  • Accessing phone features with tasks
  • ApplicationBar wrapper class that is fully Blendable and supports attached behaviors
  • Application life-cycle events
  • Accessing WCF services

The slide deck and code for the sample app are available on the downloads page.  Enjoy!

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

System.ServiceModel.ProtocolException: An HTTP Content-Type header is required

Wednesday, 19 May 2010 16:29 by jesse

The full exception message is “An HTTP Content-Type header is required for SOAP messaging and none was found.”.

If you’re writing a WCF service that returns Entity Framework entities, you may run into this error in your client application.  To correct it, open your EDMX file in the service project and change the Lazy Loading Enabled property to False.

It makes sense that related entities can’t be lazy-loaded after the query results have been returned to the client, but the error message doesn’t make that super-obvious.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Tags:   ,
Categories:   .NET | WCF | EF
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Silverlight 3 Navigation: My HyperlinkButtons don’t work!

Sunday, 17 January 2010 15:30 by jesse

The navigation framework of Silverlight 3 is great.  The URI mapping and browser history support add a lot of value.

When upgrading a Silverlight 2 site to use Silverlight 3 with navigation, I was surprised to see that all of my HyperlinkButtons that referenced external URLs were failing!

For example, a button with this XAML:

<HyperlinkButton Content="Microsoft" NavigateUri="http://www.microsoft.com"/>

when clicked yields this:

image

It turns out that once your HyperlinkButton is inside of a navigation frame (which it will be once you add navigation support to your application), you need to set the TargetName property of the button.  To preserve the Silverlight 2 behavior where the referenced URI loads in the same browser window, use “_self” as the TargetName:

<HyperlinkButton Content="Microsoft" NavigateUri="http://www.microsoft.com" TargetName="_self"/>

You can also use “_blank” to open up the page in a new browser window.

When using a HyperlinkButton to navigate to a Silverlight page internal to your application, TargetName should reference the name of the navigation frame:

<navigation:Frame x:Name="ContentFrame" Source="/home">
  <navigation:Frame.UriMapper>
    <uriMapper:UriMapper>
      <uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
      <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
    </uriMapper:UriMapper>
  </navigation:Frame.UriMapper>
</navigation:Frame>
 
<HyperlinkButton NavigateUri="/about" TargetName="ContentFrame" Content="About Us"/>
 

HyperlinkButtons fixed!

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Categories:   .NET | Silverlight
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

.NET 101

Monday, 26 October 2009 05:10 by jesse

If you find yourself wanting yourself to share some C# brilliance related to…images

  • The difference between Object.Equals() and ==
  • How string comparison is an interesting special case
  • Why class instance memory is not necessarily reclaimed when an instance goes out of scope
  • Which of Stream.Close() and Stream.Dispose() should be called (or both)

Please remember that it is not 2001.  Everyone knows these things (unless you’re in a .NET 101 class).  If you don’t know these things…may I suggest .NET U?

Seriously, though – how about something interesting like harnessing the power of IObservable<T>?  Bring on the new!

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Categories:   .NET
Actions:   E-mail | del.icio.us | Permalink | Comments (1) | Comment RSSRSS comment feed

Where are the recent items in my Windows 7 jump list?

Thursday, 1 October 2009 11:49 by jesse

I just started adding support for the Windows 7 taskbar jumplist to my WPF application, using the excellent .NET wrappers in the Windows API Code Pack.

After creating the jump list, file selection via the Windows common file dialogs should automatically cause entries to appear in the Recent section of the jump list.

But no.  What's going on?

It turns out that everything is working as expected.  However, you need to have the "recent items" checkbox enabled for the taskbar:

 

 
Once clicked, the Recent items appear on the jump list. 
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Categories:   .NET | WPF
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Scrolling TextBox in WPF

Thursday, 1 October 2009 03:03 by jesse

If you put a TextBox inside a ScrollViewer, the TextBox will take as much width as it needs, even if you set TextWrapping to Wrap.  That means that a long line of text will just stretch out to the right, beyond the right edge of the ScrollViewer, instead of wrapping.

Fortunately, you can bind the Width of the TextBox to the ScrollViewer ViewportWidth.  This makes the text wrap at the right edge of the ScrollViewer.  If you hide the horizontal scrollbar, you get just what you'd expect - vertical scrolling and horizontal wrapping.  This also allows the ScrollViewer to participate in a flow style layout and still have the text wrap correctly.

<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">

<TextBox IsReadOnly="True" FontSize="14" TextWrapping="Wrap" Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollViewer}}, Path=ViewportWidth}"/>

</ScrollViewer>

 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Categories:   .NET | Silverlight | WPF
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

code2plan Beta Release

Wednesday, 7 January 2009 16:48 by jesse

As a few of you might have seen, my side project code2plan is finally in beta.

code2plan is a free agile software project management application that is available as a Visual Studio 2008 add-in, and also as a standalone Windows desktop application.  Both versions have the same feature set, and both are WPF applications.  The program supports single users as well as supporting a shared database for teams.  You can work offline (no network connection required), and when you do sync up, a very straightforward conflict resolution feature helps you manage changes that you and other team members have made to the same data.

If you're an agile .NET developer, I would really appreciate your feedback on the program - both good and bad.  We'll be releasing new versions of the application very frequently, so there's a good chance that if code2plan doesn't work for you right now, it may very soon.  Just let me know.  Please post your comments to the forums on the code2plan web site so that everyone can benefit from the discussion.

I'll be posting here regularly over the coming weeks about the code2plan architecture, design thinking, and future plans.

Happy New Year!

Jesse

kick it on DotNetKicks.com

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Tags:  
Categories:   .NET | code2plan
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Using SQL Server 2008 Express as a default instance

Saturday, 13 September 2008 17:46 by jesse

Time to upgrade!  After uninstalling SQL Server 2005, I decided that I would try running only the Express version of SQL Server 2008 on my laptop.  After installing, I found that running SQLCMD against the (local) server no longer worked.  For example,

sqlcmd -s (local) -i SomeScript.sql

Resulted in this error:

HResult 0x2, Level 16, State 1
Named Pipes Provider: Could not open a connection to SQL Server [2].
Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : Login timeout expired.

I had installed SQL Server 2008 Express as the default instance (and I don't have any other version of SQL Server on this machine), and accepted the default instance name SQLEXPRESS.

SQLCMD is connecting to the instance through named pipes, and the pipe name it connects on for the default instance is \\.\pipe\sql\query

To connect to a named instance, it connects through the named pipe \\.\pipe\MSSQL$<instancename>\sql\query

Sure enough, after opening Sql Server Configuration Manager, I expanded the Sql Server Network Configuration, double-clicked on Named Pipes, and was able to see that the pipe name included the instance name SQLEXPRESS.  After changing the pipe name to \\.\pipe\sql\query, my sqlcmd reference to (local) worked great.  Whew.

Named Pipes Properties

kick it on DotNetKicks.com

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Tags:  
Categories:   .NET
Actions:   E-mail | del.icio.us | Permalink | Comments (2) | Comment RSSRSS comment feed