WP7: Common Language Runtime detected an invalid program. Microsoft.Xna.Framework.TitleContainer.OpenStream


The XAML designer seems to choke whenever you reference a stream (or load a stream) in the constructor of a user control or in the Loaded event. I assume this is because wherever the designer is loading these events but the relative path used to access the file isn’t working in design mode (even though it works when it’s deployed or in the emulator because the .wav file exists).

Simple fix so the designer doesn’t crash… put a try/catch around the code that opens the stream. The designer will work properly then. I could probably change the way the resource is stored, but I don’t really want to at this point. :p

Try
    FrameworkDispatcher.Update()
    Dim stream = TitleContainer.OpenStream("Resources/Pop1.wav")
    _sf = SoundEffect.FromStream(stream)
Catch ex As Exception
    ' eat this error, it's in place to fix the designer from crashing.  This works fine in production/the emulator
End Try

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.