I also get the same thing for System.IO.StringReader.Close().[quote]
Assets\Code\Services\Inventory\InventoryService.cs(695,16): error CS1061: ‘System.IO.StringReader’ does not contain a definition for ‘Close’ and no extension method ‘Close’ accepting a first argument of type ‘System.IO.StringReader’ could be found (are you missing a using directive or an assembly reference?)
[/quote]These are the current two compiler warnings I get when trying to build.
That’s not the right thing to do.
The right way is to call Dispose() instead of Close() (does the same). You can also use XmlReader from WinRTLegacy.Xml namespace.
As for Close() method for StringReader, use WinRTLegacy namespace, it has extention method.
Setting the Compilation Overrides in the Build Settings from “Use Net Core” to “None” let me make a Win8.1 build, however we cannot pass Windows App certification like that. I’m figuring out that the parts of .NET available are restricted for Windows Store builds.
So looking at the XmlReader documentation, I see that the Close() method doesn’t have a green suitcase icon next to it, but the Dispose() method that Aurimas mentioned does have a green suitcase. Which, if I understand everything correctly, should mean that I can use Dispose() for Windows Store builds.
However, Unity is giving me an error on this code.
So it seems Dispose() has only existed since .NET 4.5. From what I can gather, Mono has not caught up to .NET 4.5 yet. I’m guessing this is why Unity doesn’t know about Dispose() and won’t let me build.
Can’t call Close() since it is not available to use in the Windows Store and can’t call Dispose() because Mono has not caught up to .NET 4.5 yet. What are my options?
I suppose I could comment the line out, create a Visual Studio Project, then edit the source through Visual Studio to call Dispose() before building.
You should be able to set compilation overrides to “Use .net core” (which will make Unity use .NET For Windows Store compiler, rather than Mono) and then add “using XmlReader = WinRTLegacy.Xml.XmlReader” to the top of your source file.
EDIT: To recap, Windows Store apps require some classes from .NET 4.5, which aren’t supported with Mono yet. So in the meantime, Unity is awesome and made some classes available through the WinRTLegacy namespace.
#if NETFX_CORE
using XmlReader = WinRTLegacy.Xml.XmlReader;
#else
using XmlReader = System.Xml.XmlReader;
#endif
public class SomeClass : MonoBehaviour
{
public void ParseXml(string xmlText) {
StringReader stringReader = new StringReader(text);
XmlReader xmlReader = XmlReader.Create(stringReader);
#if NETFX_CORE
xmlReader.Dispose();
#else
xmlReader.Close();
#endif
}
}
[quote=“bakno, post:10, topic: 530912, username:bakno”]
StringReader belongs to System.IO which is not available on Metro applications.
[/quote]Hello bakno!
System.IO is actually available. StringReader is available too. The Close() method is not, but the Dispose() method is!
EDIT: I found no way to tell if a class/method was available or not from the documentation. The only way i could tell was to attempt a build and see what classes and methods the compiler errors mentioned.
if you look up the documentation on MS’s website there is notation
for example… your dispose method
“Version Information
.NET Framework
Supported in: 4.5.1, 4.5
Portable Class Library
Supported in: Portable Class Library
.NET for Windows Store apps
Supported in: Windows 8”
and your close method
“Version Information
.NET Framework
Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client Profile
Supported in: 4, 3.5 SP1”
if you see “Supported in: Windows 8” in the Version info it is safe to use for windows store apps and windows phone.
I have noticed that before. If I see “.NET for Windows Store apps / Supported in: Windows 8”, then I know for sure the class/method is allowed.
The inverse isn’t true. Even if that text is missing, the class/method may still be available.
Eg: someObject.GetType() is not allowed, but someObject.GetTypeInfo().GetType() IS allowed. I couldn’t find anything on MSDN that would indicate this. I gave up searching MSDN and got back to coding. >.>
Hello Garth
I’m getting this error when using the solution above
error CS0266: Cannot implicitly convert type ‘System.Xml.XmlReader’ to ‘WinRTLegacy.Xml.XmlReader’. An explicit conversion exists (are you missing a cast?)
Did this happened to you?
Edit: Here’s what I put on this top of my script:
#if NETFX_CORE
using XmlReader = WinRTLegacy.Xml.XmlReader; #else
using XmlReader = System.Xml.XmlReader; #endif
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.IO;
using System.Text;
It sounds like somewhere the compiler thinks you want the wrong XmlReader. Maybe you are calling a function from another class that returns System.Xml.XmlReader instead of WinRTLegacy.Xml.XmlReader or something like that.