Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by OswaldP · Feb 19, 2016 at 01:54 PM · pathnamespaceiomissing-reference

System.IO missing methods (Path.GetExtension() and more)

Hi,

I want to use the following method in a script : http://docs.unity3d.com/ScriptReference/Path.GetExtension.html

In Mono I imported the related namespaces but I get the following error when I try to use Path.GetExtension() :

 error CS0117 : 'Path' does not contain a definition for 'GetExtension'


How can I solve this ? I'm not very familiar with this kind of problems and I didn't find any satisfying solution online for the moment...

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by OswaldP · Feb 19, 2016 at 02:21 PM

Ok after several hours of searching I figured out that I was able to use the method by typing the whole path of the method (inside the runtime directory) :

 using System.IO;
     
 void Start()
 {
     //Absolute path to the method (working, no need to import the System.IO namespace) :
     System.IO.Path.GetExtension("file.jpg");
     //Relative path to the method (error, even if the namespace has been imported) :
     Path.GetExtension("file.jpg");
 }

I should add that I still don't know why the "relative" path method call is not working, and I'd be glad to know !

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ThomasVandenberghe · Feb 19, 2016 at 03:57 PM 1
Share

Do you have any other includes or classes that are named Path? This could have a conflict with System.IO.Path, in which case it would take the other class which wouldn't have the GetExtension method.

avatar image Bunny83 ThomasVandenberghe · Feb 19, 2016 at 04:23 PM 0
Share

Exactly, that's usually the reason for such errors. Things declared in the project itself usually takes precedence of things in other namespaces. So if there's a Path class (or any other type definition called "Path") the compiler will use that ins$$anonymous$$d of things declared in other namespaces.

Imported namespaces are always checked last. Likewise if you import two namespaces which both contains a class with the same name, the compiler can't tell which one you want to use as two imported namespaces have the same priority. A common example in Unity is the "Random" class. Unity's Random class is declared in the UnityEngine namespace which is imported by default. However the System namespace also has a Random class. So if you have a using UnityEngine; and a using System; in the same script and you try to use "the" / "a" Random class the compiler will throw an error "ambiguous reference".

Same problem exists with UnityEngine.Object and System.Object if you import both namespaces.

avatar image OswaldP Bunny83 · Feb 20, 2016 at 11:17 AM 0
Share

Thank you both for your answers. That was the problem indeed, one of the assets I imported must contains a different Path class. When I use the method in an empty project it works perfectly fine.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

OBB. How I can access files in OBB? 0 Answers

xmlreader android path problem 0 Answers

Configure default namespace for C# scripts in project? 0 Answers

namespace UnityEditor.iOS missing in one of two projects 0 Answers

Unity 5.6.0p3 does not recognize class inside namespace 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges