none
How to include Windows.Ai.Machinelearning into a C# program ?

    Question

  • Hi. I'm trying to use winML with c# to do some projects. I currently can't include a lot of libraries into my project as I tried to do the machine learning tutorial from microsoft . I need to include the following dependancies into my program :

    using Windows.Storage;
    using System.Windows.Graphics.Imaging;
    using System.Windows.Storage.Streams;
    using System.Windows.AI.MachineLearning.Preview;
    using System.Windows.Foundation;
    using System.Windows.Media;

    However visual studio tells me that they are all no recognized. I have a :

    Windows 10 Professional version 1809 (build 17763.253)

    Microsoft visual studio 2017 with Windows 10 SDK (10.0.17763.0)

    Thank you for your help in advance

    Tuesday, February 12, 2019 12:03 AM

Answers

  • Hi friend,

    Now I understand what you want. I find two documents about this in Unity website. Hope you can get help from them. Universal Windows Platform: WinRT API in C# scripts and Universal Windows Platform: Plugins on .NET Scripting Backend 

    And since this VS forum which discuss issues when developing within VS IDE. And your issue is more related to Unity, I recommend you open a new thread in Unity forum to get more professional support.

    Thanks for your understanding and cooperation.

    Have a nice day! And if you have any issues when using visual studio, feel free to contact us.

    Best Regards

    Lance


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by VV19 Tuesday, March 5, 2019 6:25 AM
    Tuesday, March 5, 2019 6:19 AM

All replies

  • Hi VV19,

    Welcome to MSDN forum.

    As for this issue, I can’t reproduce it in my side. And about the tutorial you mentioned above, does it refer to this document?

    In my machine(windows 1803), if I create a blank UWP app, I can include dependences like below:

    using Windows.Storage;
    using Windows.Graphics.Imaging;
    using Windows.Storage.Streams;
    using Windows.AI.MachineLearning.Preview;
    using Windows.Foundation;
    using Windows.Media;

    And if I open the tutorial sample, the dependences should be like what shows below:


    So I think what you need is to include dependences whose prefix is ‘windows.’ Instead of ‘system. windows’ . For more details about WinRt apis see here.

    And to follow the tutorial, please make sure we download the entire windows-Machine-Learning resource. After Extract it, navigate to “Windows-Machine-Learning-master\Samples\MNIST\Tutorial\cs” folder, open the MNIST_Demo.sln with vs2017. And after that, I think you can get a good start for this tutorial.

    In addition: Don’t forget add new existing item from asserts to mnist.onnx, so that mnist.cs can display and work.

    Hope all above can help solve your issue. Any update please feel free to share here. We are looking forward to your reply!

    Best Regards

    Lance


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Tuesday, February 12, 2019 6:36 AM
  • Check the tutorial with regards to the type of application: Forms, UWP, WPF, Console? Some of ‘using’ can be only used in specific kinds of programs.

    In order to use ML, see, for example, the “Install the Microsoft.ML NuGet Package” section: https://docs.microsoft.com/en-us/dotnet/machine-learning/tutorials/sentiment-analysis.

    Tuesday, February 12, 2019 6:55 AM
  • Hi friend,

    Haven't heard from you.If there has any update, please feel free to contact us.

    Looking forward to your reply!

    Best Regards

    Lance


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 18, 2019 6:18 AM
  • Hi. Thank you for your response and I apologize as I didn't receive the alert for this response. My current problem is that I cannot include these libraries into my Unity project. I have some scripts for the Hololens that I need to use ONNX models with but I cannot import the desired libraries.

    I would appreciate any help. 

    Monday, March 4, 2019 3:49 AM
  • Hi friend,

    Thanks for your feedback.

    >>My current problem is that I cannot include these libraries into my Unity project.

    Does the Unity project refers to the C# program which you mentioned at first thread?

    And this project can't include the dependancies below?

    using System.Windows.Graphics.Imaging;
    using System.Windows.Storage.Streams;
    using System.Windows.AI.MachineLearning.Preview;
    using System.Windows.Foundation;

    Have you tried my first reply since the dependencies you want with  prefix 'System' doesn't exist in System namespace? I've checked the dependencies you mentioned like: System.Windows.Storage.Streams; 

    It doesn't exist and we only have Window.Storage.Streams in C#. Please check what dependencies you really need.

    Best Regards

    Lance


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 4, 2019 10:20 AM
  • Hi and thanks for the reply.

    I do need :

    using Windows.Storage; using Windows.Graphics.Imaging; using Windows.Storage.Streams; using Windows.AI.MachineLearning.Preview; using Windows.Foundation; using Windows.Media;

    in my projects however I don't know how to include winRT in my c# unity scripts. I looked at the links and unfortunately I still don't understand how to fix this problems. 

    Thank you for your help 

    Monday, March 4, 2019 4:46 PM
  • Hi friend,

    Do you use the C# unity scripts in VS IDE? And what kind of project you create?

    Check the document about winRT and you can find these apis only support for certain projects such like UWP projects. And that means if we create a simple C# console app, we can't directly use those namespaces.

    Instead if we create a UWP project(blank or dll), we can directly include them by:

    using Windows.Storage;
    using Windows.Graphics.Imaging;
    using Windows.Storage.Streams;
    using Windows.AI.MachineLearning.Preview;
    using Windows.Foundation;
    using Windows.Media;
    So the type of project is important. Not sure about what kind of project you use, please make sure 

    you've installed UWP workload in VS like below(Go Tools->Get tools and features->To check):

    Download the uwp workload, and it will install related winRT assemblies for you. After that, check if you can use the namespaces in your project. 

    Best Regards

    Lance


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 5, 2019 5:36 AM
  • Hi and thank you for the reply.

    Sorry if I was unambiguous with my questions. I am trying to use these libraries with a unity project to use them with Hololens and I needed to include them in my scripts. I was thinking if there is a way to include them in unity but I can't find any solutions for that at the moment. 

    Thanks for your help

    Tuesday, March 5, 2019 6:04 AM
  • Hi friend,

    Now I understand what you want. I find two documents about this in Unity website. Hope you can get help from them. Universal Windows Platform: WinRT API in C# scripts and Universal Windows Platform: Plugins on .NET Scripting Backend 

    And since this VS forum which discuss issues when developing within VS IDE. And your issue is more related to Unity, I recommend you open a new thread in Unity forum to get more professional support.

    Thanks for your understanding and cooperation.

    Have a nice day! And if you have any issues when using visual studio, feel free to contact us.

    Best Regards

    Lance


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by VV19 Tuesday, March 5, 2019 6:25 AM
    Tuesday, March 5, 2019 6:19 AM
  • Thanks a lot for your help and support. I am going to work with those documentations to see if I can use them on the Hololens.

    With Regards

    Tuesday, March 5, 2019 6:27 AM
  • You're welcome, friend. Hope it helps you solve your issue.

    Have a nice day!


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 5, 2019 6:29 AM