Reference issues in .NET 4.0 project to .NET 2.0 dll/project - visual-studio-2010

I just starting to use Visual Studio 2010 and .NET 4.0. I created a new WPF project a DLL built for .NET 2.0. When I build the project, I get a bunch of warnings like this one:
The referenced assembly
"MicroFour StrataFrame Business...processorArchitecture=MSIL"
could not be resolved because it has a dependency on
"System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client".
Please remove references to assemblies not in the targeted framework
or consider retargeting your project.
When I reference a project I created that targets 3.5, it can't find any of the namespaces (during compile), though they show up in the object browser and intellisense correctly shows them.
Is there something I'm missing that needs to be done to reference an older .NET assembly?

There is very little point in targeting the client profile for .NET 4.0. The download is 41MB, the full version is 48MB, only 15% bigger. Unfortunately it is the default in VS2010, just change it with Project + Properties, Application tab, Target framework combo.
The client profile does make a lot of sense if you target 3.5, the full install is ~350 MB. The huge difference is explained by the prerequisites, .NET 4.0 requires at least XP SP3 or Vista SP1. But 3.5 installs on any version of Windows > 2000. The 3.5 installer thus contains lots of the required updates for unmanaged Windows components used by .NET. The web installer lessens that blow considerably btw.

Your 2.0 assembly has a reference to System.Web. The reference is being automatically forwarded to your target framework, 4.0. So it is attempting to use System.Web, version 4.0.0.0. The problem is with 4.0 (actually this started with 3.5), there is now the notion of a client profile. The client profile has a smaller set of reference assemblies, anything web/server related has been removed. This is to make the .NET framework a smaller/simpler download for end users.
With VS 2010 and .NET 4, the client profile is being pushed a lot harder, MS really wants us to use it. So your .NET 4 project is targeting the client profile by default. Your referenced assembly wants System.Web, so in that case you need to switch to the full profile.

Related

How do I convert a project from targeting .net core to target framework to a .net standard?

I created a new .net core 3.1 project and built it using VS2019 16.4.4
Now I want to change it to .Net Standard.
I know to go to the project properties and select the Target framework combo.
However no Standard framework options appear.
If I select Install other frameworks then I am taken to The download .Net SDKs for Visual Studio page
However the SDK I want is already installed on my machine.
Why am I not seeing what I want in the combo box.?
.NET Standard, like .NET Core and .NET Framework, is separate framework, so you can't switch that easily. You would need to create separate project targeting .NET Standard. Once you do it, you will see other options in 'Target framework'.
Worth to mention, you can't reference .NET Core and .NET Framework projects from your .NET Standard library, since .NET Standard is just an abstraction which is built differently depending on the executing environment (.NET Core or Framework)

In Visual Studio 2019, .net Core 2.1, how do I add .net Framework assembly to the project

I am working in Visual Studio 2019, and .net Core 2.1.1.
I am currently working on trying to get Identity Server 4's WsFederation integrated. In the latest instructions I could find, he mentions adding System.IdentityModel to the app through the project.json. Project.json seems to be deprecated now in .net core projects, and I am having a hell of a time figuring out how to add a freaking .net assembly to my project. Do I really need to just copy the file into the project and reference, cause that just seems wrong.
Instructions I am using:
https://www.scottbrady91.com/Identity-Server/IdentityServer-4-SharePoint-Integration-using-WS-Federation
Seems to all come back to the project type. I had created the project with AspnetCore and so I couldn't reference any .net framework assemblies, because you can't go back once you have made that choice. However, if you create the project specifically under the .net framework, you can move forward into the core frameworks, and hosting libraries of core. Which then allowed me to pull in the System.IdentityModel assemblies I needed to continue forward.

Visual Studio 2010 - Web deployment project includes framework DLLs

I have just upgraded a solution with two web deployment projects from VS 2008 to 2010 (upgrading all the projects to .net 4.0 as I went).
I installed the new VS2010 web deployment projects to allow me to open my old build projects (these build up my web sites, clean up a few files and zip them for upload).
I've got these working again, but when I look at the built files, all the referenced .net framework files (e.g. System.Web.dll etc) have been included in the deployed site. Does anybody know why this might be happening and how to turn it off?
Maybe you are using a component (DLL) which is using that files probably by needing specific file version of some framework libraries. VS will automatically copy dependencies of a dependency.
It seems you're using .Net framework Client profile version. Please check the .Net framework version selected for upgraded projects under Project properties.
Here is the MSDN article on .Net framework client profile:
http://msdn.microsoft.com/en-us/library/cc656912.aspx
One reason could be the Copy Local = True property of the referenced .net framework files.

Windows CE project with libraries problem

I am developing a Windows CE application which uses some libraries provided by other parts of our company.
When I deploy my application on "My Computer" (.NET compact application running on standard PC), everything works, but when I deploy to the device, the application hangs when trying to use methods from the library. The system also hangs. My Visual Studio 2008 sometime hangs, but sometime throws an exception "TypeLoadException: Could not load type from assembly Culture=neutral, PublicKeyToken=nu".
I couldn't include .NET Compact framework 3.5 because the image wouldn't compile, so I am using version 2.0. I use Visual Studio 2008 with deploy .NET framework option.
Most probably the problem is with version of the library you are using. Please cross check it.
Hope this link will help you.
I'm a bit confused.
First of all, what are the libraries "provided by other parts of [y]our company" build against? Are they Compact Framework assemblies (they must be)? What version of the Framework were they build against? Reflector can tell you this if you don't know.
Second, why can't you compile it with 3.5? What sort of errors are you seeing? The code should be 100% forward compatible, so if it won't build, there's a red flag going up.
Lastly, what version of the CF is installed on the target hardware? FOr example, are you trying to push a CF 2.0 app to a device with CF 3.5 already installed? If so, do you have an app.config file that provides the framework compatibility options so it knows it can run your assembly?
The problem was that libraries were compiled with for 3.5 target framework, and the application which uses them form 2.0 framework. In that case, 3.5 framework wasn't depoloyed and application would stop working as soon as call to the library methods was made.

Why is the Target Framework dropdown empty and greyed out in my C# class library, VS2008

Fairly self-explanatory. I have recently installed .NET framework 4 and VS2010 but I want to compile my 3.5 projects using 3.5 as 4 has not yet been installed on our production servers and I get "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded." if I try
All project types have the target framework dropdown greyed out
Make sure that your registry keys:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\OnlyUseLatestCLR
and
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\OnlyUseLatestCLR
are set to 0 (not 1).
This fixed it for me since applications like VS2008 are no longer forced to use .NET 4.0 runtime. I had previously set these registry keys to allow Powershell run inder .NET 4.0, however, a config file should be used for that instead.
This has something to do with .NET 2.0 assemblies (i.e. mscorlib) being removed from GAC.
I managed to fix this by first uninstalling .NET framework 3.5 and 4.0 from my Windows 7 using .NET framework cleanup tool:
http://blogs.msdn.com/b/astebner/archive/2008/08/28/8904493.aspx
And then reinstalling both frameworks (first 3.5, then 4.0) from the web. Now the drop-down has options again in VS2008 and I can multi-target 3.5 framework from VS2010.

Resources