Questions tagged [.net-4.0]

Version 4.0 of the .NET Framework. Use for questions specifically related to .NET Framework 4.0. For questions on .NET Framework generally, use the .net tag.

Released on April 12th, 2010, version 4.0 (4.0.30319.1) of the Microsoft .NET Framework contains numerous enhancements, new features and bug fixes.

What's New in the .NET Framework 4

Language Improvements

Base Class Library (BCL) additions:

For more information about the new features, see:

8834 questions
214
votes
8 answers

C# Create New T()

You can see what I'm trying (but failing) to do with the following code: protected T GetObject() { return new T(); } Any help would be greatly appreciated. EDIT: The context was as follows. I was playing around with a custom controller class…
Hanshan
  • 3,656
  • 5
  • 29
  • 36
208
votes
6 answers

How can I convert this foreach code to Parallel.ForEach?

I am a bit of confused about Parallel.ForEach. What is Parallel.ForEach and what does it exactly do? Please don't reference any MSDN link. Here's a simple example : string[] lines = File.ReadAllLines(txtProxyListPath.Text); List
SilverLight
  • 19,668
  • 65
  • 192
  • 300
200
votes
9 answers

How do I run msbuild from the command line using Windows SDK 7.1?

I'm setting up .NET 4.0 support on our CI server. I've installed .NET 4.0, and the .NET tools from the Windows 7.1 SDK. On .NET 2.0 and 3.5, that just worked. With .NET 4, when I run the "Windows SDK 7.1 Command Prompt" from the Start menu, it…
Dylan Beattie
  • 53,688
  • 35
  • 128
  • 197
196
votes
17 answers

How can I get a web site's favicon?

Simple enough question: I've created a small app that is basically just a favourites that sits in my system tray so that I can open often-used sites/folders/files from the same place. Getting the default icons from my system for known file types…
Steven Evers
  • 16,649
  • 19
  • 79
  • 126
187
votes
7 answers

Razor View Engine : An expression tree may not contain a dynamic operation

I have a model similar to this: public class SampleModel { public Product Product { get; set; } } And in my controller I get an exception trying to print out @Html.TextBoxFor(p => p.Product.Name) This is the error: Exception: An expression…
femseks
  • 2,914
  • 3
  • 23
  • 20
184
votes
19 answers

Cleaner way to do a null check in C#?

Suppose, I have this interface, interface IContact { IAddress address { get; set; } } interface IAddress { string city { get; set; } } class Person : IPerson { public IContact contact { get; set; } } class test { private test() …
173
votes
8 answers

Mixed mode assembly is built against version ‘v2.0.50727′ of the runtime

I'm getting the following exception: Mixed mode assembly is built against version ‘v2.0.50727′ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information. as I was trying to export crystal report from my…
Christina Wong
  • 1,739
  • 2
  • 11
  • 4
171
votes
2 answers

What is Microsoft.csharp.dll in .NET 4.0

This DLL is added by default in Visual Studio 2010 projects. What is this new assembly used for? It does not seem to contain much after looking at it using Reflector and Google does not seem to have much to say about it either.
anon
  • 1,713
  • 2
  • 10
  • 4
170
votes
10 answers

.NET console application as Windows service

I have console application and would like to run it as Windows service. VS2010 has project template which allow to attach console project and build Windows service. I would like to not add separated service project and if possible integrate service…
Tomas
  • 17,551
  • 43
  • 152
  • 257
167
votes
14 answers

How do I check if a property exists on a dynamic anonymous type in c#?

I have an anonymous type object that I receive as a dynamic from a method I would like to check in a property exists on that object. .... var settings = new { Filename="temp.txt", Size=10 } ... function void…
David MZ
  • 3,648
  • 6
  • 33
  • 50
166
votes
13 answers

No generic implementation of OrderedDictionary?

There doesn't appear to be a generic implementation of OrderedDictionary (which is in the System.Collections.Specialized namespace) in .NET 3.5. Is there one that I'm missing? I've found implementations out there to provide the functionality, but…
AdaTheDev
  • 142,592
  • 28
  • 206
  • 200
163
votes
7 answers

Co-variant array conversion from x to y may cause run-time exception

I have a private readonly list of LinkLabels (IList). I later add LinkLabels to this list and add those labels to a FlowLayoutPanel like follows: foreach(var s in strings) { _list.Add(new…
TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
154
votes
4 answers

Change C++/CLI project to another framework than 4.0 with vs2010

Since I upgraded my project to visual studio 2010 project format, my C++/CLI project is targeted to .net framework 4.0. It is easy to switch the framework version to another version from a C# project, but I have no clue how to do this in a C++/CLI…
codymanix
  • 28,510
  • 21
  • 92
  • 151
144
votes
7 answers

Fixing slow initial load for IIS

IIS has an annoying feature for low traffic websites where it recycles unused worker processes, causing the first user to the site after some time to get an extremely long delay (30+ seconds). I've been looking for a solution to the problem and I've…
Cavyn VonDeylen
  • 4,189
  • 9
  • 37
  • 52
137
votes
5 answers

Using async-await on .net 4

I'm currently starting to create an application that would profit a lot from C# 5's async-await feature. But I'm not sure which version of VS and of the async runtime to use. Looking at OS popularity charts, I'll need to support Windows XP for…
CodesInChaos
  • 106,488
  • 23
  • 218
  • 262