Farseer, Windows 8 and MonoGame

Topics: Developer Forum, User Forum
Aug 23, 2012 at 11:31 AM
Edited Aug 23, 2012 at 2:38 PM

Hi all,

I trying to migrate in Win8 a my developed game for Windows Phone with Farseer, XNA and I use MonoGame for XNA porting.

My issues are some errors during Farseer libs compiling about FileStream for System.IO missing (this is the message error from compiler).

Someone can help me?

Thanks in advance.

-Kafar

 

UPDATE:********************************

Maybe is good if I explain more details about what I do.

I created a Windows Store Application project type and I put into all code logic of my game and the assets content, after I created a reference to MonoGame.

My game use Farseer then I created a class library project type and I put into all source code of Farseer Physics and I created a reference to MonoGame.

When I build all I obtain 16 errors of this types:

- "Unable to find namespace 'FileStream' in Serialization.cs    18    20    FarseerPhysics"

- same error type with "Assert" in YuPengClipper.cs

- same error type with "Console" in DTSweep.cs

 

I hope someone can help me...

Thanks

 

-Kafar

Aug 25, 2012 at 5:21 PM

Hi all,

 

Please, anyone who can help me...

Many thanks.

-Kafar

Aug 26, 2012 at 1:39 PM

am soon to move to win 8 myself, so will watch this closely. can't help now sorry :(

Coordinator
Aug 28, 2012 at 12:22 AM

The types that are not found are pretty much the .NET standard types. FileStream is inside System.IO. Assert and Console are inside System. It seems you don't have the .NET library referenced correctly inside the Farseer Physics project. Check the references of the project for any issues.

Aug 28, 2012 at 12:20 PM
Genbox wrote:

The types that are not found are pretty much the .NET standard types. FileStream is inside System.IO. Assert and Console are inside System. It seems you don't have the .NET library referenced correctly inside the Farseer Physics project. Check the references of the project for any issues.

Hi Genbox,

Maybe I was wrong something but in Farseer Physics project in VS2012 (Windows 8) I see ".NET for Windows Store apps - type: NetCore 4.5", Windows - 8.0" and MonoGame lib references only.

System.IO.FileStream I found in mscorlib but if I try to add the reference VS2012 is unable to add that lib because it's already included. So, I don't understand which is the problem...

-Kafar

Oct 4, 2012 at 6:01 PM

Hi Kafar-

I responded to your post in the XAML Physics helper project as well, but figured it might help for Farseer users to see the updated Win8 code too.  FileStream is not available in Windows 8 for Metro apps, so you need to use StorageFile instead.  This code replaces the first class currently in Common\Serialization.cs The nice part about this update is that it makes the Serialization async.

    using Windows.Storage;
    using System.Threading.Tasks;

    public static class WorldSerializer
    {
        public static async void Serialize(World world, string filename)
        {
            StorageFolder folder = ApplicationData.Current.LocalFolder;
            StorageFile file = await folder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
            using (Stream s = await file.OpenStreamForWriteAsync())
            {
                new WorldXmlSerializer().Serialize(world, s);
            }
        }

        public static async void Deserialize(World world, string filename)
        {
            StorageFolder folder = ApplicationData.Current.LocalFolder;
            StorageFile file = await folder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);
            using (Stream s = await file.OpenStreamForReadAsync())
            {
                new WorldXmlDeserializer().Deserialize(world, s);
            }
        }

        public static async Task<World> Deserialize(string filename)
        {
            StorageFolder folder = ApplicationData.Current.LocalFolder;
            StorageFile file = await folder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);
            using (Stream s = await file.OpenStreamForReadAsync())
            {
                return new WorldXmlDeserializer().Deserialize(s);
            }
        }
    }

Oct 4, 2012 at 6:38 PM

Hi Treckle,

Thank you very much for your clarification, I'll try to implement your code.

Thanks again.

Bye

 

-Kafar