Does anyone know how to import and access Windows.Devices.Enumeration.DeviceInformation.FindAllAsync()
from IronPython?
I have some C# code targeting .Net 4.5 on Win8.1 that I'm trying to port to Iron Python, example:
C# snippet:
using Windows.Devices.Enumeration;
DeviceInformationCollection devices= await DeviceInformation.FindAllAsync( /* removed */ );
However, I just can't seem to import the 'Windows' assembly.
clr.AddReference("Windows")
results in:
IOError: System.IO.IOException: Could not add reference to assembly Windows
Does anyone know a way?
Here's my full test case (updated in light of some comments):
import clr
clr.AddReference("System.Windows")
clr.AddReference("System.Linq")
clr.AddReference("System.Runtime")
clr.AddReference("System.Runtime.WindowsRuntime")
clr.AddReference("System.Runtime.InteropServices.WindowsRuntime")
print clr.References
import System
from System.Runtime import *
from System.Runtime.InteropServices.WindowsRuntime import *
import Windows
Windows.Devices.Enumeration.DeviceInformation.FindAllAsync()
Output:
(<mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>,
<System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>,
<IronPython.SQLite, Version=2.7.5.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1>,
<IronPython.Wpf, Version=2.7.5.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1>,
<System.Windows, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a>,
<System.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a>,
<System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a>,
<System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>,
<System.Runtime.InteropServices.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a>)
Traceback (most recent call last):
File "notnet.py", line 17, in <module>
AttributeError: 'namespace#' object attribute 'Devices' is read-only
UPDATE:
see: https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications
so naively tried it out, I'm not even sure IronPython can import .winmd files, or of the resulting error is a permissions or missing dependency problem:
import clr
import sys
sys.path.append(r"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1\ExtensionSDKs\Microsoft.VCLibs\12.0\References\CommonConfiguration\neutral")
sys.path.append(r"C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral")
clr.AddReferenceToFile("platform.winmd")
clr.AddReferenceToFile("Windows.winmd")
output:
SystemError: Operation is not supported. (Exception from HRESULT: 0x80131515)
User contributions licensed under CC BY-SA 3.0