Oaz / Femyou

loading and running fmi-standard FMUs in dotnet core
MIT License
16 stars 7 forks source link

Load FMU with Femyou not working #6

Open bflo96 opened 1 month ago

bflo96 commented 1 month ago

Hello!

I have a program in C#, running on Visual Studio 2019, with target framework netcoreapp3.1. I used Open Modelica v1.22.3 (64-bit).

My code:

using System;
using System.Collections.Generic;
using System.Text;

namespace TesteFMU
{
    public class Program
    {
       public static void Main(string[] args)
       {
          TestFMU test = new TestFMU();
          test.Calculation();
          Console.Write("Calculation concluded.");
       }
    }
using System;
using Femyou;
using System.IO;

namespace TestFMU
{
    public class TestFMU
    {
        public void Calculation()
        {
            string fmuFolder = File.ReadAllText(@"C:\FMUTests\");
            using var model = Model.Load(Path.Combine(fmuFolder, "TestFemyou.fmu"));
            using var instance = Tools.CreateInstance(model, "test");
            var x = model.Variables["x"];
            var y = model.Variables["y"];
            var z = model.Variables["z"];
            Console.WriteLine("x = " + Convert.ToString(x));
        }
    }
}

However, when I try to load the FMU, it shows this error:

System.IO.FileNotFoundException: 'Could not find or load the native library: C:\Users\10376\AppData\Local\Temp\Femyou\TestarFemyou.fmu\binaries\win64\TestarFemyou.dll

I don't understand why it tries to load a native library and why it fails despite the DLL being available when I manually check the folder. Could it be a compatibility issue? The example BouncingBall.fmu works just fine.

Thank you!

Oaz commented 1 month ago

My best guess here would be to check the dependencies of TestarFemyou.dll and make sure that they are all included in TestarFemyou.fmu Missing dependencies is a common case of dll loading error. I have not used MS Windows for a long time but, if I remember correctly, a free tool such as DependenciesWalker could help : https://dependencywalker.com/