titanium-as / TitaniumAS.Opc.Client

Open source .NET client library for OPC DA
MIT License
197 stars 93 forks source link

Error in OpcDaBrowseElement[] elements = browser.GetElements(itemId); #8

Closed CSharpDummy closed 7 years ago

CSharpDummy commented 7 years ago

My code fails here:

OpcDaBrowseElement[] elements = browser.GetElements(itemId);

not much info ..

FatalExecutionEngineError occurred HResult=-2146233082 Message=Exception of type 'System.ExecutionEngineException' was thrown. InnerException:

alexey-kachalov commented 7 years ago

Hi!

The 'System.ExecutionEngineException' (80131506) is pretty general and can be caused by many things. It is impossible to say more about it without detailed information.

Could you explain your environment? What version of .NET is installed on you PC? Wich OPC-server do you use? Have you installed Opc Core Components (https://opcfoundation.org/developer-tools/developer-kits-classic/core-components)?

Also, give us a little bit more code, please.

CSharpDummy commented 7 years ago

The code is pretty much from your example (see below) I use also the Matrikon Test server. I did install the OPC core components. I compiled the project under Net 4.52

class Program
{
    private const string ServerUri = "Matrikon.OPC.Simulation.1"; //ProgId for matrikon simulation server
    private const string SubscribeItemId = "Random.Int4"; //itemId for subscribed opc item
    private const string GroupName = "TestGroup"; //group name for make subscription
    private const int UpdateRateInMilliseconds = 1000; //subscription update rate for group
    [MTAThread]
    static void Main(string[] args)
    {
        Uri url = UrlBuilder.Build("Matrikon.OPC.Simulation.1");
        using (var server = new OpcDaServer(url))
        {
            // Connect to the server first.
            server.Connect();

            // Browse elements.
            var browser = new OpcDaBrowserAuto(server);
            BrowseChildren(browser);

        }
    }

    private static void BrowseChildren(IOpcDaBrowser browser, string itemId = null, int indent = 0)
    {
        // Browse elements.
        // When itemId is null, root elements will be browsed.
        OpcDaBrowseElement[] elements = browser.GetElements(itemId);

        // Output elements.
        foreach (OpcDaBrowseElement element in elements)
        {
            // Output the element.
            Console.Write(new String(' ', indent));
            Console.WriteLine(element);

            // Skip elements without children.
            if (!element.HasChildren)
                continue;

            // Output children of the element.
            BrowseChildren(browser, element.ItemId, indent + 2);
        }
    }
alexey-kachalov commented 7 years ago

Hm. I have tried with you code and it works. I tried with simplified one:

  1. I have created new console project.
  2. Added package.
  3. Added the following simlified code instead if "main".
    static void Main()
    {
    Uri url = UrlBuilder.Build("Matrikon.OPC.Simulation.1");
    using (var server = new OpcDaServer(url))
    {
        server.Connect();
        var browser = new OpcDaBrowserAuto(server);
        OpcDaBrowseElement[] elements = browser.GetElements("Bucket Brigade");
        OpcDaBrowseElement element = elements.First(i => i.ItemId == "Bucket Brigade.Int4");
        Console.WriteLine(element);
        Console.ReadLine();
    }
    }
  4. Built and run.
  5. It showed me "Bucket Brigade.Int4" item description.

Things you can try:

  1. Try my way.
  2. Check if you use x86 building and runtime environments.
  3. Try with tests on the solutuion.
chinmaykathale commented 2 years ago

Hi, I am facing the same issue while browsing the element,

I am using .Net Core 3.1 framework and installed TitaniumAS.Opc.Client.NetCore NuGet package for the same. i also installed Opc Core Components.

Even when i passed null input to GetElements method, i am facing this exception

Capture

i am using this method to browser channel list from server, the exception is not showing when we pass any string like "Bucket Brigade" or directly server name. but we are not getting any channel list or element, its giving empty output.