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.

Attempt to add existing key into a dictionary

More
26 Feb 2018 20:34 #6076 by support
Although I was not able to reproduce the issue, I found that a synchronization statement is missing, and that it is a likely cause of the problem.

This is now fixed in the currently posted QuickOPC 2018.1 (on our Web page, and also in the NuGet packages). It is version/build 5.52.91 or later.

Please rebuild your project with it and re-test.

Best regards

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

More
20 Feb 2018 17:04 #6065 by support
Hello,

Thank you very much for the additional information. It is very helpful. From the call stack, it looks like a bug in QuickOPC. Unfortunately I cannot determine more details until next week when I am back in the office.

Please bear with me and I will respond then.

Best regards
The following user(s) said Thank You: giles

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

More
20 Feb 2018 09:19 #6063 by giles
Hi I am now setting application name
this log shows call stack and log entries
 
 
Running a transacted installation.
Beginning the Install phase of the installation.
See the contents of the log file for the C:\XML Download\[DELETED INFO 1]\OpcToXml.exe
assembly's progress.
The file is located at C:\XML Download\[DELETED INFO 1]\OpcToXml.InstallLog.
Installing assembly 'C:\XML Download\[DELETED INFO 1]\OpcToXml.exe'.
Affected parameters are:
   logtoconsole =
   assemblypath = C:\XML Download\[DELETED INFO 1]\OpcToXml.exe
   logfile = C:\XML Download\[DELETED INFO 1]\OpcToXml.InstallLog
Installing service OpcXml...
Creating EventLog source OpcXml in log Application...
Log entry: OPC-UA engine application info 'Time' -> UtcNow: 02/20/2018 08:58:48,
 Now: 02/20/2018 03:58:48, TickCount: 332722894.
Log entry: OPC-UA engine application info 'Debugger' -> IsAttached: False.
Log entry: OPC-UA engine application info 'AssemblyProperties' -> FullName: "Opc
Labs.BaseLib, Version=5.52.66.2, Culture=neutral, PublicKeyToken=6faddca41dacb40
9", Location: "C:\XML Download\[DELETED INFO 1]\OpcLabs.BaseLib.dll", GlobalAssemblyCac
he: False.
Log entry: OPC-UA engine application info 'AssemblyAttributes' -> AssemblyConfig
uration: "Release".
Log entry: OPC-UA engine application info 'AppDomain' -> Id: 1.
Log entry: OPC-UA engine application info 'Clr' -> Version: '4.0.30319.34209', P
trSize: 8.
Log entry: OPC-UA engine application info 'Process' -> Is64BitProcess: True, Cur
rentDirectory: "C:\XML Download\[DELETED INFO 1]", Id: 1684.
Log entry: OPC-UA engine application info 'User' -> Name: "richmar7", DomainName
: "[DELETED INFO 2]", Interactive: True.
Log entry: OPC-UA engine application info 'OSConfiguration' -> MachineName: "GBC
RAPT10009", SystemPageSize: 4096.
Log entry: OPC-UA engine application info 'OperatingSystem' -> VersionString: "M
icrosoft Windows NT 6.1.7601 Service Pack 1".
Log entry: OPC-UA engine application info 'Environment' -> Is64BitOperatingSyste
m: True, SystemDirectory: "C:\windows\system32".
Log entry: OPC-UA engine application info 'Computer' -> ProcessorCount: 2.
Log entry: The OPC-UA engine is connecting to the underlying subsystems.
Log entry: OPC-UA engine SDK configuration successfully provided by "OpcLabs.Eas
yOpc.UA.Toolkit.InternalSdkConfigurationProvider".
Log entry: OPC-UA engine SDK configuration successfully provided by "OpcLabs.Eas
yOpc.UA.Toolkit.InternalSdkConfigurationProvider".
Log entry: The OPC-UA engine has determined the client instance certificate para
meters as listed below.
SubjectName: OPC XML File Writer
StorePath: %CommonApplicationData%\OPC Foundation\CertificateStores\MachineDefau
lt
ApplicationName: OPC XML File Writer
ApplicationUri: urn:[DELETED INFO 3]:InstallUtil:4.0.0.0:neutral:b03f5f7f11d50a3a
Log entry: The OPC-UA engine has determined the client instance certificate para
meters as listed below.
SubjectName: OPC XML File Writer
StorePath: %CommonApplicationData%\OPC Foundation\CertificateStores\MachineDefau
lt
ApplicationName: OPC XML File Writer
ApplicationUri: urn:[DELETED INFO 3]:InstallUtil:4.0.0.0:neutral:b03f5f7f11d50a3a
Log entry: The OPC-UA engine will resolve the client instance certificate parame
ters directory store path to "C:\ProgramData\OPC Foundation\CertificateStores\Ma
chineDefault".
Log entry: The OPC-UA engine will resolve the client instance certificate parame
ters directory store path to "C:\ProgramData\OPC Foundation\CertificateStores\Ma
chineDefault".
Log entry: The OPC-UA engine has determined the application configuration parame
ters as listed below.
ProductUri: urn:literal:string:Microsoft%C2%AE%20.NET%20Framework
Log entry: The OPC-UA engine has determined the application configuration parame
ters as listed below.
ProductUri: urn:literal:string:Microsoft%C2%AE%20.NET%20Framework
Attempt to add existing key into a dictionary.
   at OpcLabs.BaseLib.Diagnostics.Always.Requires[TException](Boolean condition,
 String userMessage)
   at OpcLabs.BaseLib.Boxing.ManagedBoxedApp.SupportsFileVirtualizationForExecut
ion(Int32 bitness)
   at OpcLabs.BaseLib.Boxing.Boxer.CreateBoxedFile(String virtualPath, Stream st
ream, Int32 executionBitness)
   at OpcLabs.BaseLib.Boxing.Boxer.CreateFileFromManifestResource(IEnumerable`1
boxedFilePaths, Assembly assembly, String resourceName, Boolean weakBoxing, Int3
2 executionBitness, String& boxedFilePath)
   at OpcLabs.EasyOpc.UA.Boxing.Redistributables.UACertificateGeneratorBoxer.Box
UABinary(String fileName, Boolean weakBoxing, Int32 executionBitness)
   at OpcLabs.EasyOpc.UA.Boxing.Redistributables.UACertificateGeneratorBoxer.Box
()
   at OpcLabs.EasyOpc.UA.Toolkit.UAClientEngineBase.ValidateOrCreateClientCertif
icate(ApplicationInstance sdkInstance)
   at OpcLabs.EasyOpc.UA.Toolkit.UAClientEngineBase.CreateSdkApplicationInstance
(ApplicationInstance& sdkApplicationInstance)
   at OpcLabs.EasyOpc.UA.Implementations.NetSdk.NetSdkEasyUAClient.Install()
   at OpcToXml.ProjectInstaller.serviceInstaller1_AfterInstall(Object sender, In
stallEventArgs e) in C:\OpcFileWriter\OpcToXml\ProjectInstaller.cs:line 30
An exception occurred in the OnAfterInstall event handler of System.ServiceProce
ss.ServiceInstaller.
System.ArgumentException: Attempt to add existing key into a dictionary.
An exception occurred during the Install phase.
System.InvalidOperationException: An exception occurred in the OnAfterInstall ev
ent handler of System.ServiceProcess.ServiceInstaller.
The inner exception System.ArgumentException was thrown with the following error
 message: Attempt to add existing key into a dictionary..
The Rollback phase of the installation is beginning.
See the contents of the log file for the C:\XML Download\[DELETED INFO 1]\OpcToXml.exe
assembly's progress.
The file is located at C:\XML Download\[DELETED INFO 1]\OpcToXml.InstallLog.
Rolling back assembly 'C:\XML Download\[DELETED INFO 1]\OpcToXml.exe'.
Affected parameters are:
   logtoconsole =
   assemblypath = C:\XML Download\[DELETED INFO 1]\OpcToXml.exe
   logfile = C:\XML Download\[DELETED INFO 1]\OpcToXml.InstallLog
Restoring event log to previous state for source OpcXml.
The Rollback phase completed successfully.
The transacted install has completed.
The installation failed, and the rollback has been performed.

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

More
17 Feb 2018 15:03 #6059 by support
Thank you again. I do not know what is causing the problem, but below are some thoughts and hints.

1. The log you have sent contains two suspicious things: One is

An exception occurred in the OnAfterInstall event handler of System.ServiceProcess.ServiceInstaller.
System.ArgumentException: Attempt to add existing key into a dictionary."

The other is

An exception occurred in the OnAfterInstall event handler of System.ServiceProcess.ServiceInstaller.
OpcLabs.EasyOpc.UA.OperationModel.UAException: An OPC-UA operation failure with error code -1 (0xFFFFFFFF) occurred, originating from ''. The inner OPC-UA service exception with service result 'BadCertificateUntrusted' contains details about the problem.
The inner exception OpcLabs.EasyOpc.UA.UAServiceException was thrown with the following error message: Self Signed Certificate is not trusted.
IssuerName: CN=InstallUtil.exe, DC=[HIDDEN AS WELL] = BadCertificateUntrusted.
+ The error occurred while checking the (client) application instance certificate. The certificate generator path was "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Opc.Ua.CertificateGenerator.exe"..


Especially for the first one, it would be really useful to know the call stack (where it is coming from). Can you put try/catch block around the call to EasyUAClient.Install(), and log the call stack in case of an exception?

2. It would be also good if you can hook to EasyUAClient.LogEntry event before calling EasyUAClient.Install(), and then log all the message it generates.

3. Although what I will describe in this point is not probably causing the issue, it is a problem as well and I suggest that you resolve it. The problem has to do with naming of the generated certificate. If you do not set the name explicitly (more about it later), QuickOPC generates a name automatically, using information such as the running executable's name. The certificate name is used for lookup: When the certificate is generated, and the application is run the next time, it looks for the certificate and tries to reuse it.

In you case, using the automatically-generated certificate name will lead to problems. I can see that although your application's name is OpcToXml.exe, the name of the certificate generated by EasyUAClient.Install() is "InstallUtil.exe" - because that's what the running program at that time is, and "OpcToXml.exe" is just hosted by it. But when you will later run the actual OpcToXml.exe, it will look for "OpcToXml.exe" certificate (or possibly other auto-generated name - but not InstallUtil.exe".

In order to prevent this from happening, set the certificate (application) name explicitly in *both* the installation part, and the normal execution part, *before* calling EasyUAClient.Install() or any other of its methods. The process is described here: opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...%20Instance%20Certificate.html . An example in C# for that looks like this:
// This example demonstrates how to set the application name for the client certificate.
 
using System;
using OpcLabs.BaseLib.Instrumentation;
using OpcLabs.EasyOpc.UA;
 
namespace UADocExamples._UAApplicationParameters
{
    class ApplicationName
    {
        public static void Main1()
        {
            // Hook static events
            EasyUAClient.LogEntry += EasyUAClientOnLogEntry;
 
            try
            {
                // Set the application name, which determins the subject of the client certificate.
                // Note that this only works once in each host process.
                EasyUAClient.SharedParameters.EngineParameters.ApplicationParameters.ApplicationName = 
                    "QuickOPC - CSharp example application";
 
                // Do something - invoke an OPC read, to trigger some loggable entries.
                var client = new EasyUAClient();
                client.ReadValue("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10853");
 
                // The certificate will be located or created in a directory similar to:
                // C:\Users\All Users\OPC Foundation\CertificateStores\UA Applications\certs\
                // and its subject will be as given by the application name.
 
                Console.WriteLine("Processing log entry events for 10 seconds...");
                System.Threading.Thread.Sleep(10 * 1000);
 
                Console.WriteLine("Done.");
            }
            finally
            {
                // Unhook static events
                EasyUAClient.LogEntry -= EasyUAClientOnLogEntry;
            }
        }
 
        // Event handler for the LogEntry event.
        // Print the loggable entry containing client certificate parameters.
        private static void EasyUAClientOnLogEntry(object sender, LogEntryEventArgs logEntryEventArgs)
        {
            if (logEntryEventArgs.EventId == 161)
                Console.WriteLine(logEntryEventArgs);
        }
    }
}

Best regards

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

More
16 Feb 2018 15:26 #6055 by giles
1) Which QuickOPC version/build are you using?

It's the nuget package version 5.52.75

2) The certificate needs to be installed into the trusted store. Does your customer run the installer under administrator account, *and* with elevated privileges? (the behavior of Windows depends on UAC settings in this respect; your computer may be set differently than customer's).

They are 'running as administrator" - i assume this must mean they are an administrator...

On my PC the certificate ends up in c:\program data\OPC Foundation\CertificateStores\UA Applications\certs - i'll check what they have in there..

3) Is the installer in an executabel separate from the actual application, or are they "in one"?

They are installing the exe I have produced using installutil (in .net 4.5) folder
with...

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe OpcToXml.exe


4) Do you set the ApplicationName parameter in EasyUAClient shared parameters either in the installer project, or in the actual app?

No

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

More
16 Feb 2018 15:15 #6054 by support
Hello,
I do not know yet what can be causing it, but have some questtions:

1) Which QuickOPC version/build are you using?

2) The certificate needs to be installed into the trusted store. Does your customer run the installer under administrator account, *and* with elevated privileges? (the behavior of Windows depends on UAC settings in this respect; your computer may be set differently than customer's).

3) Is the installer in an executabel separate from the actual application, or are they "in one"?

4) Do you set the ApplicationName parameter in EasyUAClient shared parameters either in the installer project, or in the actual app?

Thank you
The following user(s) said Thank You: giles

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

More
16 Feb 2018 14:20 - 16 Feb 2018 15:15 #6053 by giles
Hi my client is trying to run the service installer I have written (which works in my system

this is what he gets in his event log (he has tried from two different directories) + [HIDDEN] and [HIDDEN AS WELL] is text i have replaced for anonimity

````

Installing assembly 'C:\XML Download\02 - Application Directory\OpcToXml.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\XML Download\02 - Application Directory\OpcToXml.exe
logfile = C:\XML Download\02 - Application Directory\OpcToXml.InstallLog
Installing service OpcXml...
Creating EventLog source OpcXml in log Application...
An exception occurred in the OnAfterInstall event handler of System.ServiceProcess.ServiceInstaller.
System.ArgumentException: An item with the same key has already been added.
Rolling back assembly 'C:\XML Download\02 - Application Directory\OpcToXml.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\XML Download\02 - Application Directory\OpcToXml.exe
logfile = C:\XML Download\02 - Application Directory\OpcToXml.InstallLog
Restoring event log to previous state for source OpcXml.
Installing assembly 'C:\XML Download\02 - Application Directory\OpcToXml.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\XML Download\02 - Application Directory\OpcToXml.exe
logfile = C:\XML Download\02 - Application Directory\OpcToXml.InstallLog
Installing service OpcXml...
Creating EventLog source OpcXml in log Application...
An exception occurred in the OnAfterInstall event handler of System.ServiceProcess.ServiceInstaller.
System.ArgumentException: Attempt to add existing key into a dictionary.
Rolling back assembly 'C:\XML Download\02 - Application Directory\OpcToXml.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\XML Download\02 - Application Directory\OpcToXml.exe
logfile = C:\XML Download\02 - Application Directory\OpcToXml.InstallLog
Restoring event log to previous state for source OpcXml.
Installing assembly 'C:\XML Download\[HIDDEN]\OpcToXml.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\XML Download\[HIDDEN]\OpcToXml.exe
logfile = C:\XML Download\[HIDDEN]\OpcToXml.InstallLog
Installing service OpcXml...
Creating EventLog source OpcXml in log Application...
An exception occurred in the OnAfterInstall event handler of System.ServiceProcess.ServiceInstaller.
System.ArgumentException: Attempt to add existing key into a dictionary.
Rolling back assembly 'C:\XML Download\[HIDDEN]\OpcToXml.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\XML Download\[HIDDEN]\OpcToXml.exe
logfile = C:\XML Download\[HIDDEN]\OpcToXml.InstallLog
Restoring event log to previous state for source OpcXml.
Installing assembly 'C:\XML Download\[HIDDEN]\OpcToXml.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\XML Download\[HIDDEN]\OpcToXml.exe
logfile = C:\XML Download\[HIDDEN]\OpcToXml.InstallLog
Installing service OpcXml...
Creating EventLog source OpcXml in log Application...
An exception occurred in the OnAfterInstall event handler of System.ServiceProcess.ServiceInstaller.
OpcLabs.EasyOpc.UA.OperationModel.UAException: An OPC-UA operation failure with error code -1 (0xFFFFFFFF) occurred, originating from ''. The inner OPC-UA service exception with service result 'BadCertificateUntrusted' contains details about the problem.
The inner exception OpcLabs.EasyOpc.UA.UAServiceException was thrown with the following error message: Self Signed Certificate is not trusted.
IssuerName: CN=InstallUtil.exe, DC=[HIDDEN AS WELL] = BadCertificateUntrusted.
+ The error occurred while checking the (client) application instance certificate. The certificate generator path was "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Opc.Ua.CertificateGenerator.exe"..
Rolling back assembly 'C:\XML Download\[HIDDEN]\OpcToXml.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\XML Download\[HIDDEN]\OpcToXml.exe
logfile = C:\XML Download\[HIDDEN]\OpcToXml.InstallLog
Restoring event log to previous state for source OpcXml.

````


my service installer just has:
````
using OpcLabs.EasyOpc.UA;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Threading.Tasks;
 
namespace OpcToXml
{
    [RunInstaller(true)]
    public partial class ProjectInstaller : System.Configuration.Install.Installer
    {
        public ProjectInstaller()
        {
            InitializeComponent();
 
        }
 
        private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
        {
            EasyUAClient.Install();
 
        }
    }
}
 
````
Last edit: 16 Feb 2018 15:15 by support.

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

Moderators: support
Time to create page: 0.090 seconds