I am trying to implement OPC UA client in Unity. But I am getting an ServiceResultException: Could not load configuration file.
expection in line 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?
void Start()
{
// Define the UA Client application
ApplicationInstance application = new ApplicationInstance();
application.ApplicationName = "Quickstart Console Reference Client";
application.ApplicationType = ApplicationType.Client;
// load the application configuration.
application.LoadApplicationConfiguration("Assets/ConsoleReferenceClient.Config.xml", false).Wait();
// check the application certificate.
application.CheckApplicationInstanceCertificate(false, 0).Wait();
// create the UA Client object and connect to configured server.
Quickstarts.ConsoleReferenceClient.UAClient uaClient = new Quickstarts.ConsoleReferenceClient.UAClient(application.ApplicationConfiguration);
if (uaClient.Connect())
{
uaClient.ReadNodes();
//uaClient.WriteNodes();
uaClient.Browse();
//uaClient.CallMethod();
uaClient.SubscribeToDataChanges();
System.Threading.Thread.Sleep(20000);
uaClient.Disconnect();
}
else
{
Debug.Log("Could not connect to server!");
}
Debug.Log("\nProgram ended.");
Debug.Log("Press any key to finish...");
Console.ReadKey();
}
Exception:
ServiceResultException: Could not load configuration file.
Opc.Ua.Configuration.ApplicationInstance+<LoadApplicationConfiguration>d__33.MoveNext () (at <1c5dac388c934c65a66a1f12b206c16d>:0)
Rethrow as AggregateException: One or more errors occurred.
System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) (at <fb001e01371b4adca20013e0ac763896>:0)
System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) (at <fb001e01371b4adca20013e0ac763896>:0)
System.Threading.Tasks.Task.Wait () (at <fb001e01371b4adca20013e0ac763896>:0)
TestClient.Start () (at Assets/Scripts/TestClient.cs:25)
Check if
ConsoleReferenceClient.Config.xml
is copied into output folder of your unity project. Then check the location of your executable, because the relative path (first parameter ofLoadApplicationConfiguration
method) needs to point from executable to config file).