.Net targeting framework 4.5 only sees 4.0 references? - c#

I have a project in .Net 4.5, however when I try to add a framework reference all that is available to me are 4.0 options. Why is this happening and what can I do to get the 4.5 references options?
Thank you in advance.

That's another direct result of .NET 4.5 in place upgrading .NET 4.0. Th assembly version you saw in VS should not change, while the actual file version if you check in Windows Explorer updated.
This kind of design gives maximum compatibility to applications as they can load the new assemblies just as usual. Assume Microsoft changed the number to 4.5 as you desired, such applications would throw FileNotFoundException which can be quite harmful.

Related

clr DLL built as .NET 3.5 "requires later version" when referenced from a .NET 3.5 project.

I built the dll using Visual Studio 2008 for .NET 3.5 targeted framework.
Loading it into a .NET project built in 3.5 gives the error
"OpenGLControl.dll", or one of its dependencies, requires a later version of the .NET Framework.... etc.
The dll shows a 'runtime version' of v2.0.50727.
Anyone experienced something similar? Any solutions?
According to this site: that should be acceptable for a .NET 3.5 build.
Thanks!
In the end the issue was an unversioned dependency, although not listed as a higher framework version it seems VS2008 'assumed' it to be higher. So not only must the dependencies by the same version or less, they must all have an explicit framework version.

VS 2012/2013 and .NET 4.5 Query

I am planning to install VS 2012 or 2013 and I was wondering if .NET 4.5 will get installed with it? I think it will but then what will happen to all my apps with target platform 4.0?
So my question is when I install VS, will my old apps which have target platform 4 contain elements of .NET 4.5?
Let say as example type string in 4.5 it has some improvements or something which 4.0 doesnt have. Will I get them even though I build against 4.0 according to target platform?
I would like to avoid some strange behavior in already existing projects just because I am running now visual studio 2013.
Any experience on this one guys?
Sorry in case of a duplicate question
In Visual Studio 2013 you can still build against .NET 4.0. The (highest) framework version installed on your development machine has no influence on the end result of your build process.
When installing .NET 4.5 in place of .NET 4 will change something on your PC: It gives you the ability to compile against the 4.5 version of the framework. As long as your compile your code against the NET 4.0 version, it has no need of .NET 4.5 to be installed.
If you target .NET 4.0, your code will not be able to access types which are specific to .NET 4.5 or .NET 4.5.1. However, your code will be running against .NET 4.5. That is only a problem if you do not test against .NET 4.0. In that case, you could find that bugs are fixed in .NET 4.5, but your users may still be using .NET 4.0, which may still have the bugs.

Can application built with .NET 4.5 run on .NET 4.0?

My project is targeting to .NET 4.5. It doesn't use any new 4.5 methods, so it actually works fine on the machine with only .NET 4.0 installed.
This is all good until I added some extension methods and reflection. Then when I ran this .NET 4.5 program on the 4.0 machine, it failed with "System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly mscorlib". The famous ExtensionAttribute program that has been documented well here.
Another quick way to test this is to add the following line. Then the program will throw the exception when running on .NET 4.0 only.
Console.WriteLine(typeof(System.Runtime.CompilerServices.ExtensionAttribute).Assembly.FullName);
I'm wondering if there is a way to work around it. For example, the ILMerge (when using the correct /targetplatform option as documented in the link) actually changes the ExtensionAttribute from mscorlib to System.Core if the project is target to .NET 4.0 (with 4.5 installed). But it doesn't seem to work on the project targeted to .NET 4.5.
I know this is a long shot. But just want to see if anyone has other ideas since it was so close.
Thanks.
In general, this will not work. It does work in some cases since 4.5 is an in place replacement for 4.0, but it's not going to work in general. I've, personally, seen problems with types that have moved into different assemblies, and the bindings aren't setup correctly, just like you're seeing. The reflection types aren't the only types that were moved in 4.5.
My project is targeting to .NET 4.5. It doesn't use any new 4.5 methods, so it actually works fine on the machine with only .NET 4.0 installed.
If this is the case, you could just change your application to target .NET 4.0. This should allow it to run safely on a machine with only .NET 4 installed.

easiest way to convert .NET project from 4.5 to 4.0?

I have a .NET application that I built in 4.5, which has references to a bunch of libraries that were built in 4.5, which themselves have references to 4.5, etc. A user group that I'm trying to distribute the application to is having problems running the executable because they have 4.0 installed; in particular, they're getting a MissingMethodException:
Method not found: 'System.Type System.Runtime.InteropServices.Marshal.GetTypeFromCLSID(System.Guid)'.
Because we may have trouble getting each user upgraded to 4.5 (as none of them have admin permissions on their machines and this would require a separate upgrade request for each user), I'm looking at finding an easy way to rebuild the project as 4.0. This seems to require that I rebuild every library and its referenced libraries in 4.0; is there an easier way to do this than going through each library one by one and building a 4.0 version? I'm thinking maybe like a one-click option for "Rebuild all referenced libraries in target framework" or something like that.
If you have dependencies on .Net 4.5 DLLs then you will need to also get .Net 4.0 versions of those if you want to successfully downgrade your project. A .Net project can only reference .Net DLLs up to the same version of .Net as the referencing assembly.
The easiest way to do this is to use something like NuGet to manage your dependencies. Note that when you change the target framework version of your project in VS you will need to uninstall and re-install dependencies with NuGet as NuGet does not automatically do this for you when you change the target framework version.
Of course if all the dependencies are to your own code and you aren't publishing this through a dependency management system like NuGet you will need to downgrade all your other code to .Net 4.0 as well
When I use Visual Studio, I right click on the project, change the framework, fix the References and recompile. Usually straight forward.
Please, have a look at this MSDN page to correctly switch your project to a lower target framework without problems! It is a little bit outdated for what concerns versions, but the process is the same described!
This is based on my experience. I had an application initially created in .net framework 4.5 but I wanted to convert it in .net framework 4.0. I created new project initially created 4.0 and then I did copy and paste of all the forms and controls of my previous application and it works. Framework 4.5 is using Aero2 and 4.0 is Aero... Good Luck :)

Assembly Compatibility Question

I have a basic server control that I've written using .NET 3.5. If I give that dll to someone who is running a .NET 2.0 application, will it work?
Unless you are referencing any DLL's included in .NET 3.0 or 3.5 then yes it should work because the CLR versions are the same in .NET 2.0, 3.0, and 3.5. I believe there may have been minor changes to the 2.0 assemblies ("red bits") but I'll have to double check.
You can even just change the project properties in Visual Studio to target .NET 2.0 to be sure. If your app doesn't compile then it wouldn't have run on .NET 2.0 anyway.
Scott Hanselman has posted about .NET 2.0-3.5 differences.
The first thing you should do is try changing the Target Framework to 2.0 and see if your Server Control project still compiles (Right click on the project, choose Properties, then change the Target Framework to ".NET Framework 2.0" and choose "Yes" in the "Target Framework Change" dialog). If it still compiles you're off to a fairly good start. Now compile it, add it to a new web site and check to see if it works.
Most of the time you'll probably find that your control won't be using any 3.5 specific features, so once you've tried compiling it against 3.5 you'll be good to go!

Categories