Reputation: 859
I have an app which targets .NET Framework 4.6
When I run it on a machine with only .NET 4.5 installed, it starts, and most of it works... I just get a couple of really odd an unhelpful runtime errors, such as
"Method not found: '!!0[] System.Array.Empty()'"
(amongst others) which don't go very far to reminding me that the problem is the .NET runtime.
I could put a call into the method which doesn't work under .NET 4.5 in start up, catch the error, and rethrow a helpful error message. In some ways this would be the most specific - just check the functions I need to use, and if the next version of .NET has a weird out of order version number, testing $expectedversion <= $actualversion will break whereas checking the functions work will be fine.
It just FEELS really ugly and messy. I don't expect my programs's startup routine to have to do this sort of stuff. It's also really hard to test, because all my machines have .NET 4.6 on them.
I could check the registry - except for the fact that registry access is one of the things which seems to have changed between 4.5 and 4.6, and my code which checks registry settings also throws unhelpful exceptions. And the registry checking stuff I've seen works well with known .NET versions but has very specific version numbers and isn't going to tell me much about unknown .NET versions that don't exist yet.
So - what is the best method of checking that the runtime environment matches the version of .NET that I've compiled against?
Upvotes: 1
Views: 971
Reputation: 180917
You can use a <supportedRuntime>
tag in your app.config, which will allow the runtime to give better information.
An example configuration would be;
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
</configuration>
Upvotes: 5