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
92
votes
3 answers

What is wrong with ToLowerInvariant()?

I have the following line of code: var connectionString = configItems. Find(item => item.Name.ToLowerInvariant() == "connectionstring"); VS 2010 code analysis is telling me the following: Warning 7 CA1308 :…
JL.
  • 78,954
  • 126
  • 311
  • 459
91
votes
12 answers

How can I send a file document to the printer and have it print?

Here's the basic premise: My user clicks some gizmos and a PDF file is spit out to his desktop. Is there some way for me to send this file to the printer queue and have it print to the locally connected printer? string filePath =…
Only Bolivian Here
  • 35,719
  • 63
  • 161
  • 257
91
votes
5 answers

Why is the new Tuple type in .Net 4.0 a reference type (class) and not a value type (struct)

Does anyone know the answer and/or have an opinion about this? Since tuples would normally not be very large, I would assume it would make more sense to use structs than classes for these. What say you?
Bent Rasmussen
  • 5,538
  • 9
  • 44
  • 63
90
votes
12 answers

Get property value from C# dynamic object by string (reflection?)

Imagine that I have a dynamic variable: dynamic d = *something* Now, I create properties for d which I have on the other hand from a string array: string[] strarray = { 'property1','property2',..... } I don't know the property names in…
sergata.NET LTD
  • 969
  • 1
  • 6
  • 7
90
votes
4 answers

Exception: "URI formats are not supported"

I have an absolute local path pointing to a dir: "file:\\C:\\Users\\john\\documents\\visual studio 2010\\Projects\\proj" But when I try to throw it into DirectoryInfo's ctor I get the "URI formats are not supported" exception. I googled and looked…
Howie
  • 2,760
  • 6
  • 32
  • 60
88
votes
6 answers

Is it possible to run a .NET 4.5 app on XP?

First, I have read the following: Connect case VS case and especially this channel9 post So, from the last bullet, I really think there is no way around this, but I had to see if I could get a definitive answer as my team would like to upgrade…
Justin Pihony
  • 66,056
  • 18
  • 147
  • 180
87
votes
5 answers

Differences between .NET 4.0 and .NET 4.5 in High level in .NET

Eager to know Differences between .NET 4.0 and .NET 4.5 in High level in .NET and also differences in ASP.NET, C# also in these frameworks
venkat
  • 5,648
  • 16
  • 58
  • 83
85
votes
9 answers

String.Replace() vs. StringBuilder.Replace()

I have a string in which I need to replace markers with values from a dictionary. It has to be as efficient as possible. Doing a loop with a string.replace is just going to consume memory (strings are immutable, remember). Would…
Dustin Davis
  • 14,482
  • 13
  • 63
  • 119
83
votes
1 answer

Default for generic type?

Is it possible to do something like public class PriorityQueue where TPriority : IComparable (note the =int) ? Before you suggest it, yes, I know I can just add another line: public class PriorityQueue :…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
80
votes
13 answers

Cannot install windows service

I have created a very simple window service using visual studio 2010 and .NُET 4.0. This service has no functionality added from the default windows service project, other than an installer has been added. If I run "installutil.exe appName.exe" on…
Matthew Dalton
  • 911
  • 1
  • 7
  • 7
79
votes
4 answers

Where is GACUTIL for .net Framework 4.0 in windows 7?

i've made an assembly in the .net framework that I intend to publish to the GAC but I can't find the gacutil utlity. I've been googling a while and I've found a lot of suggestions, but nothing works: Copy the assemby to %window%\assemby [DOES NOT…
Flavio CF Oliveira
  • 5,235
  • 13
  • 40
  • 63
77
votes
9 answers

How to abort a Task like aborting a Thread (Thread.Abort method)?

We could abort a Thread like this: Thread thread = new Thread(SomeMethod); . . . thread.Abort(); But can I abort a Task (in .Net 4.0) in the same way not by cancellation mechanism. I want to kill the Task immediately.
Amir Karimi
  • 5,401
  • 4
  • 32
  • 51
76
votes
3 answers

Using multiple instances of MemoryCache

I'd like to add caching capabilities to my application using the System.Runtime.Caching namespace, and would probably want to use caching in several places and in different contexts. To do so, I want to use several MemoryCache instances. However, I…
Adi Lester
  • 24,731
  • 12
  • 95
  • 110
76
votes
5 answers

How to "sleep" until timeout or cancellation is requested in .NET 4.0

What's the best way to sleep a certain amount of time, but be able to be interrupted by a IsCancellationRequested from a CancellationToken? I'm looking for a solution which works in .NET 4.0. I'd like to write void MyFunc (CancellationToken ct) { …
Onur
  • 5,017
  • 5
  • 38
  • 54
74
votes
5 answers

Passing a method parameter using Task.Factory.StartNew

I have the following code: var task = Task.Factory.StartNew(CheckFiles, cancelCheckFile.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default); private void CheckFiles() { //Do stuff } I now want to amend CheckFiles to accept and integer…
Jon
  • 38,814
  • 81
  • 233
  • 382