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
5
votes
1 answer

ObservableCollection CollectionChanged event seems not to be firing – why?

What’s wrong with this code? Clicking button1 doesn’t cause the messageBox to appear. public partial class Form1 : Form { public ObservableCollection aCollection2 = new ObservableCollection(); myClass mc = new myClass(); …
ispiro
  • 26,556
  • 38
  • 136
  • 291
5
votes
1 answer

Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib

I'm using Unity IoC (Microsoft.Practices.Unity) and I can compile fine, but I'm getting the following error at run time: Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral,…
Didaxis
  • 8,486
  • 7
  • 52
  • 89
5
votes
2 answers

Registering a custom URI protocol to handle custom resource loading from XAML

I'm working on a project where loose bits of XAML (and some associated IronPython code) will be dynamically loaded and executed by a client application. The client will be using a custom WCF service (and some local caching) to retrieve the XAML,…
Adam Maras
  • 26,269
  • 6
  • 65
  • 91
5
votes
2 answers

Why does this DateTime parse always fail?

Can anyone see what I'm doing wrong here? The Assert.IsTrue(parses) always fails. [TestMethod] public void Can_Parse_To_DateTime() { DateTime expected = new DateTime(2011, 10, 19, 16, 01, 59); DateTime actual; …
Scott Baker
  • 10,013
  • 17
  • 56
  • 102
5
votes
1 answer

.NET Find Windows Sleep Settings

I would like to find out what the current windows sleep mode setting is i.e. Is it switched on and what is the timer period. Any ideas? My preferences (in order) are: .NET Managed Code API Read Registry Value
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
5
votes
3 answers

Wpf ListBoxes' ItemsSource strange behaviour

Edited to address F Ruffell's answer I have the following xaml and this code-behind: var ints = new[] { 1, 2, 3 }; _list1.ItemsSource =…
alpha-mouse
  • 4,953
  • 24
  • 36
5
votes
1 answer

what is the Linq expression tree for setting a property of an object?

Suppose I have: class Foo { public int Bar { get; set; } } public void SetThree( Foo x ) { Action fnSet = (xx, val) => { xx.Bar = val; }; fnSet(x, 3); } How can I rewrite the definition of fnSet using an expression trees,…
Eric
  • 11,392
  • 13
  • 57
  • 100
5
votes
1 answer

How do I follow-up a Parallel.ForEach on completion?

I want to take a set of objects and run a routine on all of them. The order doesn't matter and they are each independent operations, so I thought I would call Parallel.ForEach on the collection. But I want to follow-up the whole thing once…
Sean Hanley
  • 5,677
  • 7
  • 42
  • 53
5
votes
1 answer

How to enable GZip compression in a self-hosted RESTful WCF webservice?

I have a RESTful WCF web service written in C# using .NET 4.0, and I'd like the responses to be compressed using GZip or deflate. (I might need to support compression for requests too, but that is not yet a requirement). It will be deployed as a…
Martin Szabo
  • 146
  • 2
  • 6
5
votes
4 answers

How to add a "Page x of y" footer to Word2007 doc as I am generating it using C#

I looked here and here and here I tried this: private void AddFooters() { foreach (Word.Section wordSection in this.WordDoc.Sections) { object fieldEmpty = Word.WdFieldType.wdFieldEmpty; object…
Hamish Grubijan
  • 10,562
  • 23
  • 99
  • 147
5
votes
2 answers

Lambda inside Lambda

assume we have a lambda expression like var thread= new Thread(() => { Foo1(); Foo2(() => { Foo3(); DoSomething(); } ); }); the…
HPT
  • 351
  • 2
  • 11
5
votes
7 answers

INotifyPropertyChanged usage outside data binding

I've never used INotifyPropertyChanged, and I'm considering using it widely throughout a new application. My question is, is it 'proper' to use INotifyPropertyChanged interface in order to provide event notifications for things other than databound…
mservidio
  • 12,817
  • 9
  • 58
  • 84
5
votes
6 answers

line number while querying with linq

I am using a stream reader to read a text file and then using Linq for retrieving the information String fileContent = prodFileStreamReader.ReadToEnd(); var mydata = from con in fileContent.Split('$').Select(x => x.Trim()) …
user425381
  • 53
  • 1
  • 4
5
votes
1 answer

How can I handle generic method invocations in my DynamicObject?

I'm trying to construct a DynamicObject that is able to handle generic method invocations, but it seems that the needed API - although present in RC versions of 4.0 Framework - has been marked internal in RTM (namely, CSharpInvokeMemberBinder is now…
skolima
  • 31,963
  • 27
  • 115
  • 151
5
votes
5 answers

C# .NET Tasks: How to get notification when multiple tasks have completed

In my WPF application, I need to run 2 long running tasks in parallel, both which return data that needs to be shown in the UI. I have a a property in my view model called IsBusy, which should be true until both tasks have completed. How to I get a…
Mas
  • 4,546
  • 5
  • 39
  • 56