Code: Select all
ApplicationLicenseManager.AddProcessLicenses(Assembly.GetExecutingAssembly(), "License.lic");
MyServerManager server = new MyServerManager();
ApplicationInstance.Default.Start(server, null, server); //Start the server
The same code works fine, if it's started internal from Main(). But as soon as i try to call the OpcUaServerStarter over an external Project in the same Project Map (for example a Test Project) the NullReferenceException appears.At ApplicationInstance.Default.Start(server, null, server)" following Error Appears: System.NullReferenceException: Object reference not set to an object instance. at UnifiedAutomation.UaServer.ServerSettings..ctor ( ApplicationInstance application ) at UnifiedAutomation.UaServer.ServerManager.OnServerStarting ( ApplicationInstance application ) at UnifiedAutomation.UaBase.ServerBase.Start ( ApplicationInstance application ) at UnifiedAutomation.UaServer.ServerManager.Start ( ApplicationInstance application ) at UnifiedAutomation.UaBase.ApplicationInstance.Start ( ServerBase server , WaitCallback callback , Object userData ) at VeitsServer.TapakoServerStarter.StartAkomiServer ( IDevice testDeviceToLink ) in TapakoServerStarter.cs : line . 39 at Implementationstests.OpcUaServerTest.ServerShouldRun ( ) in OpcUaServerTest.cs : line 44
Maybe the Project has to be compiled as a .dll or I have to add some references? Or it has some reason, that the visibility of MyServerManager is internal at the OPC-UA Tutorial.
MyServerManager Class (only critical difference to the working MyServerManager may be the public encapsulation):
Code: Select all
public class MyServerManager : ServerManager
{
private NodeManager _nodeManager;
private ObjectModel _objectModel;
/// <summary>
/// Method is called (from SDK) when NodeManager starts up.
/// </summary>
/// <param name="rootNodeManager"></param>
protected override void OnRootNodeManagerStarted(RootNodeManager rootNodeManager)
{
Console.WriteLine("Creating Node Manager.");
_nodeManager = new NodeManager(this);
_nodeManager.Startup();
_objectModel = new ObjectModel(_nodeManager);
}
/// <summary>
/// Creates an internal model of the given device and automatically creates nodes and callbacks
/// </summary>
/// <param name="device">AKOMI Device that will be shown on the Server</param>
public void LinkObjectToModel(IDevice device)
{
if (_objectModel == null)
{
throw new NullReferenceException("hv: objectModel is not initilized, try starting the server first.");
}
Console.WriteLine("Register Device: " + device.GetType().Name);
_objectModel.RegisterAkomiDevice(device, 0, 4);
}
/// <summary>
/// Creates an internal model of the given entity and automatically creates nodes and callbacks
/// </summary>
public void LinkObjectToModel(object entity, string name, int curLvl, int maxLvl)
{
if (_objectModel == null)
{
throw new NullReferenceException("hv: objectModel is not initilized, try starting the server first.");
}
Console.WriteLine("Register Entity: " + name);
_objectModel.RegisterEntity(entity, name, curLvl, maxLvl);
}
}
Thanks!