Loading in images issue

Hi everyone, very new to monogame and coding in general so be easy on me :yum:

So i’m using the pipeline, and it looks like this:

Yet, in VS, the solution explorer looks like this:

When I try and run the game I recieve this error:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not find file ‘C:\Users\samma\OneDrive\Documents\Code\C#\SpaceGame\SpaceGame\bin\Windows\x86\Debug\spaceShip’.
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 Microsoft.Xna.Framework.TitleContainer.PlatformOpenStream(String safeName)
at Microsoft.Xna.Framework.TitleContainer.OpenStream(String name)
at SpaceGame.GameSprite…ctor(GraphicsDevice graphicsDevice, String textureName, Single scale) in C:\Users\samma\OneDrive\Documents\Code\C#\SpaceGame\SpaceGame\Sprites.cs:line 65
at SpaceGame.MovingSprite…ctor(GraphicsDevice graphicsDevice, String textureName, Single scale) in C:\Users\samma\OneDrive\Documents\Code\C#\SpaceGame\SpaceGame\Sprites.cs:line 79
at SpaceGame.Game1.LoadContent() in C:\Users\samma\OneDrive\Documents\Code\C#\SpaceGame\SpaceGame\Game1.cs:line 57
at Microsoft.Xna.Framework.Game.Initialize()
at SpaceGame.Game1.Initialize() in C:\Users\samma\OneDrive\Documents\Code\C#\SpaceGame\SpaceGame\Game1.cs:line 46
at Microsoft.Xna.Framework.Game.DoInitialize()
at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
at Microsoft.Xna.Framework.Game.Run()
at SpaceGame.Program.Main() in C:\Users\samma\OneDrive\Documents\Code\C#\SpaceGame\SpaceGame\Program.cs:line 18

Again, I’m very new to this so it’s probably a rookie error, but being a rookie myself I can’t spot it…
Would appreciate any help

Thanks

Can you show the loading code? Something like Content.Load…

“FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs,…”

C:\Users\samma*OneDrive*\Documents…

Seems like a access security problem, try to copy the project folder to a normal drive directory and open the solution from there ^_^y

System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not find file ‘C:\Users\samma\Documents\Code\C#\Space_Game\Space_Game\bin\Windows\x86\Debug\spaceShip’.
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 Microsoft.Xna.Framework.TitleContainer.PlatformOpenStream(String safeName)
at Microsoft.Xna.Framework.TitleContainer.OpenStream(String name)
at Space_Game.GameSprite…ctor(GraphicsDevice graphicsDevice, String textureName, Single scale) in C:\Users\samma\Documents\Code\C#\Space_Game\Space_Game\Sprites.cs:line 65
at Space_Game.MovingSprite…ctor(GraphicsDevice graphicsDevice, String textureName, Single scale) in C:\Users\samma\Documents\Code\C#\Space_Game\Space_Game\Sprites.cs:line 79
at Space_Game.Game1.LoadContent() in C:\Users\samma\Documents\Code\C#\Space_Game\Space_Game\Game1.cs:line 57
at Microsoft.Xna.Framework.Game.Initialize()
at Space_Game.Game1.Initialize() in C:\Users\samma\Documents\Code\C#\Space_Game\Space_Game\Game1.cs:line 46
at Microsoft.Xna.Framework.Game.DoInitialize()
at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
at Microsoft.Xna.Framework.Game.Run()
at Space_Game.Program.Main() in C:\Users\samma\Documents\Code\C#\Space_Game\Space_Game\Program.cs:line 18

For some reason, despite me not selecting the one drive folder, it default set the path to that…so I forced it to not be a onedrive folder by creating a new project and copying the code. I added the content to the pipeline. And I recieved the above error, sigh. I then manually added the png file to the folder it says and it still can’t find it.

//Constructor, set the scale and texture
public GameSprite(GraphicsDevice graphicsDevice, string textureName, float scale)
{
this.scale = scale;
if (texture == null)
{
using (var stream = TitleContainer.OpenStream(textureName))
{
texture = Texture2D.FromStream(graphicsDevice, stream);
}

        }
    }

Above is the code that i’m currently using. This website :https://docs.microsoft.com/en-us/windows/uwp/get-started/get-started-tutorial-game-mg2d suggests that it should work.

Are you intentionally not using MonoGame’s ContentManager?

Usually you would just do something like:

Content.RootDirectory = "Content"; //... some time later Content.Load<Texture2D>("my_texture_file")

But maybe you have particular needs to use filestream (which I don’t know much about).

Hi! I’m having the exact same problem… Did you manage to solve it?