3

everyone.

I am using Visual Studio to develop uwp application. The compiler says that type FileMode exists in both MySql.Data.RT and System.IO.FileSystem.Primitives. The error message is below.

Error CS0433 Type 'FileMode' exists in both 'MySql.Data.RT, Version=6.7.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' and 'System.IO.FileSystem.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.    

However, I have used the complete name of the type as following.

FileStream fileStream = new FileStream(fileName, System.IO.FileMode.Open);

I don't know why there is still an error, any advice is welcome.

EDIT:

I don't think this question is duplicate because I could not find any way to modify the answer to the provided candidate duplicate question to solve the issue I encountered.

EDIT:

I eventually solved this issue myself. I found out that the namespace System.IO exists in two dll files, MySql.Data.RT and System.IO.FileStream.Primitives. That's why even I specified the full name of the object (System.IO.FileMode), the compiler still doesn't know which dll file it should references the object to. My solution is to add an alias to MySql.Data.RT as MySQL, and modify the code as following.

using MySql.Data.MySqlClient;

=>

extern alias MySQL;
using MySQL::MySql.Data.MySqlClient;

Note:

One can add an alias to a reference via right click on it in the solution explorer and then click the property option, then the UI will appear.

David Chen
  • 1,777
  • 2
  • 12
  • 23
  • 1
    What are the namespaces of both classes? – Patrick Hofman Feb 15 '17 at 14:09
  • Have you done a clean? – Joshua Drake Feb 15 '17 at 14:14
  • From a first glance it looks like you have 2 namespaces with the class FileMode. This may cause a confusion when accessing FileMode. It doesn't happen in the code you wrote because you use the class' full name: System.IO.FileMode. Try using the full name each time you're using FileMode – Ori Nachum Feb 15 '17 at 14:14
  • @OriNachum I've used the full name when I am using `FileMode` everywhere in my project. – David Chen Feb 15 '17 at 16:09
  • 1
    @DavidChen, did you try manually deleting the OBJ and BIN folders? (Not the right-click clean from VS) – Ori Nachum Feb 15 '17 at 16:23
  • @JoshuaDrake I cleaned and rebuild it, but it didn't work out. – David Chen Feb 15 '17 at 16:23
  • @OriNachum, No I haven't. How can I achieve that? – David Chen Feb 15 '17 at 16:24
  • Go the the Project's folder (Right click on the project, and then click Open Folder in File Explorer). You should see obj and bin folders. You can delete them both - VS generates them when you build your code. Edit: After deleting your code, try to build again – Ori Nachum Feb 15 '17 at 16:43
  • I disagree with the Duplicate Flag because the other question was bout the interaction of dlls, and within the scope of a web app, while this question is about compilation within the confines of a single solution. – Joshua Drake Feb 15 '17 at 16:44
  • @OriNachum Thanks for your advice, but it didn't work out. Also, it occurred to me that it was the first time I wanted to build the project when the error appeared. – David Chen Feb 15 '17 at 17:38
  • @DavidChen, Where did you get the MySQL.DATA.RT from? I couldn't locate it in MySQL.DATA namespace. I'm trying to reproduce the issue in my end. – Ori Nachum Feb 16 '17 at 10:24
  • @OriNachum I added the reference to my project. Below is the path. `C:\Program Files (x86)\MySQL\MySQL Connector Net 6.7.9\Assemblies\RT\MySql.Data.RT.dll` – David Chen Feb 16 '17 at 15:44
  • @DavidChen, What project did you start? When I try to recreate on Windows 7, Visual Studio 2015, .NET Frameowkr 4.5.2 I get the error: The Project targets `.NET Framework` while the file references `.NETCore` – Ori Nachum Feb 16 '17 at 15:53
  • @OriNachum universal windows application – David Chen Feb 16 '17 at 17:40
  • It is acceptable to accept your own answers. Your edit should be an answer. – Joshua Drake Feb 17 '17 at 19:55
  • 1
    @JoshuaDrake Because it is marked as duplicate now, it can't be answered now. I've flagged it for moderator intervention. Thanks for your advice. – David Chen Feb 18 '17 at 03:17
  • @EshanSajjad This doesn't seem a duplicate issue as marked - the other issue refers to a server with specific files reference errors, while this is about namespaces. OP wasn't able to adapt the solution to this issue. – Ori Nachum Mar 01 '17 at 14:25

0 Answers0