Silverlight 3 Could Not download the silverlight Application

by Ken Tucker 11. October 2009 11:53

I created a simple Silverlight 3 app.

 

<UserControl x:Class="SilverlightApplication2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
        <TextBlock Text="Hello World!" ></TextBlock>
    </Grid>
</UserControl>

 

When I run it I get an error about not being able to download the silverlight app

 

Line: 56
Error: Unhandled Error in Silverlight Application
Code: 2104   
Category: InitializeError      
Message: Could not download the Silverlight application. Check web server settings   

 

Well if you look in the ClientBin folder you will see it is empty so the xap file is not available to be used

 

To fix this right click on the web application and select Build Order.  On the Dependencies tab make sure the Checkbox next to the Silverlight app is checked.

Space Coast .Net Meeting – June 16, 2009 John Papa

by Ken Tucker 11. May 2009 11:55
John Papa - Ado.Net Data Services

6/17/2009 6:30:00 PM

6/17/2009 8:00:00 PM

About

jp2

John Papa is a Microsoft C# MVP, INETA speaker, member of the WPF and Silverlight Insiders, consultant, speaker, author, and trainer for ASPSOFT who specializes in professional application development with Microsoft technologies including Silverlight, WPF, C#, .NET and SQL Server. John has written over 70 articles and authored 9 books including his latest book Data Driven Services with Silverlight 2 by O’Reilly Media. John is currently working on a follow up to his Silverlight book, with a working title of Silverlight for Business.

He can often be found speaking at industry conferences such as MIXVSLive and DevConnections, speaking at user groups around the country, and viewed on MSDN Web Casts. John also spearheaded the 1st annual Silverlight MIXer, a gathering of some of the most influential members of the Silverlight community for a great night a MIX09. You can always find John at johnpapa.net.

John Papa will be showing Astoria using Silverlight 3 beta as the client.

ADO.NET Data Services (codenamed Astoria) exposes entity models through RESTful services. It can dramatically simplify the code required to expose business objects through web services and reduce a tremendous amount of code. This session will show how to expose entity models using ADO.NET Data Services, how to consume and save data, and how to debug the communications using various tools. When the technology does not quite do what you need out of the box, it also allows for customizations to create custom service operations, intercept queries, and enforce permissions. Attendees will walk away with an understanding of the capabilities of ADO.NET Data Services, how to use them with Silverlight, and when and where it is ideal to use in an application architecture and when there are better options.

Street: 8045 N. Wickham Road
City: melbourne
Country: USA
State: Florida

Silverlight 2 GDR Available

by Ken Tucker 21. February 2009 09:28

This week Microsoft Release an GDR to silverlight 2 which included some minor fixes.

 

Here is a list of the main changes in the GDR (build 2.0.40115.0):

  • Fixes problems that were caused by Silverlight and McAfee scanning tools interactions
  • UI automation stability fixes, including:
    • graceful failures when attempting to use features that require .NET Framework 3.0 or 3.5 on machines that do not have either framework installed
    • improved Tablet support
  • Fixes an issue that arises when Mac users customize their environment by removing Arial and Verdana fonts
  • Fixes a known issue with Isolated Storage IncreaseQuotaTo method (see this post for more information)


The one fix which bothered me a lot is the graceful failures when attempting to use features that require .Net framework 3.0 or 3.5 on machines that do that nave either framework installed. Silverlight 2 has its own version of the .net framework why should it use .net 3.0 or 3.5 and of course the .net framework is not available for the mac.  Well after looking around some I found this in the comments on Tim Sneath's Blog

  " apologies - we could probably be clearer here on what this means. Essentially, this was a bug that could be triggered in certain situations where you were using the accessibility tools (e.g. magnifier) on Silverlight content on a machine without .NET Framework installed. In short, the bug was an accidental dependency that has now been removed." - Tim Sneath

  http://blogs.msdn.com/tims/archive/2009/02/18/silverlight-2-gdr1-now-available.aspx

For More info on the Update please check out Tim Heuer's Blog entry

 http://timheuer.com/blog/archive/2009/02/19/silverlight-2-gets-minor-update-gdr1.aspx

 

 

MSDN Tikihut tour at Space Coast .Net

by Ken Tucker 7. November 2008 15:38
When:
Wednesday, November 19, 2008 6:30 PM Eastern Time (US & Canada)
   Who: Joe Healy, Jeff Barnes, and Russ Fustino

 

http://www.dotnettikihut.com/


Event Overview

 

Session 1 - What’s New in SQL Server 2008 for Developers - SQL Server 2008 adds numerous new capabilities for developers – from support for Spatial Data types to a storage mechanism for SQL BLOB data using the NTFS file system, and much, much more. The new release also delivers several improvements to development-related areas, from T-SQL to SQLCLR to XML. This presentation will provide a technical dive into the latest and greatest features you’ll find in SQL Server 2008, while offering insight into how to effectively apply them to your upcoming development projects.

 

Session 2 – Build next generation applications with Silverlight 2.0 - Silverlight provides a powerful platform for building the next generation of rich interactive applications on the Internet. In this session, we’ll take a look at the programming model and tools that developers and designers can leverage to build these true next generation experiences for consumers and business, and demonstrate how to build a rich interactive application (RIA) using Silverlight and Microsoft .NET. We’ll explore how to use Microsoft Visual Studio to create applications, and  networking, how to retrieve data from a Web service, and various other aspects of building Silverlight applications.

 

Session 3 – Real World Application - How to create an end-to-end Mobile GPS tracking application using the .NET Compact Framework, WCF, LINQ, Silverlight, Deep Zoom, and Virtual Earth - Inspired by a true-story mobility case study recently published on the Microsoft.com website, this session will walk you through how to create a mobile GPS tracking application using the .NET Compact Framework, Windows Mobile SDK, and Compact SQL.   At the Web host layer,   we will create a Windows Communication Foundation service and generate a Compact framework client proxy to send the GPS tracks to a host web server - where finally, the GPS trail can then be viewed using LINQ, Silverlight, Deep Zoom, and Virtual Earth.

 

Optional Session 4 (dependent on available event time) - Power up your Office applications with VSTO - In this presentation, we’ll focus on the power and productivity of Visual Studio Tools for the Microsoft Office System (VSTO) – a .NET Smart Client technology. We’ll give you tips and tricks for designing and building smart client applications with VSTO, which allows you to create managed code applications with .NET languages including Microsoft Visual Basic .NET and Visual C#. VSTO also makes it simple to manifest the functionality of those applications in the rich user interfaces of Microsoft Office Excel, Word, PowerPoint, Visio, Outlook and others from the Office stack. VSTO addresses some of the biggest challenges that Office solution developers are facing today, including separation of data and view elements, server-side and offline scenarios, seamless integration with the Visual Studio tools, deployment and updating. Join us for this eye-opening session and learn just how easy it is to build and deploy powerful applications with VSTO.

 

Please Register if you plan to attend this event.

https://msevents.microsoft.com/CUI/Register.aspx?culture=en-US&EventID=1032392616&CountryCode=US&IsRedirect=false



kick it on DotNetKicks.com

Silverlight 2 RC0 DataGrid CommittingEdit work around

by Ken Tucker 5. October 2008 12:04

In Silverlight 2 Beta 2 DataGrid had a CommittingEdit event which was a great event to update the data in an ado.net dataservice.   Unfortunately this event was removed in the RC0 of the datagrid.  As a work around Jonathan Shen suggested using a template column and using the LostFocus event to update your dataservice data.

 

 

                 <data:DataGridTemplateColumn Header="Command">
                        <data:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding FirstName}"></TextBlock>
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellTemplate>
                        <data:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <TextBox Text="{Binding FirstName}" LostFocus="TextBox_LostFocus"></TextBox>   //you can detect other events.
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellEditingTemplate>
                    </data:DataGridTemplateColumn>

 

Well this works fine but I don't want to have to define all my columns this way.  Sometimes it is nice to just let the datagrid autogenerate the columns. So I decided to use the DataGrid's PreparingCellForEdit to add the handler for the LostFocus event.  Couple of other things you need to do.  First Remove the old event handler so the event does not fire multiple times.  Second we need a variable to keep track of the item that was edited when the lost focus event is fired we will be on another record.

 

Dim prod As Northwind.Products

Private Sub dgProducts_PreparingCellForEdit(ByVal sender As Object, ByVal e As System.Windows.Controls.DataGridPreparingCellForEditEventArgs) Handles dgProducts.PreparingCellForEdit
    RemoveHandler e.EditingElement.LostFocus, AddressOf Textbox_LostFocus
    AddHandler e.EditingElement.LostFocus, AddressOf Textbox_LostFocus
    prod = DirectCast(dgProducts.SelectedItem, Northwind.Products)
End Sub

Friend Sub Textbox_LostFocus(ByVal sender As Object, ByVal e As EventArgs)
    proxy.UpdateObject(prod)
End Sub

 

Here is the complete code

 

Imports System.Collections.ObjectModel
Imports System.Data.Services.Client
Imports System.Diagnostics

Partial Public Class Page
    Inherits UserControl

    Public Sub New()
        InitializeComponent()
    End Sub

    Dim q As DataServiceQuery(Of Northwind.Products)
    Dim proxy As Northwind.NorthwindEntities

    Private Sub Page_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Dim address = New Uri(Application.Current.Host.Source, "../WebDataService1.svc")

        proxy = New Northwind.NorthwindEntities(address)

        Dim qry = From p In proxy.Products Select p
        q = CType(qry, Global.System.Data.Services.Client.DataServiceQuery(Of Northwind.Products))

        q.BeginExecute(AddressOf ProductsLoaded, Nothing)

    End Sub

    Friend Sub ProductsLoaded(ByVal ar As System.IAsyncResult)
        Dim c = q.EndExecute(ar)
        Dim d As New ObservableCollection(Of Northwind.Products)
        For Each p In c
            d.Add(p)
        Next
        Dim GetOnRightThread As New SetTheDataSource(AddressOf SetDataSource)
        Dispatcher.BeginInvoke(GetOnRightThread, New Object() {d})
    End Sub

    Delegate Sub SetTheDataSource(ByVal d As ObservableCollection(Of Northwind.Products))

    Friend Sub SetDataSource(ByVal d As ObservableCollection(Of Northwind.Products))
        dgProducts.ItemsSource = d
    End Sub

    Dim prod As Northwind.Products

    Private Sub dgProducts_PreparingCellForEdit(ByVal sender As Object, ByVal e As System.Windows.Controls.DataGridPreparingCellForEditEventArgs) Handles dgProducts.PreparingCellForEdit
        RemoveHandler e.EditingElement.LostFocus, AddressOf Textbox_LostFocus
        AddHandler e.EditingElement.LostFocus, AddressOf Textbox_LostFocus
        prod = DirectCast(dgProducts.SelectedItem, Northwind.Products)
    End Sub

    Friend Sub Textbox_LostFocus(ByVal sender As Object, ByVal e As EventArgs)
        proxy.UpdateObject(prod)
    End Sub

    Friend Sub SaveComplete(ByVal ar As System.IAsyncResult)
        proxy.EndSaveChanges(ar)
    End Sub

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSave.Click
        proxy.BeginSaveChanges(AddressOf SaveComplete, Nothing)
    End Sub
End Class


kick it on DotNetKicks.com

Silverlight 2.0 Create a context menu

by Ken Tucker 5. October 2008 01:11

Silverlight 2 does not come with a context menu control.  You could always handle the html document's oncontextmenu event and open a popcontrol to use as a context menu.  This sample should help you get started.

 

<UserControl x:Class="SilverlightContextMenu.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Grid>
        <Rectangle x:Name="LayoutRoot" Fill ="Green" ></Rectangle >
        <Popup x:Name="menu">
            <StackPanel>
                <Button x:Name="btnRed" Content="Red"></Button>
                <Button x:Name="btnWhite" Content="White"></Button>
                <Button x:Name="btnBlue" Content="Blue"></Button>
            </StackPanel>
        </Popup>
    </Grid>
</UserControl>
Imports System.Windows.Browser

Partial Public Class Page
    Inherits UserControl

    Dim WithEvents cm As ContextMenuCatcher

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub btnBlue_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnBlue.Click
        LayoutRoot.fill = New SolidColorBrush(Colors.Blue)
        menu.IsOpen = False
    End Sub

    Private Sub btnRed_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnRed.Click
        LayoutRoot.fill = New SolidColorBrush(Colors.Red)
        menu.IsOpen = False
    End Sub

    Private Sub btnWhite_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnWhite.Click
        LayoutRoot.fill = New SolidColorBrush(Colors.White)
        menu.IsOpen = False
    End Sub

    Private Sub Page_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        cm = New ContextMenuCatcher(LayoutRoot)
        menu.IsOpen = False
    End Sub

    Private Sub cm_RightClick(ByVal sender As Object, ByVal e As RightClickEventArgs) Handles cm.RightClick
        menu.HorizontalOffset = e.AbsolutePoint.X
        menu.VerticalOffset = e.AbsolutePoint.Y
        menu.IsOpen = True
    End Sub

    Private Sub menu_MouseLeave(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles menu.MouseLeave
        menu.IsOpen = False
    End Sub

End Class

Public Class ContextMenuCatcher
    Public Event RightClick(ByVal sender As Object, ByVal e As RightClickEventArgs)
    Dim ctrl As UIElement

    Public Sub New(ByVal c As UIElement)
        ctrl = c

        HtmlPage.Document.AttachEvent("oncontextmenu", AddressOf OnContextMenu)
    End Sub

    Private Sub OnContextMenu(ByVal sender As Object, ByVal e As HtmlEventArgs)
        System.Diagnostics.Debug.WriteLine(e.OffsetX.ToString)
        System.Diagnostics.Debug.WriteLine(e.OffsetY.ToString)
        Dim pt As New Point(e.OffsetX, e.OffsetY)
        e.PreventDefault()
        e.StopPropagation()
        RaiseEvent RightClick(Me, New RightClickEventArgs(ctrl, pt))
    End Sub

End Class

Public Class RightClickEventArgs

    Dim m_Source As UIElement
    Public Property Source() As UIElement
        Get
            Return m_Source
        End Get
        Set(ByVal value As UIElement)
            m_Source = value
        End Set
    End Property

    Dim m_RelativePoint As Point
    Public Property RelativePoint() As Point
        Get
            Return m_RelativePoint
        End Get
        Set(ByVal value As Point)
            m_RelativePoint = value
        End Set
    End Property

    Dim m_AbsolutePoint As Point
    Public Property AbsolutePoint() As Point
        Get
            Return m_AbsolutePoint
        End Get
        Set(ByVal value As Point)
            m_AbsolutePoint = value
        End Set
    End Property

    Friend Sub New(ByVal source As UIElement, ByVal absolutePoint As Point)
        Me.Source = source
        Me.AbsolutePoint = absolutePoint
        Me.RelativePoint = GetPosition(source)
    End Sub

    Public Function GetPosition(ByVal relativeTo As UIElement) As Point
        Dim transform As GeneralTransform = Application.Current.RootVisual.TransformToVisual(relativeTo)
        Return transform.Transform(AbsolutePoint)
    End Function
End Class
 
You also have to make the silverlight control windowless for this to work

<asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/SilverlightContextMenu.xap" MinimumVersion="2.0.30923.0" Width="100%" Height="100%" Windowless="true" />

Publishing a VB Silverlight 2 Beta 2 app which uses a WCF service

by Ken Tucker 15. July 2008 19:54

Note this works with the released version of Silverlight 2

 

I created a Silverlight 2 beta 2 app which uses a WCF Silverlight service which worked fine localy but did call the service when I published it to my web host.  After playing around with the different settings I finally came across an entry in the Silverlight Forums by sladapter with a solution. 

 

http://silverlight.net/forums/t/19021.aspx 

 

So lets create a simple Silverlight 2 App to demo how to do this.  I created a silverlight app with a web application project.   I prefer web applications to web sites but a web site will work the same.  

 

Add a WCF Silverlight- enabled service named  service1 to the web application. 

 

This is the code I am using for the service

 

Imports System.ServiceModel
Imports System.ServiceModel.Activation

<ServiceContract(Namespace:="")> _
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
Public Class Service1

    <OperationContract()> _
    Public Function SayHello() As String
        ' Add your operation implementation here
        Return "Hello World"
    End Function
End Class

 

Lets add a TextBlock to the Page.xaml to display our message.

 

<UserControl x:Class="SilverlightApplication2.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
            <TextBlock x:Name="txt">Loading..</TextBlock>
    </Grid>
</UserControl>

 

Now run the app.  Once that is done we can add a service reference to our silverlight app.  Press the arrow on the Discover button and select services in the solution.  You should windup with something like this.

 

image

 

In the silverlight app open up the file ServiceReferences.ClientConfig

 

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_Service1" maxBufferSize="65536"
                    maxReceivedMessageSize="65536">
                    <security mode="None" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:1205/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_Service1" contract="ServiceReference1.Service1"
                name="BasicHttpBinding_Service1" />
        </client>
    </system.serviceModel>
</configuration>

 

In the endpoint address change the contract to include the project name.

 

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_Service1" maxBufferSize="65536"
                    maxReceivedMessageSize="65536">
                    <security mode="None" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:1205/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_Service1" contract="SilverlightApplication2.ServiceReference1.Service1"
                name="BasicHttpBinding_Service1" />
        </client>
    </system.serviceModel>
</configuration>

 

Now lets add some code to call the service. Page.Xaml.VB

 

Partial Public Class Page
    Inherits UserControl
    Dim current As String

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub Page_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Dim ws As New ServiceReference1.Service1Client
        AddHandler ws.SayHelloCompleted, AddressOf HelloComplete
        ws.SayHelloAsync()
    End Sub

    Private Sub HelloComplete(ByVal sender As Object, ByVal e As ServiceReference1.SayHelloCompletedEventArgs)
        txt.Text = e.Result
    End Sub

End Class

 

Now if we run the app you should see Hello World but when published you will only see loading.   So lets change how we create the service so that this will work once deployed.  Basically we tell the service to use the current web address.

 

Private Sub Page_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
    Dim address = New Uri(Application.Current.Host.Source, "../Service1.svc")

    Dim ws As New ServiceReference1.Service1Client("BasicHttpBinding_Service1", address.AbsoluteUri)
    AddHandler ws.SayHelloCompleted, AddressOf HelloComplete
    ws.SayHelloAsync()
End Sub

 

Hope this helps

Silverlight XAML 404 errors

by Ken Tucker 28. August 2007 13:12

Silverlight XAML 404 errors


I created a simple web application which uses silverlight. Once I was happy with the way it was working I deployed to my webhost. When the web page loaded the silverlight control is not displaying anything.

 

Fidder 2 lets you examine what is going on when a webpage is loading. I see that there is a 404 error when loading the xaml file being displayed in the silverlight control. When I log into my webhost's control panel I see the xaml file is there.

 

According to Tim Heuser's blog all you have to do is Mime type for xaml. I added the mime type for xaml and silverlight control started to work.

 

Mime File .xaml

Type: application/xaml+xml


Hope this helps


kick it on DotNetKicks.com