Best Way To Determine If .NET 3.5 Is Installed

13,885

Solution 1

You could try:

static bool HasNet35()
{
    try
    {
        AppDomain.CurrentDomain.Load(
            "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
        return true;
    }
    catch
    {
        return false;
    }
}

@Nick: Good question, I'll try it in a bit.

Kev

Solution 2

That is because technically .NET 3.5 is an extension of the 2.0 framework. The quickest way is to include an assembly from .NET 3.5 and see if it breaks.

System.Web.Extensions

Is a good assembly that is only included in version 3.5. Also it seems that you are using ASP.NET to run this check, this really limits you because you will be unable to check the file system or the registry running in the protected mode of ASP.NET. Or you can always problematically try loading an assembly from the GAC that should only be in .NET 3.5, however you may run in to problems with permissions again.

This may be one of those times where you ask your self "What am I trying to accomplish?" and see if there are alternative routes.

Solution 3

A good resource I found:

http://www.walkernews.net/2008/05/16/how-to-check-net-framework-version-installed/

Solution 4

@Kev, really like your solution. Thanks for the help.

Using the registry the code would look something like this:

RegistryKey key = Registry
        .LocalMachine
        .OpenSubKey("Software\\Microsoft\\NET Framework Setup\\NDP\\v3.5");
return (key != null);

I would be curious if either of these would work in a medium trust environment (although I am working in full trust so it doesn't matter to what I am currently working on).

Solution 5

Another interesting find is the presence of assemblies here:

C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5

You'd think Microsoft would build a check for "latest version" into the framework.

Share:
13,885
sestocker
Author by

sestocker

I'm Director of Solution Architecture at edynamic where I oversee teams on content management projects, primarily Sitecore.

Updated on June 04, 2022

Comments

  • sestocker
    sestocker almost 2 years

    I need to programatically determine whether .NET 3.5 is installed. I thought it would be easy:

    <% Response.Write(Environment.Version.ToString()); %>
    

    Which returns "2.0.50727.1434" so no such luck...

    In my research I have that there are some rather obscure registry keys I can look at but I'm not sure if that is the route to go. Does anyone have any suggestions?