.net-4.0

Howto get started with C# 4.0 and .NET 4.0?

I don't want to download Visual Studio 2010. How can I start studying (not developing real applications) C# 4.0 and .NET 4.0 with just a text editor? Can I just download C# 4.0 compiler and .NET 4.0 framework and get started? How? I have got Visual Studio 2008 but I learn from SO questions that it can't do the job. ...

Is there a c# precompiler define for the CLR version

Hi, I need to compile code conditionally by the CLR version. e.g there's a code that I need to compile only in CLR 2 (.NET 3.5 VS2008) and not in CLR 4 (.NET 4 VS2010) Is there a precompiler directive for the current CLR version that I can use inside an #if clause? Thanks. ...

Can I use .NET 4 with SharePoint 2007?

I'm on a team that's currently building a MOSS 2007 based application (which relies on .NET 2), and we'd like to leverage the Entity Framework v4 (which relies on .NET 4). Is this possible? ...

Is WebProtocolException included in .net 4.0?

The WCF starter kit has WebProtocolException to throw exceptions in WCF. Is this included in .net 4.0? ...

Reusing part of the query with joins

I need to implement 3 public methods that all rely on the same initial join. Would a solution like the one described below work? The code below is an example, the real stuff is much more complicated, that's why I want to reuse it. private Tuple<Customer,Order> GetCustomerOrders() { from c in customers join o in orders o...

Default valued DateTime column, mapping with EF4

In my database there's a datetime column "Created" with default value getutcdate(). I would like my EF datacontext to generate an insert query that doesn't set this column, and fetch the resulting value. Is there a way to do this? I tried setting StoreGeneratedPattern to either None, Identity or Computed, I get an exception that DateTim...

Making sure that DateTime properties return DateTimeKind.Utc

Is it possible to define DateTime properties in entity objects that are of Kind == DateTimeKind.Utc by using either the .edmx file, or a t4 template? When possible using t4, please describe how to change the property. Currently the property gets generated as: [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] [Dat...

[c#] dynamic vs var

Possible Duplicate: Whats the difference between dynamic(C# 4) and var? What is the difference between dynamic and var keyword in .NET 4.0 (VS 2010). As per MSDN, the definition of dynamic is - Dynamic lookup allows you to write method, operator and indexer calls, property and field accesses, and even object invocations which by...

How do I use Fluent NHibernate with .NET 4.0?

I want to learn to use Fluent NHibernate, and I'm working in VS2010 Beta2, compiling against .NET 4, but I'm experiencing some problems. Summary My main problem (at the moment) is that the namespace FluentNHibernate isn't available even though I've imported all the .dll assemblies mentioned in this guide. This is what I've done: 1. I d...

Weird override problem with Fluent NHibernate and .NET 4

I recently asked a question about using Fluent NHibernate with .NET 4 - I solved that problem, but met a new one. Summary My main problem (at the moment) is configuring the database. I'm following this guide, but trying to work against SQL Server 2008 Express instead, as that's what I'll be using and thus what I need to learn. The fail...

Does Silverlight 4 require .NET 4?

Do Silverlight 4 applications require that they target .NET 4. With the delay in .NET 4 and Visual Studio 2010; can I still get the advantages of Silverlight 4 running against the .NET 3.5 framework? ...

How is the Stream.CopyTo(Stream) method implemented in .NET 4?

A useful convenience introduced in .NET 4 is Stream.CopyTo(Stream[, Int32]) which reads the content from the current stream and writes it to another stream. This obviates the need for slightly tedious code such as this: public static void CopyStream(Stream input, Stream output) { byte[] buffer = new byte[32768]; while (true) ...

Calling UrlDecode in a C# .NET 4.0 Visual Studio 2010 Console Application ?

OK, for some reason Microsoft removed System.Web but we can import System.Net.WebUtility and call HtmlDecode(), but how can we call UrlDecode()? Please answer for .NET 4.0/VS2010 B2 ONLY. ...

System.Windows.Baml2006.TypeConverterMarkupExtension threw an exception

I got this error in a WPf Application when calling the InitializeComponent. In the Designer I get this error: Could not load file or assembly 'LCP.ScanLite.WindowsWPF, Culture=neutral' or one of its dependencies. The system cannot find the file specified. at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String code...

Resource messages: 'AssemblyResolver': Not in Cache

I have a small C# library written in C# (and .NET4.0 B2). I use a resource assembly (let's call this XXXAssembly) containing resx files to provide the message strings which are used in other assemblies. When running a program by using these assemblies, I get the following lines (always happen to be 4 these 4 lines): 'AssemblyResolver': ...

How to write an extension method that returns a dynamic object?

I was thinking about how Regex.Match.Group wants to be dynamic: Regex.Match (...).Groups["Foo"] would like to be: Regex.Match (...).Groups.Foo I thought about writing an extension method that would allow: Regex.Match (...).Groups().Foo And tried writing it this way, but this isn't allowed (';' required by 'static dynamic') pu...

Mixing MEF parts targetting .NET 3.5 with an application targetting .NET 4.0

The Managed Extensibility Framework is both a stand-alone project (currently targetting .NET 3.5) and part of the .NET 4.0 framework. Suppose I create assemblies targetting .NET 3.5 that contain MEF parts. These assemblies will reference the stand-alone version of System.ComponentModel.Composition.dll. Now suppose I create a MEF-enabl...

What's the best BDD framework for working with ASP.NET MVC 2 + C# 4?

I just heard about BDD when I watch video of Scott Guthrie in Sweden. One of listener asked question to Scott about How VS2010 and ASP.NET MVC do to support BDD. After that, I search about BDD (Behavior Driven Development) that focus on specification more than unit testing when compares with TDD (Test Driven Development). I found some f...

How do I convert a DateTime to a Date in C#

I can't believe how long it's taken me to fail at finding the answer to this seemingly obvious question. Date SomeRandomMadeUpDate = DateTime.Now.AddMonths(randomMonths).Date; Cannot implicitly convert type 'System.DateTime' to 'System.Date' I can even call: Date.Now but calling .AddDays on it returns a DateTime. Again,...

C#: Code Contracts vs. normal parameter validation

Hi, consider the following two pieces of code: public static Time Parse(string value) { string regXExpres = "^([0-9]|[0-1][0-9]|2[0-3]):([0-9]|[0-5][0-9])$|^24:(0|00)$"; Contract.Requires(value != null); Contract.Requires(new Regex(regXExpres).IsMatch(value)); string[] tokens = value.S...