The type 'FileMode' exists in both MonoGame.Framework and mscorlib

I’m working on moving my XNA game to MonoGame. I have finally reached an issue with System.IO.FileMode and System.IO.FileAccess. Both of these are in both mscorlib and monogame.framework. I have tried the following and none of them work. I’m using VS 2015 if that matters.

global::System.IO.FileMode.Open -> still gives the same error

using io = gloabal::System.IO; io.FileMode.Open -> still gives teh same error.

Any one know a work around for this issue with monogame?

if talking about UWP, this may be related to https://github.com/mono/MonoGame/pull/4039 and if so, it was fixed some days ago (using a development build or compile from source should fix the problem)

Compiling from services and downloading the development build still gives me this issue… Any other ideas?

Hi!

Is there any solution or way around?
I’ve got the same problem while porting my app from xna to monogame.uwp

I also have the same problem. I need to use IsolatedStorageFile.OpenFile FileMode and get the error:

The type ‘FileMode’ exists in both ‘MonoGame.Framework, Version=3.4.0.459, Culture=neutral, PublicKeyToken=null’ and ‘System.IO.FileSystem.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

Anyone found a solution?

There are a few workarounds in .NEt to get past name collisions… You can use the full type name, System.IO.FileMode.Append

or you can use an alias at the top of the file
using catpants = System.IO.FileMode;

http://www.dotnetperls.com/using-alias

Hope this helps. Cheers!

Here’s my solution:

Create a new project and include it in the project that requires FileMode. Add the following class

using System;
using System.IO;
    
namespace EX
        {
        
            public sealed class Helper
            {
        
           public enum FileModeType
                {
                    CreateNew,
                    Create,
                    Open,
                    OpenOrCreate,
                    Truncate,
                    Append
                }
                   
                public static FileMode FileMode(FileModeType type)
                {
                    switch (type)
                    {
                        case FileModeType.CreateNew:
                            return System.IO.FileMode.CreateNew;
                        case FileModeType.Create:
                            return System.IO.FileMode.Create;
                        case FileModeType.Open:
                            return System.IO.FileMode.Open;
                        case FileModeType.OpenOrCreate:
                            return System.IO.FileMode.OpenOrCreate;
                        case FileModeType.Truncate:
                            return System.IO.FileMode.Truncate;
                        case FileModeType.Append:
                            return System.IO.FileMode.Append;
                                
                    }
        
                    throw new Exception("No such FileMode");
                }
            }
        }

Now to use for example IO.FileMode.Open you use EX.Helper.FileMode(EX.Helper.FileModeType.Open)

Thanks all!

@binaryfish
Some time ago I tried to use alias and found some dificulties and don’t remember now what is.

@dmanning23
Using another project works!

But i’ve found a third way - using stream async methods directly cause my project is for UWP

I was having the same issue and it was because I was referencing the MonoGame in the ‘Windows8’ folder. I had to manually browse and select the one in the ‘Windows’ folder. This fixed the issue for me.