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
58
votes
4 answers

How do I express a void method call as the result of DynamicMetaObject.BindInvokeMember?

I'm trying to give a short example of IDynamicMetaObjectProvider for the second edition of C# in Depth, and I'm running into issues. I want to be able to express a void call, and I'm failing. I'm sure it's possible, because if I dynamically call a…
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
58
votes
12 answers

"This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded"

I'm getting the error: "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded." I have a .NET 4.0 dll project that is being called by a .NET 2.0 project. Is there a way to reconcile the difference in…
Nick Myers
  • 662
  • 1
  • 5
  • 10
57
votes
4 answers

Entity Framework Vote of No Confidence - relevant in .NET 4?

I'm deciding on an ORM for a big project and was determined to go for ADO.NET Entity Framework, specifically its new version that ships with .NET 4. During my search for information on EF I stumbled upon ADO .NET Entity Framework Vote of No…
Asaf R
  • 6,880
  • 9
  • 47
  • 69
56
votes
1 answer

What does "reference was created to embedded interop assembly" mean?

I am getting the following warning: A reference was created to embedded interop assembly c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Accessibility.dll because of an indirect reference to that assembly…
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
56
votes
5 answers

Show Dialog box at center of its parent

It's been a mess to show a DialogBox at the center of its parent form. Here is a method to show a dialog. I am positioning its parent to center but not able to center the DialogBox private void OpenForm(Object point, Object height, Object width) { …
Tausif Khan
  • 2,228
  • 9
  • 40
  • 51
56
votes
7 answers

How do I fix the "compilerVersion" IIS error?

I'm getting this exception: System.Configuration.ConfigurationErrorsException: The value for the 'compilerVersion' attribute in the provider options must be 'v4.0' or later if you are compiling for version 4.0 or later of the .NET …
Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447
55
votes
11 answers

Is there an elegant way to repeat an action?

In C#, using .NET Framework 4, is there an elegant way to repeat the same action a determined number of times? For example, instead of: int repeat = 10; for (int i = 0; i < repeat; i++) { Console.WriteLine("Hello World."); …
Arseni Mourzenko
  • 50,338
  • 35
  • 112
  • 199
55
votes
7 answers

Cached property vs Lazy

In .NET 4 the following snippet with a cached property can also be written using the System.Lazy class. I measured the performance of both approaches and it's pretty much the same. Is there any real benefit or magic for why I should use one over…
Martin Buberl
  • 45,844
  • 25
  • 100
  • 144
55
votes
12 answers

int.TryParse syntatic sugar

int.TryPrase is great and all, but there is only one problem...it takes at least two lines of code to use: int intValue; string stringValue = "123"; int.TryParse(stringValue, out intValue); .... Of course I can do something like: string stringValue…
O.O
  • 11,077
  • 18
  • 94
  • 182
55
votes
3 answers

someString.IndexOf(someString) returns 1 instead of 0 under .NET 4

We have recently upgraded all our projects from .NET 3.5 to .NET 4. I have come across a rather strange issue with respect to string.IndexOf(). My code obviously does something slightly different, but in the process of investigating the issue, I…
knersis
  • 585
  • 5
  • 13
54
votes
9 answers

Row_number over (Partition by xxx) in Linq?

I have a DataTable which has a structure and data: id | inst | name ------------------------ 1 | guitar | john 2 | guitar | george 3 | guitar | paul 4 | drums | ringo 5 | drums | pete I can retrieve the records…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
54
votes
4 answers

Covariance and IList

I would like a Covariant collection whose items can be retrieved by index. IEnumerable is the only .net collection that I'm aware of that is Covariant, but it does not have this index support. Specifically, I'd like to do this: List dogs = new…
Brian M
  • 553
  • 1
  • 4
  • 6
54
votes
6 answers

How to get notification that a System.Threading.Tasks.Task has completed

I am currently replacing some home baked task functionality with a new implementation using the new System.Threading.Tasks functionality found in .net 4. I have a slight issue though, and although I can think of some solutions I would like some…
Ben Williams
  • 1,193
  • 1
  • 10
  • 22
54
votes
4 answers

Is a linq query to ConcurrentDictionary Values threadsafe?

let's say I have the following code: ConcurrentDictionary myDict= new ConcurrentDictionary(); Normally every access by key is threadsafe, but is also the following linq query threadsafe? I have not found anything in the…
Chris
  • 4,325
  • 11
  • 51
  • 70
53
votes
2 answers

Casting a result to float in method returning float changes result

Why does this code print False in .NET 4? It seems some unexpected behavior is being caused by the explicit cast. I'd like an answer beyond "floating point is inaccurate" or "don't do that". float a(float x, float y) { return ( x * y ); } float…
Rz Mk
  • 1,072
  • 10
  • 15