Content.Load<Effect> Is returning exceptions, help?

I am trying to load an effect file called effects.fx, but it keeps returning this error:

'Microsoft.Xna.Framework.Content.ContentLoadException was unhandled
HResult=-2146233088
Message=The content file was not found.
Source=MonoGame.Framework
StackTrace:
at Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName)
at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject)
at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName)
at Flight_Sim.Game1.LoadContent() in G:\C#\Flight Sim\Flight Sim\Game1.cs:line 50
at Microsoft.Xna.Framework.Game.Initialize()
at Flight_Sim.Game1.Initialize() in G:\C#\Flight Sim\Flight Sim\Game1.cs:line 37
at Microsoft.Xna.Framework.Game.DoInitialize()
at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
at Microsoft.Xna.Framework.Game.Run()
at Flight_Sim.Program.Main() in G:\C#\Flight Sim\Flight Sim\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.IO.FileNotFoundException
HResult=-2147024894
Message=Content\effects.xnb
Source=MonoGame.Framework
StackTrace:
at Microsoft.Xna.Framework.TitleContainer.OpenStream(String name)
at Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName)
InnerException: System.IO.DirectoryNotFoundException
HResult=-2147024893
Message=Could not find a part of the path ‘G:\C#\Flight Sim\Flight Sim\bin\Windows\x86\Debug\Content\effects.xnb’.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at 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)
at System.IO.FileStream…ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.OpenRead(String path)
at Microsoft.Xna.Framework.TitleContainer.PlatformOpenStream(String safeName)
at Microsoft.Xna.Framework.TitleContainer.OpenStream(String name)
InnerException: ’

Any suggestions on how to fix it?

Could not find a part of the path ‘G:\C#\Flight Sim\Flight Sim\bin\Windows\x86\Debug\Content\effects.xnb’.

Double check that your file is at the right location. Maybe you forgot to copy it over after building your content? If you did not start from a MonoGame template that will not happen automatically.

How would I do that? There is no folder named content in the …\Debug\ folder. I’m kinda new at monogame, so I don’t know.

You should make that folder and put the effects.xnb file in there. MG expects the file to be there. When you load content the path is relative to your working directory (which is the folder that contains the game executable, so ‘G:\C#\Flight Sim\Flight Sim\bin\Windows\x86\Debug’ in your case).
EDIT: It looks in the Content folder because that is set as the root folder of the ContentManager in your Game1 constructor (at least by default) by the line Content.RootDirectory = "Content";.

And where do I get the effects.xnb file?

That would be the result of building your effects.fx file using the Pipeline Tool. The docs have some more information: http://www.monogame.net/documentation/?page=Using_The_Pipeline_Tool

thanks, this worked!

1 Like