I have a legacy project that I have inherited. It was an absolute utter and complete mess. Within version control, every single file was revision 1. Long story short it was completely broken and did not come close to compiling. dll refresh files were pointed to files outside of version control, and the dll's that were versioned were the WRONG ones. Hours and hours lost just getting this to build in VS2008.
At any rate, according to the project details the project targets framework 3.5. However, an 401.2 authorization error I get in my browser when debugging the project says that framework 2.0.* was being used.
Has anyone had seen this before, or know of a remedy?
The 3.5 version of the framework is just some additional features (such as Linq) integrated into v2.0 of the CLR. So, even if your project shows a target of 3.5, it is still running on version 2.0 of the CLR.
See http://en.wikipedia.org/wiki/.NET_Framework_version_history#.NET_Framework_3.5
Check IIS to see which version of the framework the worker process is using. Also check any class files you may also be compiling to make sure that they are using the same framework version.
Related
I am trying to update a large solution to .NET Framework 4.7.2 with VS2019. One of the problems with this solution is that it is a large plugin type architecture, where (for many reasons) I am not able to recompile and release the plugins to production with the updated shared set of libraries that the solution provides.
Normally this is OK, but we have to be very careful to ensure full backwards binary compatibility. When we recently upgraded to .NET 4.7.2, we started getting conflicting usage indicators between System.Linq and MoreLinq, generally on the .ToHashSet() extension that we commonly use. The problem is outlined somewhat on MoreLinq's github
I think the only way to correct this is to isolate MoreLINQs usage into a single DLL that I control, and once all plugins reference that DLL upgrade to 4.7.2, fixing the .ToHashSet() call in the common location at that time.
Does anyone know of a better/more efficient way to do this, without re-releasing all the plugins at once? Some kind of global redirect that I am not aware of?
Evidently this just works. Installing the solutions common DLLs # 4.7.2 alongside older plugins # 4.5.2 worked fine, even though those plugins had compilation errors when compiling in Visual Studio against 4.7.2.
I'd be curious to know what internals are making this succeed. Does the system load multiple versions of .NET framework DLLs for the running process?
I'm working on a project, to which I would like to add Prometheus metrics exporting. There's a pretty great library for it over at NuGet that I've used. The new version (2.0.x, prerelease), however, is supposedly build for .NET Standard. That's fine, but my current project is built for the .NET Framework on Windows. When I add this NuGet package, however, I get over 100 assemblies added to the output of my project, including many that I don't think are related.
I added an issue for this to the project, but the project maintainer came to the conclusion that this is normal. I don't agree, however, and I'd like to know if there is a specific suggestion I can make to improve the situation.
What should prometheus-net change to avoid adding all these assemblies to the output of my project?
This is a flaw/bug/unfortunate side effect of the current .NET Standard 2.0 build situation. When a .NET Framework before 4.7.1 is targeted, the system cannot be sure that all the dependencies exist, so it copies all of these extra assemblies to the output.
4.7.1 has everything that .NET Standard 2.0 needs, so they will not be included if that framework is targeted (though, things might break if an earlier framework is used at runtime).
There is information (and a workaround that seems to work for me) at https://github.com/dotnet/standard/issues/415#issuecomment-314288712
I have several projects in a large solution that won't convert to V4.5.1 (or even V4.5). Most did, but obviously I need to get all of them converted. The GUI in Visual Studio says that it did it and reloads the project, but if you go back into the properties it still says V4 and it won't compile because of dependencies that converted properly and are V4.5.1
I tried manually updating the .csproj files and it says 4.5.1 as the target framework, and I even updated the app.config/web.config to point to the right version, however Visual Studio's property page still says .NET 4 and is throwing compile errors because it can't access the ones that successfully updated to 4.5.1
What am I missing in the process to get these updated? I've tried VS.net 2012 and 2013 and both do the same thing.
In hopes that this helps others:
In our case, the issue was that we were referencing a custom targets file that was created for the entire solution. even though the project was getting updated, the custom targets file was overriding it thus preventing the project from getting updated.
Updated the targets file to point to .net 4.5 and everything was fine.
For me, the solution was to remove all the extraneous <PropertyGroup> sections from the .csproject file - except the first one.
VS 2015 was setting the <TargetFramework> to 4.5.1 on only one of them (not the first one).
After two days of suffering, I have created a new project, targeted .NET 4.5 and then manually copied all files from the existing project. Made sure new project compiles. Removed old project. Moved new project into the directory of the old project so that I can reverse merge into trunk. Job done.
Project I was upgrading was an old WPF project with thousands (no kidding) XAML files in a single project. It also had a release preview of MvvmLight (years old) and an older version of Prism along with a range of other libraries. All and all the project is a mess and somebody must have done something really stupid to make targeting .NET 4.5 this difficult.
I had a similar issue. Turns out the DLLs were built for target framework 4.5.1, but the project I was working in was built for 4.5 only. There were some suppressed warning messages when I compiled. When I showed compile warnings, that was the hint that told me what was going on.
I recompiled the DLLs for framework 4.5, and then the DLLs copied automatically without needing additional references to the assemblies.
In my case I was working with projects designed for SharePoint 2010. Apparently the project template restricts the .NET target framework version which can be selected.
As I was trying to compile a SharePoint 2016 server, once I got the beta templates downloaded for 2016, Visual Studio automatically prompted me to upgrade these projects when trying to open the solution again. Hope this helps someone.
Preview bits for SharePoint 2016 are available here: https://www.microsoft.com/en-us/download/details.aspx?id=49972
I have VS2010 and VS2012 installed on my computer and had the .NET Framework 4.0 which I then upgraded to .NET Framework 4.5. However, I am still developing apps that need to work on .NET Framework 4.0. The project says that it is targeting .NET Framework 4 (Client Profile) the assemblies even point to .NET Framework 4.0 folder under Referenced Assemblies. The problem comes when I move this application to a machine that only has 4.0 it won't start and come up with errors the immediate problem being an exception resulting from WindowState={Binding WindowState} which you can't do in 4.0 but you can in 4.5. I need this to throw the exception on my development box, why doesn't it? My assumption is that despite my best efforts is that it uses the 4.5 dlls if they exist. How can I make it really use 4.0 without uninstall 4.5?
Update
To repro this install .NET Framework 4.5 and create a WPF project targeting .NET Framework 4.0. Bind the WindowState to a property in a VM or code behind make this property have a public get and private set. .NET Framework 4.5 handles this just fine even when Mode=TwoWay must ignore the set .NET Framework 4 doesn't and throws an exception: "A TwoWay or OneWayToSource binding cannot work on the read-only property 'State' of type...". On the box with .NET Framework 4.5 works like a charm try it on a machine with only .NET Framework 4.0 and it blows up... So any ideas on how to really target 4.0 when 4.5 is installed?
Bug report to MS here: https://connect.microsoft.com/VisualStudio/feedback/details/774694/targeting-net-framework-4-0-when-4-5-doesnt-seem-to-work
Time to punt this question. I'm no expert on WPF, don't like it much for exactly these kind of problems, debugging dependency property problems is a nightmare. But I'm pretty convinced you are chasing a ghost. WindowState has been a dependency property all the way back to 3.0, nothing special happened to it in 4.5 that I can see or ever heard of.
You got some kind of error message that nobody can see that convinced you that it had something to do with the binding. I'm from Missouri, the Show Me State. Well, close enough to Wisconsin.
Spend more time working on code that gives you a reliable exception message and stack trace that helps you diagnose errors on the machine you deploy to, the one without a debugger to help you figure out what's going wrong. You do so by writing an event handler for the AppDomain.CurrentDomain.UnhandledException event. Log or display the e.ExceptionObject.ToString() return value. It gives you the exception message and the Holy Stack Trace. If that doesn't help then update your question with what you saw.
This appears to be a bug in .NET Framework 4.5 and it should throw the exception but with .NET Framework 4.5 installed there is no way to have your application run on .NET framework 4.0 it will always use 4.5.
See this reported bug for more info:
http://connect.microsoft.com/VisualStudio/feedback/details/773682/wpf-property-with-private-setter-is-updated-by-a-twoway-binding
You said you can't reproduce this in a test project. So that implies that it may be something that should work fine in 4.0 right? You might have some combination of code that is crashing on a bug in 4.0, that was fixed in 4.5. When you target 4.0, you will only get warnings when you try to use API's/features that the compiler can determine are not supported in 4.0.
Something that should work in 4.0 may crashed due to some rarely seen bug, and then fixed in 4.5. When your 4.0 targeted app runs under 4.5 environment, it will be affected by bug fixes to features that existed in 4.0.
There may be an update for 4.0 that includes the bug fix, so as not to require 4.5 upgrade if users are adverse to that for some reason. So it might not even be a 4.5 change, but simply a coincidence that some users don't have all of the updates available for 4.0(which would have been cumulatively includes in your 4.5).
These kind of cases I've rarely encountered, but do happen sometimes and are the reason people who support desktop .NET applications are notorious for asking users to update there .NET framework as a first try at solving odd issues before spending time troubleshooting.
Sometimes the opposite occurs. Your code only works due to some bug or poor behavior of a .NET API, and later an update cleans this up, perhaps tightening security somewhere is the most often thing I've seen, and your code suddenly breaks due to a minor version update of .NET.
.Net 4.5 replaces .net 4.0 with new, same-named libraries, that actually have some fixes.
That's short answer.
Unlike earlier versions, updating .net 4 to 4.5 replaces files, instead of adding sided by side files.
Even if you have folder like this Windows/Microsoft.Net/Framework/v40/ ,
After update, there is a change in this folder.
Files are changed, some errors were handled in .net without developer's concern.
How to target 4.0 framework using .net 4.5 ?
I still don't know, but I'm still digging
Suggested read on this topic:
Scott Hanselman :
http://www.hanselman.com/blog/NETVersioningAndMultiTargetingNET45IsAnInplaceUpgradeToNET40.aspx
Rick Strahl:
http://weblog.west-wind.com/posts/2012/Mar/13/NET-45-is-an-inplace-replacement-for-NET-40
And similar problem, created by me:
https://stackoverflow.com/questions/26483168/errors-on-net-4-0-dont-appear-on-net-4-5
The solution:
I've got the same problem when installed VS2017 after VS2015: Framework 4.0 just disappeared from project target list.
Following some comments around here I've tried with NuGet package: Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.4 and bin fix for 1.0.1.
Don't do that! My build time went ~300% up for the same project. It was disaster.
I see that 4.5 is an "in place replacement" for 4.0 However this does not explain why I cant see both options in my target frameworks combo.
I was reading the same mantra all around the web. It's simply not answer to the problem. Framework 4.0 is a must for any industrial machinery related software - because it runs on Windows XP, while .NET 4.5. is useless in my scenario, and probably for many other real-life stuff.
The solution is simple:
You just have to download and install Visual Studio 2013 Express from official web page:
https://www.microsoft.com/en-us/download/details.aspx?id=44914
After installing it, just open your VS2015 and you'll see 4.0 again.
...
"In place replacement ..." my....
This is re-post of answer I gave on a duplicate question. I'm posting here since this thread got more attention and existing answers here give no solution for the issue.
I can't seem to get my application up and running on my dev server and I'm not sure why.
I have compiled my code in VS 2008 with a target framework of 3.5. I am using 3.5 mainly because I have implemented LINQ rather extensively. Compiling and runs local without any problems.
The hang up is that my server only has the 2.0 .Net framework and upgrading to 3.5 is apparently not going to happen.
I was under the impression after doing some research that as long as I was trying to execute compiled code the server would not need 3.5 installed.
Today I am trying to publish to the server and I can't get past this error in my WEB.CONFIG
Configuration Error
Parser Error Message: Child nodes not allowed.
providerOption name="CompilerVersion" value="v3.5"/
EDIT ADD ON QUESTION:
I have seen some posts about possibly setting my references to "copy local" which might allow me to run on the 2.0 server. Thoughts?
You are right in that 3.5 runs on the 2.0 CLR, but 3.5 contains libraries and if you have used any of those, you're out of luck unless you install 3.5 on that server.
There are plenty of options for a 3.5 program to not run correctly on only 2.0, so I'd consider downgrading the program, or upgrading the server.
Note regarding copy local. Even if you copy all the 3.5 libraries that your app uses, there is no guarantee it'll work and most likely it won't. Even so, distributing the libraries with your app is expressively prohibited by the .NET license.
Since you have stated you use LINQ, the only legal way to get your app running is to install the 3.5 license.
Or, you can rewrite your app using only 2.0.
I'm pretty sure that LINQ is one of the things that makes 3.5 a requirement. A lot of the other things, like lambda expressions etc. are just compiler trickery.
Because System.Linq is a 3.5 feature, the framework is required to be that version.
A good way to determine would be to change the target framework to 2.0 and see if it builds.
Code compiled against 3.0 or 3.5 may run on the 2.0 framework, but only if you do not use any libraries that are specific to the 3.0+ framework. One good way to find what's causing your code to fail is to switch your target to 2.0 and change things so that it compiles. Since one of your target installations is .NET 2.0, you are going to have to write .NET 2.0 code; this is not unique to .NET. In the past, writing an application that executed in both Win95 and WinNT involved extra work for the developer to carefully make sure the appropriate API was used.
Technically, 3.5-targetted code can run on 2.0 with no problems, but there's some gotchas you have to watch for. If anything accesses something that is unavailable in .NET 2.0, that will fail. This doesn't happen when the application starts, it happens when the application tries to make the call. I tested this by making a console application that does a little bit of output, then tries to display a WPF window. The output is made, but the application throws an exception when it tries to display the window on a machine with nothing but .NET 2.0.
Another gotcha is that VS 2008 actually comes with the .NET Framework 2.0 SP1, and there are a few types and methods in SP1 that are not in the normal 2.0 Framework. Visual Studio will not flag these methods as unsafe.
Finally, if this is a web application, the default web.config file for 3.5-targeted projects is very different than the web.config file for 2.0-targeted projects. Make sure you're distributing a compatible web.config. This is likely the problem you are encountering. A cheap workaround might be to change your target to .NET 2.0, copy that web.config, and use it in this case. Keep in mind that if you are using any 3.0+-specific language features or types your code will still fail, but this should get you past the web.config.
You're not going to be able to run code targetted to 3.5 on the server unless you get 3.5 installed on it.
The problem isn't your code, rather that the required libraries will be missing.
This is not possible. Although the CLR has not changed (like it did between v1.1 and v2.0) The libraries have. You cannot run a 3.5 app that doesn't have the 3.5 fraework installed. All of the Linq features are made possible by the 3.5 framework.
One error is in Web.Config. The published Web.Config is setup to allow compilation from .NET 3.5, which is the reason it includes build provider information.
Beyond that, your code won't run. By using LINQ, you're referencing assemblies that don't exist in .NET 2.0.
I was just going to leave a comment by my rep is not quite there. I agree with the crowd so far and believe that lassevk's answer is the best so please give him the rep for that. One this I wanted you to know about though is that once you install 3.5 on your IIS server (6 or better). When you go to the IIS Manager and right click on your website to access the ASP.Net tab. You will see AFTER the install of the 3.5 Framework that there is no 3.5 option available. It will still show it as 2.0.50727. Don't worry about that, it will still work just fine. Because of this inconsistence (thanks Microsoft) some confusion has been caused. Actually I think this is why you may have thought that 2.0 would run your 3.5 code just fine. Hope this helps and anyone please edit this so it makes more sense.
You can may use of some C# 3 features whilst targeting .NET 2.0. Its the language features which by the time its compilied to IL will run on the 2.0 CLR regardless of whether that CLR is part of a 2.0 or higher framework install.
Hence you can use anonymous types, extension methods and Lambda expressions but as soon as you do things like LINQ you then need external libraries that are part of 3.5
If you are only doing LINQ to Object you could add the LINQBridge to your distribution.
Another problem you can run into is if you are shipping a web application that includes the source code, such as code behind files, in line code and .cs in the App_Code folder.
You can end up shipping C# source code which compiles on the developement machine with C# 3 compilier present but fails to compile on a server only equiped with C# 2. In this case you can't use any new language features either.
What's worse is that specifing the .NET 2.0 framework as the target in the Visual Studio doesn't stop you using C# 3 language features. You get no warnings that such syntax will not compile on a 2.0 machine.
Hence if you are shipping such a web app, you'll need to compile pretty much everything first.
You can just copy over the 3.5 dlls onto the server. You can absolutely run 3.5 code on a 2.0 server.