Hello!
I’m building a tank shooter game and I’m currently trying to add sounds, however, it won’t load the sound file.
I get this error:
Microsoft.Xna.Framework.Content.ContentLoadException was unhandled
HResult=-2146233088
Message=Could not load Sounds/TankFire asset as a non-content file!
Source=MonoGame.Framework
StackTrace:
vid Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject)
vid Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName)
vid TankGame.AudioManager.AddSound(String folder, String name, Single volume) i C:\Users\Timmy\Dropbox\Visual Studio Projects\Skolan\TankGame\TankGame\AudioManager.cs:rad 23
vid TankGame.Tank.Update(List`1 tanks) i C:\Users\Timmy\Dropbox\Visual Studio Projects\Skolan\TankGame\TankGame\Tank.cs:rad 72
vid TankGame.Screens.GameScreen.Update(Game1 game) i C:\Users\Timmy\Dropbox\Visual Studio Projects\Skolan\TankGame\TankGame\Screens\GameScreen.cs:rad 46
vid TankGame.Game1.<Update>b__11_0(BaseScreen s) i C:\Users\Timmy\Dropbox\Visual Studio Projects\Skolan\TankGame\TankGame\Game1.cs:rad 85
vid System.Collections.Generic.List`1.ForEach(Action`1 action)
vid TankGame.Game1.Update(GameTime gameTime) i C:\Users\Timmy\Dropbox\Visual Studio Projects\Skolan\TankGame\TankGame\Game1.cs:rad 82
vid Microsoft.Xna.Framework.Game.DoUpdate(GameTime gameTime)
vid Microsoft.Xna.Framework.Game.Tick()
vid MonoGame.Framework.WinFormsGameWindow.RunLoop()
vid MonoGame.Framework.WinFormsGamePlatform.RunLoop()
vid Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
vid Microsoft.Xna.Framework.Game.Run()
vid TankGame.Program.Main() i C:\Users\Timmy\Dropbox\Visual Studio Projects\Skolan\TankGame\TankGame\Program.cs:rad 18
vid System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
vid System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
vid Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
vid System.Threading.ThreadHelper.ThreadStart_Context(Object state)
vid System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
vid System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
vid System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
vid System.Threading.ThreadHelper.ThreadStart()
InnerException:
HResult=-2146233088
Message=The content file was not found.
Source=MonoGame.Framework
StackTrace:
vid Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName)
vid Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject)
InnerException:
FileName=C:\Users\Timmy\Dropbox\Visual Studio Projects\Skolan\TankGame\TankGame\bin\Windows\Debug\Content\Sounds\TankFire.xnb
HResult=-2147024894
Message=Det gick inte att hitta filen C:\Users\Timmy\Dropbox\Visual Studio Projects\Skolan\TankGame\TankGame\bin\Windows\Debug\Content\Sounds\TankFire.xnb.
Source=mscorlib
StackTrace:
vid System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
vid System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
vid System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
vid Microsoft.Xna.Framework.TitleContainer.OpenStream(String name)
vid Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName)
InnerException:
I use this code:
public void AddSound(string folder, string name, float volume)
{
SoundEffect sound = Content.Load<SoundEffect>(folder + "/" + name);
Audio audio = new Audio(sound);
audioList.Add(audio);
}
and I do have the soundfile in Content\Sounds\name.xnb
I’ve tried .wma, .wav and .xnb files as well as changing the code to try with and without the extension. Also, the file is set to copy if newer but I’ve tried never copy as well.
Also, if you see something you don’t understand in the error it’s Swedish.
Do anyone know what I should do?
Thanks in advance!