1

I've got a vs2010 solution containing an ASP.Net 4 website, and a Silverlight 4 project.

The website is linked to the Silverlight project ('Map') and the ClientBin folder contains a Map.xap file.

The Map project is very simple. It contains the default App.xaml and App.xaml.cs files. The MainPage.xaml file looks like this

<UserControl x:Class="Map.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:DesignHeight="380" d:DesignWidth="800">

<Canvas x:Name="MainCanvas" Width="800" Height="380">
    <Canvas.Background>
        <ImageBrush ImageSource="map.png" Stretch="None"/>
    </Canvas.Background>
</Canvas>

The code behind for that looks like this:

public partial class MainPage : UserControl
{

        public MainPage()
        {
            InitializeComponent();
            throw new Exception();
        }

}

Inside one of the website pages I have the default object pointing to my Silverlight xap

When I run the website, I see my background image on the Canvas in the Silverlight window, so I know it's working in that sense. However, I cannot break on any breakpoints set in the MainPage.xaml.cs file (in IE). I have checked the correct settings for Silverlight debugging.

And see that Exception I'm throwing in the MainPage constructor? I'm not seeing that either. In fact, nothing I put in there seems to be run at all, but I know the xaml is rendering because I can see my canvas background. What am I not getting here?

Erix
  • 7,059
  • 2
  • 35
  • 61

4 Answers4

2

I have run in to this issue and the way we solved it was to manually attach the process to the debugger.

VoodooChild
  • 9,776
  • 8
  • 66
  • 99
2

For what it's worth, you've got it right, something's just not wired up correctly. If you didn't already, just create a new Silverlight App from VS2010 and start over to make sure everything is wired correctly. You can absolutely attach to process, but you shouldn't "have to".

VS2010 puts a Grid, not a canvas, as the default base. This doesn't matter, you can use either, however since I'm seeing a canvas there, it is making me question how you created the project to begin with. If you following a book, etc., then some part of the process may have been missed.

Make sure that under the Web project properties, you look in the Silverlight Applications tab, and make sure that grid lists the Silverlight project as "Map", Path in Web should be "ClientBin", and Configuration Specific Folders is "No".

I don't think you need anything special in the Silverlight project, but DO make sure it is set to build in DEBUG mode, not RELEASE. (I've made this dumb mistake before). Also set it for Any CPU.

Finally, I know you said you are using IE, but just be sure it's not FF, etc. FF can be setup to Debug SL apps, but it takes a tweak first.

Todd Davis
  • 5,855
  • 10
  • 53
  • 89
1

Have you enabled Silverlight debugging in the ASP.NET website project properties under Web -> Debuggers?

Andrew Garrison
  • 6,977
  • 11
  • 50
  • 77
1

Have you tried clearing your browser's cache? I know that when I use FireFox, it caches the XAP and the Visual Studio debugger can't find the right symbols.

If this is the problem, then here is a neat trick to get around the issue, stolen from another Stackoverflow post. Just put this in your ASPX page hosting the silverlight app.

<param name="source" value="ClientBin/App.xap?<%= DateTime.Now.Ticks %>" />
Community
  • 1
  • 1
Andrew Garrison
  • 6,977
  • 11
  • 50
  • 77