Menu

Unable to use DWSIM.Automation.dll (Linux OS)

Dmitry
2020-12-01
2020-12-10
  • Dmitry

    Dmitry - 2020-12-01

    Hello!
    I have installed Mono and DWSIM version 6.2.2-amd64 as deb-package on Ubuntu 20.04.
    DWSIM works well if i run it as an application.
    However, when I try to use the API, I get an error during the call method Automation().

    For instance, my python code is:

    import clr
    import sys
    
    sys.path.append('/usr/local/lib/dwsim')
    
    clr.AddReference('/usr/local/lib/dwsim/DWSIM.Interfaces.dll')
    clr.AddReference('/usr/local/lib/dwsim/DWSIM.Automation.dll')
    
    from DWSIM import Interfaces, Automation
    
    process = Automation.Automation()
    process = process.LoadFlowsheet("Gas.dwxmz")
    

    After executing this script, I get:

    NullReferenceException Traceback (most recent call last)
    <ipython-input-1-c13c6f6f6a76> in <module>
    26 from DWSIM import Interfaces, Automation
    27
    ---> 28 process = Automation.Automation()
    29 process = process.LoadFlowsheet("home/raf/Gas.dwxmz")
    30 flowsheet = Interfaces.IFlowsheet(process)</module></ipython-input-1-c13c6f6f6a76>

    NullReferenceException: Object reference not set to an instance of an object
    at Microsoft.VisualBasic.ApplicationServices.AssemblyInfo.get_DirectoryPath () [0x00001] in <4240dd9f28434ace833cfdaa17202e70>:0

    Using Automation2() instead Automation() causes the Python's kernel to crash.
    The similar code works well for Windows 10.
    What am I doing wrong?

     
  • Daniel Medeiros

    Daniel Medeiros - 2020-12-01

    Automation2() works on macOS, and it should also work on Linux. Do you have more info on the crash? Did you try calling the Automation2() from a C# code?

     
    • Dmitry

      Dmitry - 2020-12-02

      Thanks a lot for the quick response!

      When i run my python script, i also get multiple files in my project directory kind of "mono_crash.mem.38580.1.blob". I found their content to be meaningless.

      I called the method from C# code and got no errors.
      However, I had to copy the executable file directly to dwsim directory where dll's are located.
      Specifically, my elementary C# code:

      using System;
      using DWSIM.Automation;
      using DWSIM.Interfaces;
      
      namespace DWSIM_test { 
          class MainClass {
              public static void Main(string[] args) {
      
                  var Automation = new DWSIM.Automation.Automation2();
                  var A = Automation.LoadFlowsheet("Gas.dwxmz");
              }
          }
      }
      

      This compiles (with links to DWSIM.Automation.dll and DWSIM.Interfaces.dll), but if I run the executable from my home directory, I get an error:
      $ mono DWSIM_test.exe
      """ Unhandled Exception:
      System.TypeLoadException: Could not load type of field 'DWSIM.Automation.Automation2:app' (0) due to: Could not load file or assembly 'Eto, Version=2.5.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
      [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type of field 'DWSIM.Automation.Automation2:app' (0) due to: Could not load file or assembly 'Eto, Version=2.5.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. """

      After copying my executable file to the directory with dll's (/usr/local/lib/dwsim/) and launched it from the dwsim directory - it's works well.
      I suspect there is some problem with dependency resolution Mono on Linux.
      Is it possible to somehow configure the project so that it can be loaded independently?
      Well, I also probably using libraries incorrectly...

       
  • Daniel Medeiros

    Daniel Medeiros - 2020-12-02

    Try playing with System.IO.Directory.SetCurrentDirectory()

     
  • Dmitry

    Dmitry - 2020-12-07

    Hello!
    It looks like this issue is pythonnet related. Similar crashes occur not only for me.

    I am using .net to interact with DVSIM API now.
    I would like to clarify the following.

    When I run DWSIM using command in terminal:

    :~$ mono /usr/local/lib/dwsim/DWSIM.exe
    

    I get the "classic UI" and I cannot calculate anything even by running the sample.
    At this point in the terminal, I see:

    Could not set X locale modifiers
    Gtk-Message: 20:03:48.402: Failed to load module "canberra-gtk-module"
    Error checking latest version: System.Net.WebException: Error: ProtocolError
    at System.Net.WebConnection.InitConnection (System.Net.WebOperation operation, System.Threading.CancellationToken cancellationToken) [0x00165] in <3d97dda773a54430b892e1d794e5d921>:0
    at System.Net.WebOperation.Run () [0x0009a] in <3d97dda773a54430b892e1d794e5d921>:0
    at System.Net.WebCompletionSource1[T].WaitForCompletion () [0x00094] in <3d97dda773a54430b892e1d794e5d921>:0 at System.Net.HttpWebRequest.RunWithTimeoutWorker[T] (System.Threading.Tasks.Task1[TResult] workerTask, System.Int32 timeout, System.Action abort, System.Func`1[TResult] aborted, System.Threading.CancellationTokenSource cts) [0x000f8] in <3d97dda773a54430b892e1d794e5d921>:0
    at System.Net.HttpWebRequest.GetResponse () [0x00016] in <3d97dda773a54430b892e1d794e5d921>:0
    at System.Net.WebClient.GetWebResponse (System.Net.WebRequest request) [0x00000] in <3d97dda773a54430b892e1d794e5d921>:0
    at System.Net.WebClient.DownloadBits (System.Net.WebRequest request, System.IO.Stream writeStream) [0x000e6] in <3d97dda773a54430b892e1d794e5d921>:0
    at System.Net.WebClient.DownloadDataInternal (System.Uri address, System.Net.WebRequest& request) [0x00061] in <3d97dda773a54430b892e1d794e5d921>:0
    at System.Net.WebClient.DownloadString (System.Uri address) [0x00011] in <3d97dda773a54430b892e1d794e5d921>:0
    at (wrapper remoting-invoke-with-check) System.Net.WebClient.DownloadString(System.Uri)
    at DWSIM.SharedClasses.UpdateCheck.CheckForUpdates () [0x00048] in <b97a4310545f46448b1501cf25ada8e5>:0
    [12/7/2020 8:04:06 PM] resource pool: create resource pool...
    [12/7/2020 8:04:06 PM] resource pool: create resource pool...
    [12/7/2020 8:04:08 PM] resource pool: font resource group added. font groups: 1</b97a4310545f46448b1501cf25ada8e5>

    But when I run DWSIM using command in terminal just like:

    :~$ dwsim
    

    I get "Cross-Platform UI" and when i try to simulate something - it works well!

    Also, when I use the saved .dwxmz file from the classic UI version in my .net application, using code like

    using System;
    using DWSIM.Automation;
    using DWSIM.Interfaces;
    namespace DWSIM_test
    { 
        class MainClass
        {
            public static void Main(string[] args) {
            DWSIM.Automation.Automation2 interf = new DWSIM.Automation.Automation2();
          DWSIM.Interfaces.IFlowsheet sim;
         sim = interf.LoadFlowsheet("home/Gas.dwxmz");
             }
         }
     }
    

    I get in terminal:
    """Solving Flowsheet, please wait...
    System.Exception: ABS-01: UnsupportedSolver ---> System.Exception: UnsupportedSolver
    at DWSIM.UnitOperations.UnitOperations.Column.Calculate (System.Object args) [0x019ca] in <84d6452e36fa4cc494ef5f2714d7c7d0>:0 ...
    System.Exception: ABS-01: UnsupportedSolver ---> System.Exception: UnsupportedSolver ...
    etc..."""

    However, when I use the saved .dwxmz file from the cross-platform UI version, it works fine!

    Does the format .dwxmz contain information about the type of UI?
    What is the fundamental difference between classic UI and cross-platform UI versions? Do both work well on Linux, or are there any features and preferences for Linux?
    I will be glad to receive any information.
    Thanks for your hard work.

     
  • Daniel Medeiros

    Daniel Medeiros - 2020-12-07

    Are you running the latest version (6.3.6)?

     
  • Dmitry

    Dmitry - 2020-12-10

    I used an older version (5.x.x), the newest version is much more stable, thanks!
    I access to spreadsheet cells from C# on Linux like this:

    using System;
    using DWSIM.Automation;
    using DWSIM.Interfaces;
    using DWSIM.CrossPlatform.UI.Controls.ReoGrid;
    
    namespace DWSIM_test
    { 
        class MainClass
        {
            public static void Main(string[] args) {
                string path = "home/test3.6.dwxmz";
                Automation2 process = new Automation2();
                IFlowsheet flowsheet = (IFlowsheet)process.LoadFlowsheet(path);
    
                var output = flowsheet.GetObject("MSTR-42");
                var input_ = flowsheet.GetObject("MSTR-01");
    
                var SpreadObject = flowsheet.GetSpreadsheetObject();
                ReoGridControl SpreadsheetData = (ReoGridControl)SpreadObject;
                var SpreadSheet = SpreadsheetData.GetWorksheetByName("MAIN");
                SpreadSheet.SetCellData("A20", 20000000); //Set data to A20
                Console.WriteLine(SpreadSheet.ToString());
                Console.WriteLine("X = " + SpreadSheet.GetCellData(19,0));
    

    and I get access to properties schematic elements like this:

                Console.WriteLine(output.GetPropertyValue("PROP_MS_0", null));
                Console.WriteLine(input_.GetPropertyValue("PROP_MS_0", null));
    

    Is there a better way to getting and setting values?

    About using ChemSep on Linux...
    When I run sample "Natural Gas Processing Unit with Turbo-Expansion (Classic UI - Windows only).dwxmz" on Linux (cross-platform UI) and Windows (classic UI), the sample is calculated successfully for both OS, although on Linux there is no access to CAPE-OPEN interface.
    - Can I set these variables via C # API on Linux?
    If the schema is evaluated for both operating systems, is the calculation correct for both?
    - Generally, does DWSIM С# API on Linux have fundamental restrictions to using ChemSep?
    If i using only DWSIM C# API - Is it possible to do, using classic UI on Windows, fundamentally, what cannot be done on Linux using cross-platform UI?

     

    Last edit: Dmitry 2020-12-10

Log in to post a comment.