Skip to content

NULL Reference Exception - AddGroup #70

Description

@shrivicky

Dear everyone,
I'm getting a NULL reference error while adding the group. ie: in line -> opcDaGroup = server.AddGroup("Group");
Please help me out what's the issue and how to overcome the same.
Error

    public OpcDaGroup opcDaGroup;

    private void StartConnection(string Cls_Id, string Machine_IpAddress)
    {
        try
        {
            log.Debug("START - Starting the connection");
            Uri url = UrlBuilder.Build(Cls_Id, Machine_IpAddress);
            server = new OpcDaServer(url);
            server.Connect();
            log.Debug("END   - Starting the connection");
        }
        catch (Exception e)
        {
            log.Error("Could not connect to the OPC server for the IpAddress: {0}", e);
        }
    }

    public OpcDaAdapterThreadImpl(string Cls_Id, string Machine_IpAddress, string name, ICollection<TagConfigurationModel> tags)
    {
        this.Cls_Id = Cls_Id;
        this.Machine_IpAddress = Machine_IpAddress;
        this.name = name;
        this.AdapterReady = true;
        Tags = tags;
        var group = tags.GroupBy(c => new { ItemName = c.TagName }).Select(c => c.Key).Distinct();
        grouptags = group.Select(c => new TagConfigurationModel { TagName = c.ItemName }).ToList();
        opcTagItems = grouptags.Select(c => new OpcDaItemDefinition { ItemId = c.TagName, IsActive = true }).ToList();
        // Connection Initializing
        StartConnection(Cls_Id, Machine_IpAddress);
        if (server.IsConnected)
        {
            // Add group to the server
            opcDaGroup = server.AddGroup("Group");
            opcDaGroup.IsActive = true;

            // Add Items to group
            opcDaGroup.AddItems(opcTagItems);
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions