"MissingApplicationCertificate" Event is not being raised

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
gaurav139690
Jr. Member
Jr. Member
Posts: 3
Joined: 16 Aug 2022, 14:53

"MissingApplicationCertificate" Event is not being raised

Post by gaurav139690 »

Hi Team,

In my custom C# console App (.Net Framework) (using the evaluation license), the MissingApplicationCertificate event is not being raised.
I have used License and App.Config files from GettingStarted sample project. I have also copied the Opc.Ua.CertificateGenerator.exe into the application output directory .i.e. next to the application exe.

The App.config file mentions below:

Code: Select all

 
      <!-- Specify location of Certificates and Trust Lists -->
      <ApplicationCertificate>
        <StoreType>Directory</StoreType>
        <StorePath>%CommonApplicationData%\unifiedautomation\UaSdkNetBundleEval\pkiclient\own</StorePath>
        <!--
        <StoreType>Windows</StoreType>
        <StorePath>LocalMachine\My</StorePath>
        -->
When I delete all available certificates from %CommonApplicationData%\unifiedautomation\UaSdkNetBundleEval\pkiclient\ location, I can see the MissingApplicationCertificate event being raised in the GettingStarted sample project . But when I do the same in my custom App, It does not raise it. I am testing in debug mode with breakpoints shown below. PLEASE HELP.

Below is my code:

Code: Select all

namespace OPCUAExplorer
{
    static class Program
    {
        static void Main(string[] args)
        {
            try
            {
                
                ApplicationLicenseManager.AddProcessLicenses(System.Reflection.Assembly.GetExecutingAssembly(), "License.lic");
                //Create the certificate if it does not exist yet
                ApplicationInstance.Default.AutoCreateCertificate = true;
                
                //Breakpoint #1
		ApplicationInstance.Default.MissingApplicationCertificate +=
                    new CreateCertificateEventHandler(Application_MissingApplicationCertificate);
               

                //SERVER AND ENDPOINT DISCOVERY[WORKS]
                //========================================
                List<ApplicationDescription> servers;
                List<EndpointDescription> endpoints;
                // create the object used to find servers or endpoints.
                using (Discovery discovery = new Discovery())
                {
                    // look for the LDS with the default endpoint.
                    //string discoveryUrlServer = "opc.tcp://" + "localhost" + ":4840"; 
                    //servers = discovery.FindServers(discoveryUrlServer);

                    // get the discoverUrl from the gui
                    string discoveryUrlEndPoints = "opc.tcp://localhost:48030"; //UADemoServer
                                                                             
                     // look for the LDS with the default endpoint.
                    endpoints = discovery.GetEndpoints(discoveryUrlEndPoints);
                }



            }
            catch (Exception e)
            {
                Console.Write(e.Message);
                return;
            }
        }

        static void Application_MissingApplicationCertificate(object sender, CreateCertificateEventArgs e)
        {
            try
            {
                // let the application create a suitablable default if no user interaction allowed.
                if (e.Silent)
                {
                    return;
                }
            //Breakpoint #2
                Console.Write("Missing Certificate");

            }
            catch (Exception exception)
            {
                Console.Write(exception.Message);
            }
        }
    
    }
}

User avatar
Support Team
Hero Member
Hero Member
Posts: 3064
Joined: 18 Mar 2011, 15:09

Re: "MissingApplicationCertificate" Event is not being raised

Post by Support Team »

Hello,

You need to pass the ApplicationInstance.Default to the constructor of Discovery. In this the correct application instance is started (ApplicationInstance.Default instead of ApplicationInstanceBase.Default).
Best regards
Unified Automation Support Team

Post Reply