LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

.NET library loaded in LabVIEW 2019 does not use system default TLS version

Solved!
Go to solution

We have a .NET library which is used by LabVIEW 2019 among other things. Several methods in this library makes http calls to a server. Recently the server has disabled TLS 1.0 and 1.1, so communication with the server has to use TLS 1.2.

 

The .NET library targets .NET Framework 4.6.2, which supports using system default TLS version by default (i.e. you don't have to set the registry key SystemDefaultTlsVersions to 1). On Windows 8.1 and Windows 10, TLS 1.2 is the system default, so the .NET library uses TLS 1.2 by default. Good.

 

However, that does not seem to be the case when the library is loaded through LabVIEW 2019. In order for the library to use the system default TLS version when loaded in LabVIEW, I have to set either of these registry keys to 1 (depending on the bitness of LabVIEW):

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SystemDefaultTlsVersions

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319\SystemDefaultTlsVersions

 

Does anyone have any idea why this is the case? Is there anything I could do to the .NET library where I would not have to set these keys and still use the system default TLS version?

0 Kudos
Message 1 of 19
(3,367 Views)

It's first make sure LabVIEW is using the .NET version you're expecting:

Get dotNet Version.png

 

I seem to have 4.8 installed*, but LabVIEW uses 4.0.

 

*how-quickly-check-net-framework-version-windows-10

0 Kudos
Message 2 of 19
(3,325 Views)

Thank you for taking an interest.

 

I also seem to have .NET Framework 4.8 installed. System.Environment.Version gives the CLR version (which is 4.0.30319.42000 for me) not .NET version.

 

According to this https://docs.microsoft.com/en-us/dotnet/api/system.environment.version


 For the .NET Framework 4.6 and later versions, it has the form 4.0.30319.42000


Message 3 of 19
(3,300 Views)

Interesting... 

 

According to how-to-determine-which-versions-are-installed:

 

CLR version greater than or equal to 4.0.30319.42000 supports .NET Framework versions starting with .NET Framework 4.6.

 

So, back to 0 on the reason why your code acts weirdly...

0 Kudos
Message 4 of 19
(3,296 Views)

EDIT: That posted it 2X...

0 Kudos
Message 5 of 19
(3,294 Views)

Maybe this helps... Apparently, you can set the security protocol:

https://docs.microsoft.com/en-us/dotnet/api/system.net.securityprotocoltype?view=netcore-3.1

 

Perhaps LabVIEW sets the security protocol internally?

Perhaps you can set it instead of the registry key?

If you read it, maybe it will shed some light on the issue?

 

It's not a perfect match, I don't see why the registry key would help even if LabVIEW changes the protocol. So even if it helps, it won't explain anything.

0 Kudos
Message 6 of 19
(3,290 Views)
Solution
Accepted by topic author Nesh

This one is interesting too:

https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls

 

For .NET Framework 4.6 - 4.6.2 and not WCF
Set the DontEnableSystemDefaultTlsVersions AppContext switch to false. See Configuring security via AppContext switches.

 

It seems pretty complicated to me...

0 Kudos
Message 7 of 19
(3,287 Views)

If I set the AppContext switch Switch.System.Net.DontEnableSystemDefaultTlsVersions to false before running the rest of the code it works!

 

Nesh_0-1600416290755.png

 

Thanks

Message 8 of 19
(3,279 Views)

Hi,

 

I am unable to locate this particular "appcontext" functionality (and hence the DontEnableSystemDefaultTlsVersions).

Where is this located? I am using Windows 10 (64bit) and LabVIEW 2019(32bit)

 

Guruguruthilakkamata_0-1659438280685.png

 

0 Kudos
Message 9 of 19
(2,547 Views)

@Guruguruthilak.kamata wrote:

Hi,

 

I am unable to locate this particular "appcontext" functionality (and hence the DontEnableSystemDefaultTlsVersions).

Where is this located? I am using Windows 10 (64bit) and LabVIEW 2019(32bit)

 

Guruguruthilakkamata_0-1659438280685.png

 


I don't know specifically about the TLS issue, but with .NET, sometimes you have to hunt around to find the specific class in LV. In my case, I can find the AppContext class by going to the mscorlib assembly (where you will often find these system classes) and looking under System (why not directly in the main list or in System.Runtime, which also exists in mscorlib? I have no idea. I never understood exactly how to figure out where the relevant class would show up).


___________________
Try to take over the world!
0 Kudos
Message 10 of 19
(2,537 Views)