title: Silverlight webcam API throwing strange error
body: <p>I am trying to show my webcam using VideoBrush on rectangle. However, i am facing this weird issue :-</p>
  
  <pre><code>External component has thrown an exception.
  
     at MS.Internal.XcpImports.CaptureGraph_GetAvailableVideoCaptureDevicesNative(IntPtr pContext, Int32&amp; typeIndex, CValue&amp; DeviceCollection)
     at MS.Internal.XcpImports.CaptureGraph_GetAvailableVideoCaptureDevices()
     at System.Windows.Media.CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice()
     at System.Windows.Media.CaptureSource..ctor()
     at FMT.Client.Views.ChildWindows.Webcam.Webcam_Loaded(Object sender, RoutedEventArgs e)
  </code></pre>
  
  <p>I then right clicked on Silverlight application, went into configuration and then into Mic/Webcam tab. I have my webcam selected there and i can see my webcam fine when i am in that dialog. Here is my code :-</p>
  
  <pre><code>using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Media;
  using System;
  
  namespace FMT.Client.Views.ChildWindows
  {
      public partial class Webcam : ChildWindow
      {
          private CaptureSource _source;
          private CaptureDevice _webcam;
          private VideoBrush _webcamBrush;
          private ImageBrush _capturedImage;
  
          public Webcam()
          {
              InitializeComponent();
              this.Loaded += Webcam_Loaded;
          }
  
          void Webcam_Loaded(object sender, RoutedEventArgs e)
          {
              try
              {
                  //if (CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices().Count &lt;= 0)
                  //{
                  //    ErrorWindow window = new ErrorWindow("Error","Please check the default webcam in the Silverlight config. You can specify the video and audio devices that are used by default with the Silverlight Configuration. Just press the right mouse button over the application, click Silverlight in the context menu and select the  Webcam / Mic tab to set them.");
                  //    window.Show();
                  //    this.DialogResult = false;
                  //}
                  //else
                  //{
                      _source = new CaptureSource();
                      _source.CaptureImageCompleted += _source_CaptureImageCompleted;
                      _source.CaptureFailed += _source_CaptureFailed;
                      _webcam = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
                      if (_webcam != null)
                      {
                          _source.VideoCaptureDevice = (VideoCaptureDevice)_webcam;
                          _webcamBrush = new VideoBrush();
                          _webcamBrush.SetSource(_source);
                          capturedRect.Fill = _webcamBrush;
                          _capturedImage = new ImageBrush();
                          RequestAccess();
                      }
                  //}
              }
              catch (Exception ex)
              {
                  ErrorWindow window = new ErrorWindow(ex);
                  window.Show();
                  this.DialogResult = false;
              }
          }
  
          void RequestAccess()
          {
              if (CaptureDeviceConfiguration.RequestDeviceAccess() &amp;&amp; _source.VideoCaptureDevice != null)
              {
                  _source.Start();
              }
              else
                  this.DialogResult = false;
          }
  
          void _source_CaptureFailed(object sender, ExceptionRoutedEventArgs e)
          {
              ErrorWindow window = new ErrorWindow(e.ErrorException);
              window.Show();
          }
  
          void _source_CaptureImageCompleted(object sender, CaptureImageCompletedEventArgs e)
          {
              if(e.Result != null)
                  _capturedImage.ImageSource = e.Result;
          }
  
          private void hypCapture_Click(object sender, RoutedEventArgs e)
          {
              if (_source.VideoCaptureDevice != null &amp;&amp;
                 _source.State == CaptureState.Started)
              {
                  _source.CaptureImageAsync();
              }
          }
  
      }
  }
  </code></pre>
  
  <p>Any idea, why does the execution fails while calling the constructor of CaptureSource?</p>
  
  <p>Thanks in advance :)</p>