NullpointerException @ ApplicationInstance.Default.Start

Unified Architecture topics related to OPC UA Specification, compliant behavior and any technical issues of OPC UA, like Security, Information Model, Companion Specs DI, PLCopen, ADI, ...

Moderator: Support Team

Post Reply
fellfalla
Full Member
Full Member
Posts: 6
Joined: 12 Aug 2015, 17:44

NullpointerException @ ApplicationInstance.Default.Start

Post by fellfalla »

I tried to start an OPC UA Server this way: http://documentation.unified-automation ... ess01.html

Code: Select all

ApplicationLicenseManager.AddProcessLicenses(Assembly.GetExecutingAssembly(), "License.lic");
MyServerManager server = new MyServerManager();
ApplicationInstance.Default.Start(server, null, server); //Start the server
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
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.

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);
    }

}
For an Image of the Debug session visit the same Question at http://stackoverflow.com/questions/3192 ... s-nullpoin

Thanks!

fellfalla
Full Member
Full Member
Posts: 6
Joined: 12 Aug 2015, 17:44

Re: NullpointerException @ ApplicationInstance.Default.Start

Post by fellfalla »

I already found the Solution by myself. Hope this post will help anybody.
http://stackoverflow.com/questions/3192 ... 5_31922402

Post Reply