Access HTTPS Url Without Root Certificate

Made a short project that I put into a zip folder and emailed you named DnsErrorTest.zip. I reliably get the error above in the results of test 1 when running it with TinyCLR and do not get any error when running it through my desktop like in test 2.

I haven’t received any email yet. Which email address did you send it to?

Please send to this: dat.tran@gh…

While you’re sending me the project, could you also add this code, run it on your side, and let me know the results?

NetworkController_NetworkAddressChanged is the event that is raised when the device successfully connects to the network. Your project should already have this event, or something similar.

private static void NetworkController_NetworkAddressChanged(NetworkController sender, NetworkAddressChangedEventArgs e)
{
    var ipProperties = sender.GetIPProperties();

    var address = ipProperties.Address.GetAddressBytes();
    var subnet = ipProperties.SubnetMask.GetAddressBytes();
    var gw = ipProperties.GatewayAddress.GetAddressBytes();

    var interfaceProperties = sender.GetInterfaceProperties();

    Console.WriteLine("Mac: " + interfaceProperties.MacAddress[0].ToString("x") + ":" + interfaceProperties.MacAddress[1].ToString("x") + ":" + interfaceProperties.MacAddress[2].ToString("x") + ":" + interfaceProperties.MacAddress[3].ToString("x") + ":" + interfaceProperties.MacAddress[4].ToString("x") + ":" + interfaceProperties.MacAddress[5].ToString("x"));

    Console.WriteLine("ip address :" + address[0] + "." + address[1] + "." + address[2] + "." + address[3]);
    Console.WriteLine("subnetmask :" + subnet[0] + "." + subnet[1] + "." + subnet[2] + "." + subnet[3]);
    Console.WriteLine("gate way :" + gw[0] + "." + gw[1] + "." + gw[2] + "." + gw[3]);

    var dnsCount = ipProperties.DnsAddresses.Length;

    for (int i = 0; i < dnsCount; i++)
    {
        var dns = ipProperties.DnsAddresses[i].GetAddressBytes();

        Console.WriteLine("dns[" + i + "] :" + dns[0] + "." + dns[1] + "." + dns[2] + "." + dns[3]);
    }
}

It would also be helpful if you could confirm that the minimal project works or not on TinyCLR 2.x.

Please test only the minimal project, not your full application. The full project is too large to narrow the issue down effectively, and TinyCLR 2.x does not support HTTPS without a root CA certificate anyway.

@Dat_Tran I sent it both to dat.tran@gh… as well as gus.issa@gh… I will note that the email address you posted in the comment only says posted only says “dat.tran@gh…” so I can’t be sure if your domain is different from what I sent, but it matches Gus’s domain, who reached out to me recently so I assume that it is correct.

I already have a “NetworkLinkReady” event that is invoked when an ethernet connection is established. It looks like this:

       ///<summary> Internally invoked when an ethernet connection is established. </summary>
        private static void NetworkLinkReady(NetworkController sender, NetworkAddressChangedEventArgs e)
        {
            //Verify the class has been initialized
            if (!IsInitialized)
            {
                Console.WriteLine("Controller has not been initialized.");
                return;
            }

            byte[] ipBytes = sender.GetIPProperties().Address.GetAddressBytes();

            if (ipBytes[0] == 169 && ipBytes[1] == 254)
            {
                Thread.Sleep(5000);
                DisconnectEthernetNetwork(true);
            }

            //Check that the IP address is valid and the method has not already been invoked
            else if (!LinkReady && ipBytes[0] != 0)
            {
                //Pull the IP address and save it to the system
                _ipAddress = PadIpv4Address(ipBytes[0] + "." + ipBytes[1] + "." + ipBytes[2] + "." + ipBytes[3]);

                //Pull the subnet mask and save it to the system
                byte[] subnetBytes = sender.GetIPProperties().SubnetMask.GetAddressBytes();
                _subnetMask = PadIpv4Address(subnetBytes[0] + "." + subnetBytes[1] + "." + subnetBytes[2] + "." +
                                             subnetBytes[3]);

                //Pull the gateway and save it to the system
                byte[] gatewayBytes = sender.GetIPProperties().GatewayAddress.GetAddressBytes();
                _gatewayAddress = PadIpv4Address(gatewayBytes[0] + "." + gatewayBytes[1] + "." + gatewayBytes[2] + "." +
                                                 gatewayBytes[3]);

                //Pull the DNS address and save it to the system
                byte[] dnsBytes = sender.GetIPProperties().DnsAddresses[0].GetAddressBytes();
                _dnsAddress = PadIpv4Address(dnsBytes[0] + "." + dnsBytes[1] + "." + dnsBytes[2] + "." + dnsBytes[3]);

                //Start the network health thread
                Console.WriteLine("Starting new health reset timer...");
                _networkHealthResetCounter = 0;

                //Reset the health timer
                _networkHealthCheckTimer?.Dispose();
                _networkHealthCheckTimer = null;
                _networkHealthCheckTimer = new Timer(NetworkHealthResetTask, null, 0, 60000);

                //Invoke the network ready lambda event
                Console.WriteLine($"Ethernet connected (IP: {_ipAddress}).");
                LinkReady = true;
                IsEthernetCableConnected = true;
                NetworkValidated = false;
                OnEthernetNetworkReady.Invoke(_dhcpEnableFlag, _ddnsEnableFlag, _ipAddress, _subnetMask, _gatewayAddress, _dnsAddress);
            }
        }

Will do, give me a bit to remake the project with the correct version of the dlls and run some tests. I will likely be pulled away by some work shortly though so it may be a few hours.

Do I need to revert the TinyCLR extension on visual studio or is it backwards compatible?

It would be better to uninstall TinyCLR 3.0 and install TinyCLR 2.x for the test if you want test on 2.x.

The email is correct, but neither Gus nor I have received your email. It’s possible that the email was blocked because your ZIP file included the output files (such as .exe files in the bin or obj folders).

Please delete the bin and obj folders, create the ZIP file again, and resend it.

Alternatively, you can upload the project to Google Drive and send me the link.

Just resent the email with a new zip file without the bin or obj folders. I’ll go the google drive route if you still don’t see it shortly.

Still have not seen it.

Also, a ZIP file for a clean project shouldn’t be 13 MB (as screenshot).

The generated build files (bin and obj, package folders) should not be included in the ZIP file.

You might also receive a notification if your email wasn’t delivered successfully.

Just private messaged you a google drive link since the email route seems to not be working.

I see it and am looking into it.

The code does work on TinyCLR 2.x, no error.

Thanks, that is useful information for us.

Seem we are seeing issue. Please help us to verify

in your test project, file EthernetController.cs , change line 399:

// was:  _interfaceSettings.DnsAddresses = new IPAddress[] { new IPAddress(newDns) };
_interfaceSettings.DnsAddresses = _ddnsEnableFlag ? null : new IPAddress[] { new IPAddress(newDns) };

Let use know the result after that.

Try on 3.0 of course. Make sure firmware, library and extension all are 3.0.

After making the change I still get an error:

#### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (4) ####
#### Message: 
#### GHIElectronics.TinyCLR.Devices.Network.Provider.NetworkControllerApiWrapper::GetHostByName [IP: 0000] ####
#### System.Net.Dns::GetHostEntry [IP: 0024] ####
#### GHI_Framework.EthernetController::DoTestDnsTemp [IP: 0008] ####
#### DnsTest.MainThread::EthernetIsReady [IP: 0004] ####
#### GHI_Framework.EthernetController::NetworkLinkReady [IP: 0227] ####
#### GHIElectronics.TinyCLR.Devices.Network.NetworkController::OnNetworkAddressChanged [IP: 000e] ####
#### GHIElectronics.TinyCLR.Devices.Network.Provider.NetworkControllerApiWrapper::<.ctor>b__8_1 [IP: 001f] ####
Exception thrown: ‘System.InvalidOperationException’ in GHIElectronics.TinyCLR.Devices.Network.dll
DNS threw (expected): Exception was thrown: System.InvalidOperationException

Hi, I sent you a message that need your help on one more test. Just change c# code and run it again then give me result.

Thankjs

Since you’ve identified that the issue is related to your office network, should we close this issue, or would you like us to investigate anything further?

I believe that we can close this issue, my apologies about the networking issues, I am not a part of my company’s IT department and was unaware of the changes they were making to our local network at the time.

We wish we know what they changed, but if you can’t reproduce the issue and we can’t reproduce it either, it’s difficult to investigate any further.

We’re glad to hear it’s working for you now