2

Edit: I solved my problem.

I seem to have the same problem as this one and this one. Except that I can use XNA3.0 or 3.1, but neither of them have Microsoft.Xna.Framework.Xact.dll Instead there are Microsoft.Xna.Framework and Microsoft.Xna.Framework.Game .

I am programming on a Microsoft surface table, and I copied code from an example that uses XNA 2.0. I can run the example code fine, but I can't find the reference that it is using.

I have a reference to both Microsoft.Xna.Framework and Microsoft.Xna.Framework.Game, and in the code I have

using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework;

My code breaks when it tries to create a new AudioEngine: (because if I comment it out the program runs)

string filename = System.Windows.Forms.Application.ExecutablePath;
string path = System.IO.Path.GetDirectoryName(filename) + "\\Audio\\";

try
{
audioEngine = new AudioEngine(path + "PianoSounds.xgs");
waveBank = new WaveBank(audioEngine, path + "PianoSounds.xwb");
soundBank = new SoundBank(audioEngine, path + "PianoSounds.xsb");
}

The error I get isn't very helpfull:

Cannot create instance of 'SurfaceWindow1' defined in assembly 'CoffeeTable1, Version=1.0.4652.32991, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation.  Error in markup file 'CoffeeTable1;component/SurfaceWindow1.xaml' Line 1 Position 18.

This is the xaml file SurfaceWindow1.xaml that tries to initialise:

<s:SurfaceWindow x:Class="CoffeeTable1.SurfaceWindow1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:s="http://schemas.microsoft.com/surface/2008"
    Title="CoffeeTable1"
    >
  <s:SurfaceWindow.Resources>
    <ImageBrush x:Key="WindowBackground" Stretch="None" Opacity="0.6" ImageSource="pack://application:,,,/Resources/WindowBackground.jpg"/>
  </s:SurfaceWindow.Resources>

  <Grid Background="{StaticResource WindowBackground}" >
        <s:SurfaceButton Content="A" ContactEnter="StartSound" Margin="50,50,0,0" Height="100" Width="100" HorizontalAlignment="Left" VerticalAlignment="Top" Name="A6" ClickMode="Hover" />
    </Grid>
</s:SurfaceWindow>
Community
  • 1
  • 1
Niels
  • 1,340
  • 2
  • 15
  • 32
  • Do you have a reference to in microsoft.xna.framework.dll in your project? – Jesse Carter Sep 26 '12 at 17:21
  • If you have a proper reference to that .dll try adding a using statement for Microsoft.Xna.Framework.Audio in your code. I think that things got moved over to Xact in XNA 4.0. Also if we could see the code where you are trying to instantiate your AudioEngine it might help – Jesse Carter Sep 26 '12 at 17:24
  • 1
    We need the relevant error/output information then. It doesn't look like the problem has anything to do with a missing reference if you are able to build this and its not complaining about the way you declared a new AudioEngine. If there was a problem with the using/reference it wouldn't even let you compile. For all we know its failing cause your path is wrong and it can't find the .xgs – Jesse Carter Sep 26 '12 at 17:32
  • I edited the question to give some more info. Yes I have the using statement. And the code is directly copied from the example. I also copied the files and added them to the project. If I comment out the line that creates the audioengine, the program runs. – Niels Sep 26 '12 at 17:33
  • Do you have a corresponding catch block to handle Exceptions? Put a break point there and see if you can get the InnerException message or any information about whats breaking when you try to create your AudioEngine. Also, looks like you have an error coming from xaml. Can you post that too? – Jesse Carter Sep 26 '12 at 17:36
  • Did you by any chance change the name of a xaml file? – Jesse Carter Sep 26 '12 at 17:38
  • As far as I can see the name is still correct (and no I did not change it). The debugger never reaches the catch blocks, so I can't get any more detailed errors. – Niels Sep 26 '12 at 17:44
  • 1
    The problem is not directly related to your C# code there is something going on with your xaml. The fact that you can't reach the catch blook and the error being thrown are proof of that – Jesse Carter Sep 26 '12 at 17:46
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/17201/discussion-between-niels-and-jesse-carter) – Niels Sep 26 '12 at 17:49
  • I solved the error by writing the full path of the files. I don't get why it didn't go to the catch block though. Thanks for your help and patience! – Niels Sep 26 '12 at 17:59
  • 1
    No problem man glad you got it figured out! – Jesse Carter Sep 26 '12 at 18:53

0 Answers0