Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Could not load configuration file

Discussion in 'Scripting' started by sooaaib, Oct 16, 2020.

  1. sooaaib

    sooaaib

    Joined:
    Mar 15, 2020
    Posts:
    5
    I am trying to implement OPC UA client in Unity. But I am getting an ServiceResultException: Could not load configuration file expection in line
    Code (CSharp):
    1. application.LoadApplicationConfiguration("ConsoleReferenceClient.Config.xml", false).Wait();
    which means the "Config.xml" file couldn't be loaded in Unity. But the same program works perfectly in console application. How can I load the configuration file in unity?

    Code (CSharp):
    1. void Start()
    2. {
    3.             // Define the UA Client application
    4.             ApplicationInstance application = new ApplicationInstance();
    5.                 application.ApplicationName = "Quickstart Console Reference Client";
    6.                 application.ApplicationType = ApplicationType.Client;
    7.            
    8.    
    9.             // load the application configuration.
    10.             application.LoadApplicationConfiguration("Assets/ConsoleReferenceClient.Config.xml", false).Wait();
    11.                 // check the application certificate.
    12.                 application.CheckApplicationInstanceCertificate(false, 0).Wait();
    13.    
    14.                 // create the UA Client object and connect to configured server.
    15.                 Quickstarts.ConsoleReferenceClient.UAClient uaClient = new Quickstarts.ConsoleReferenceClient.UAClient(application.ApplicationConfiguration);
    16.    
    17.                 if (uaClient.Connect())
    18.                 {
    19.                     uaClient.ReadNodes();
    20.                     //uaClient.WriteNodes();
    21.                     uaClient.Browse();
    22.                     //uaClient.CallMethod();
    23.                     uaClient.SubscribeToDataChanges();
    24.                     System.Threading.Thread.Sleep(20000);
    25.    
    26.                     uaClient.Disconnect();
    27.                 }
    28.                 else
    29.                 {
    30.                     Debug.Log("Could not connect to server!");
    31.                 }
    32.                 Debug.Log("\nProgram ended.");
    33.                 Debug.Log("Press any key to finish...");
    34.                 Console.ReadKey();
    35. }
    Exception:

    Code (CSharp):
    1. ServiceResultException: Could not load configuration file.
    2.     Opc.Ua.Configuration.ApplicationInstance+<LoadApplicationConfiguration>d__33.MoveNext () (at <1c5dac388c934c65a66a1f12b206c16d>:0)
    3.     Rethrow as AggregateException: One or more errors occurred.
    4.     System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) (at <fb001e01371b4adca20013e0ac763896>:0)
    5.     System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) (at <fb001e01371b4adca20013e0ac763896>:0)
    6.     System.Threading.Tasks.Task.Wait () (at <fb001e01371b4adca20013e0ac763896>:0)
    7.     TestClient.Start () (at Assets/Scripts/TestClient.cs:25)
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You may need to insert Application.dataPath into the file path if you really want to use the Assets folder. Your post said it isn't finding Config.xml, I'm not sure if you're being brief or not, but the filename your code is actually trying to open is ConsoleReferenceClient.Config.xml. Make sure that's the actual filename. Also, you will not be able to open an xml file this way located in the Assets folder in a build. If your error is with your build, it is probably because the Assets folder does not actually exist in a build. Try using StreamingAssets instead.


    https://docs.unity3d.com/ScriptReference/Application-dataPath.html
    https://docs.unity3d.com/Manual/StreamingAssets.html

    I don't know anything specifically about OPC UA clients in Unity, so I'm just commenting on the potential file path issues.
     
  3. sooaaib

    sooaaib

    Joined:
    Mar 15, 2020
    Posts:
    5
    Thank you for your suggestion. I have tried that. The problem is not with the datapath. I have tried withour loading the file.
    I think the problem is for broken assembly. Some of my assembly couldn't be loaded. I have created a thread about that. Could you please help me regarding that?