Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

× If you are developing in .NET, but are using the OPC-UA (OPC Unified Architecture), please post in the QuickOPC-UA category instead.

EasyOPCDA Client Freezes when placed in multithreaded application

More
29 Apr 2022 07:52 - 29 Apr 2022 07:59 #10837 by support
Hi.
I was able to reproduce what you are seeing.

However, while the symptoms are quite similar as before, the cause of the problem is now different. What happens is that the assembly references in the project file are mixed up, and that causes the App_Web* assemblies to be not found.

There are multiple issues in the project file (WIN_TEST.csproj), e.g. there is:

<Reference Include="App_Web_OpcLabs.EasyOpcClassicRaw.amd64, Version=5.62.456.1, Culture=neutral, PublicKeyToken=6faddca41dacb409, processorArchitecture=AMD64">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\..\..\..\..\Program Files (x86)\Software Toolbox OPC Data Client 2021.3\Assemblies\net47\App_Web_OpcLabs.EasyOpcClassicRaw.amd64.dll</HintPath>
    </Reference>
    <Reference Include="App_Web_OpcLabs.EasyOpcClassicRaw.x86, Version=5.62.456.1, Culture=neutral, PublicKeyToken=6faddca41dacb409, processorArchitecture=x86">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\..\..\..\..\Program Files (x86)\Software Toolbox OPC Data Client 2021.3\Assemblies\net47\App_Web_OpcLabs.EasyOpcClassicRaw.x86.dll</HintPath>
    </Reference>
- this has an incorrect version/build number (5.62.456.1) compared to what the other assemblies have (5.62.1032.1), and in addition it leads to a path that's not inside the solution zip file.


When App_Web* assemblies are not found on the main thread (with lines 48-49 in Program.cs) present, it throws the exception you reported, and the whole program crashes.

When lines 49-49 in program.cs are commented out, the "not found" error then happens inside the task. In this case, unfortunately, it gets swallowed up and nothing is reported. So, the program is actually not "stuck" in "_easyDaClient.EventingFailure += OnEasyOpcDaEventingFailure;". It has thrown an exception there.

You can verify that this is the case by placing a breakpoint into the "catch" block of StartClient(), and inspecting the exception object ("ex").

Remedy:
1. In the project References, do "Manage NuGet Packages", and remove the OpcLabs.QuickOpc package
2. In the project References, remove any remaining OPC Data Clients assemblies. Specifically, remove the App_Web* assemblies.
3. In the project References, do "Manage NuGet Packages", and add the OpcLabs.QuickOpc package.

Note that when I first received your solution, I had removed the assembly references and replaced them with those that work on my system, without realizing that wrong assembly references can themselves be the cause. But the issue with BoxedApp exists as well I believe.

Best regards
Last edit: 29 Apr 2022 07:59 by support.

Please Log in or Create an account to join the conversation.

More
28 Apr 2022 14:23 #10836 by Restrepo
Here you can find the - Latest Solution

Please take a look at line 15 in Program.cs

Let me know if you need anything else. thank you in advance.

Please Log in or Create an account to join the conversation.

More
28 Apr 2022 13:38 #10835 by support
Hello,
no, no changes to the original C# code should be needed, just the app.config modification.

In my test, adding the <appSettings> part - which looks like yours in the picture - resolves the issue with the original code reliably.

Please send the current state of you solution so that I can check that we have the same thing.

Best regards

Please Log in or Create an account to join the conversation.

More
28 Apr 2022 13:07 #10834 by Restrepo
Thank you for the reply.

Ok so for my clarity, disabling the Boxing seems to resolve the issue, but do I still need to proactively load up the App_Web_OpcLabs.EasyOpcClassicRaw.x86 and the App_Web_OpcLabs.EasyOpcClassicRaw.amd64 binaries?

The reason I asked is that I disabled the boxing as you can see in the screenshot attached but it is still stuck on Hooking Event...
Attachments:

Please Log in or Create an account to join the conversation.

More
28 Apr 2022 12:19 #10833 by support
Hello,

your mention of boxedApp has triggered my suspicion. I think it is actually the cause the problem (sorry, Microsoft, for blaming you prematurely). I am fighting with this library quite a lot. It is used to make the deployment easier - so that users don't have to deploy things like OPC Core Components, Visual C++ libraries, or OPC UA Certificate Generator. Which is good, but it apparently has problems in some situations.

With knowing this, I was able to get the problems go away by following the instructions here: kb.opclabs.com/How_to_disable_prerequisites_boxing (basically, copy the section from the snippet at the bottom of the page, and paste it appropriately into project's app.config in Visual Studio.

In some cases (but not so often, because many users already have them) it may then be necessary to install the actually prerequisites the BoxedApp was meant to provide:
opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...ml#Prerequisites%20Boxing.html

Best regards

Please Log in or Create an account to join the conversation.

More
27 Apr 2022 19:54 #10832 by Restrepo
Thank you for the reply.

So the customer give it a try and here is what he encountered.

He tried the second option and Subscribe to the Item using “_easyDaClient.SubscribeItem(_machine, _serverAddress, opcItemId, 1000);”; however, the application freezes, and it seems that is because the event “ItemChanged” never get triggered until one clicks the app title and clicks outside of the application (like before). So, it looks as if option 2 is also generating issues that are causing the application to freeze when it is trying to raise the “ItemChanged” event.


Now, it looks like the customer found another work that involves proactively loading the DLL before creating the OPC client object See screenshot attached. Well, It seems to hook up the events successfully but now it gets stuck while subscribing to an item or if calling on BrowseBranches.

In the case of when getting stuck while trying to SubscribeItem, Doing some debugging It looks like as if it is trying to load "opc_aeps.dll", "opccomn_ps.dll", "opcproxy.dll", and "OpcLabs.EasyOpc.Boxing.Redistributables.res.x86.opc_aeps.dll" (x86 or x64) from C:\\Windows\\system32\\” and “C:\\Program Files (x86)\\Common Files\\OPC Foundation\\Bin\\” into some _boxedApp by calling RegisterComLibraryInVirtualRegistry. Do you happen to know the location of those assembly files? Attached you can see the trace.

Let me know if you have any questions. Thank you for your assistance.
Attachments:

Please Log in or Create an account to join the conversation.

More
27 Apr 2022 15:30 #10831 by support
Hello.

Thank you, I was able to reproduce the issue using your solution. And, the key is in the call stack you also provided - there, it can be seen that the program has blocked itself when trying to load one of the assemblies we have for OPC Classic.

However, I have very high confidence (although not 100% certainty) that there is nothing wrong in user's code, or our code. It looks like Microsoft problem. There is nothing else than simply loading that assembly (dynamically) inside the queued Task. This should work.

Since these are "mixed-mode" assemblies (with native code) that are rarely used, I would not be surprised that there was some problem inside MS part that has not been discovered yet.

Given this, I can only provide workarounds. I tried two of them, and there may be more:

1) Trigger loading of the mixed-mode assembly at least once BEFORE it would get loaded from inside the Task, e.g.:
        static async Task Main(string[] args)
        {
            var _easyDaClient = new EasyDAClient();
            _easyDaClient.ItemChanged += (sender, eventArgs) => { };
 
            ThreadPool.QueueUserWorkItem(async o =>
            {
                await SourceManager.Singleton.Start();
            });
 
            Console.WriteLine("Waiting.....");
            Console.ReadLine();
        }

OR

2) Switch to fully managed code implementation of OPC Classic client part (slight behavior differences may exist between the two implementation):
        public bool StartClient()
        {
            try
            {
                Console.WriteLine("Creating client obj...");
 
                var _easyDaClient = new EasyDAClient();
                _easyDaClient.InstanceParameters.EnableNativeClient = false;
 
                ...
        }
 

Best regards

Please Log in or Create an account to join the conversation.

More
27 Apr 2022 04:10 #10830 by Restrepo
sorry, forgot to add the sample app. I am not sure if the attachment will make through, but in case it does not, you can get the sample app here - Project File Download

Please Log in or Create an account to join the conversation.

More
27 Apr 2022 04:02 #10829 by Restrepo
Hey, thank you for the quick reply.

Attached you have a sample application where the customer is able to replicate the behavior. If you run the application you can see that the code never passes the Hooking Event... line as seen on screenshot CosoleOutput.png.

The customer also was able to gather a trace which I have also included.

Please let me know if you have any other questions.

Thank you.
Attachments:

Please Log in or Create an account to join the conversation.

More
25 Apr 2022 20:03 #10822 by support
Hello.

There are some concerns that have to do STA/MTA threads and SynchronizationContext, but before we get to explaining that (and sometimes that gets complicated and I do not pretend to fully understand all of it either), do you have a reproducible project (possibly the console one, for start) for me to look at?

Thank you

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.067 seconds