.net-4.0

Why has this particular TimeSpan format string stopped working in .NET 4?

Consider this code (prestuffed with an example): DateTime dt1 = DateTime.Parse("7/30/2010 9:33:29.1234567 AM"); DateTime dt2 = DateTime.Parse("6/30/2010 9:33:00.7654321 AM"); TimeSpan ts = dt1 - dt2; Console.WriteLine(string.Format( "{0:d.hh:mm:ss.ff}", ts )); This is representative of a piece of code that I've had working since .NE...

Converting a custom date format (string) to a datetime

I have a large set (100+ million) of observations with the date represented as a custom string format. We did not generate the date strings, I just need to convert the date string to a datetime type. How do I convert a string date (eg, 12 JUN 2010) to a datetime? My thoughts are to parse the string into components, assemble them in the...

.Net Parallel.For strange behavior...

I brute-forced summing of all primes under 2000000. After that, just for fun I tried to parallel my for, but I was a little bit surprised when I saw that Parallel.For gives me an incorrect sum! Here's my code : (C#) static class Problem { public static long Solution() { long sum = 0; //Correct result is 14291382...

When does File.ReadLines free resources

When working with files in C#, I am conditioned to think about freeing the associated resources. Usually this is a using statement, unless its a one liner convenience method like File.ReadAllLines, which will open and close the file for me. .Net 4.0 has introduced the convenience method File.ReadLines. This returns an IEnumerable and ...

HtmlString vs. MvcHtmlString

HtmlString vs. MvcHtmlString What are the differences bettween those two, or when to prefer one over the other? Edit: One thing to prefer MvcHtmlString over HtmlString is the extension method IsNullOrEmpty of MvcHtmlString. ...

For a simple web application, what service locator library you prefer to use?

For a simple application that use asp.net mvc 3 and .net-4, what service locator application is preferred, with performance concern in mind? ...

How can I enable caching in an EntityDataSource control?

I have three dropdowns, which are bound to the same EntityDataSource control. This results in three identical queries of my database for the data. I have looked for some way to enable caching on the EntityDataSource control, but it doesn't seem to be there? Am I missing something? Am I going to have to roll my own databinding instead...

List, SortedList, Dictionary to store objects by key and serialize them?

My requirements: I need to store a collection of objects inside a class, objects must be accessible by their key (which will be unique string), search/remove/replace must work like this MyClass somethingNew = new MyClass(); // set someproperties on somethingNew somethingNew.Id = "FooBar"; // theOtherObject already contains an ...

Windows Workflow Foundation 4.0 Tutorials / Introductions

Pretty much all of the tutorials/introductions to Windows Workflow Foundation seem to be targeted at versions prior to 4.0, or are somewhat simplistic and don't really show me anything about WHAT the real strengths of Workflows are. Could someone point me in the direction of some slightly meatier tutorials (clearly my google-fu is faili...

DataContractSerializer and its issues - search for better serializer

We've already established previously that DCS serializes/deserializes objects alphabetically. However, after further investigation I've discoverred this is not entirely true. If we have a structure like this: [DataContract] public class Content { [DataMember] public string Title; [DataMember] public string Slug; [D...

nServiceBus .Net 4.0 and MEF

So I've been tinkering in the last few days with nServiceBus. Here a few things that I want to know. How do I get a version that will play nice with .net 4.0? I'm using NServiceBus.2.0.0.1145 which I believe is the lastest but I needed to convert the sample solutions to VS2010 (which works fine) but their target framework is 3.5. Also...

asp.net 4.0 dynamic data generating search or filtering for each columns

Hi, I am using dynamic data entities linq to sql project. For my test project I have one table, with 10 columns and a single primary key for example. Almost all the columns are varchars. I can get the basic project up and running fine - update, delete, insert etc. Since it has no foreign keys, there are no search filters rendered. I w...

Reference issues in .NET 4.0 project to .NET 2.0 dll/project

I just starting to use Visual Studio 2010 and .NET 4.0. I created a new WPF project a DLL built for .NET 2.0. When I build the project, I get a bunch of warnings like this one: The referenced assembly "MicroFour StrataFrame Business...processorArchitecture=MSIL" could not be resolved because it has a dependency on "System.Web, Version...

How to register assembly in Net Framework 4.0

I have an net assembly that was originally written in framework 1.1. I have complied this with a framework 4.0 and need to put in the GAC There is no Framework configuration tool (Administrative Tools/Microsoft .Net Framework n.n Configuration any longer. How do I view/Manage Framewok 4.0 GAC assemblies. I am using this assembly with S...

SyncStagedProgressEventArgs converted to DbSyncSessionProgressEventArgs

I am working on an app that is using Synchronization Framework v2. I am basically done with it, but would like to offer some better fedback about the progress of the synchronization. I was looking at one of the Synchframework examples that Microsoft offers, SharingAppDemo-CEProviderEndToEnd, and see that the have a method in the Progress...

Has anyone had any difficulty upgrading from Entity Framework 1 to Entity framework 4?

I'm looking at a project that has been developed and maintained with Entity Framework 1 that is relatively stable at this point. I'm wondering if people have ever migrated a project like that to EF 4 and if anyone can share any particular difficulties they may have had. I know there are a lot of benefits to look forward to but I'm tryi...

Automatically adding rows to excel file template

Hi, I am running .net 4.0 asp.net app on IIS 7. I want to know if there is an easy way of adding rows to an excel 2007/2010 (not too fussed) template file that a user can download from the server. For example, the user might check a couple of tick boxes and clicks a button on the web page. The server does a sql query on a table and com...

How can I use CAS in .NET 4 to lock down my MEF extensions?

I have an application in .NET 4 that uses MEF for extensibility. My main application has three assemblies: Host, Application and Contracts. Host is the "boot-strapping" executable that creates the container and does the composition. Application contains the logic of my application, and more extension points for 3rd parties. Contracts...

Which design by contract framework for C#.NET?

I am looking at using design by contract for a personal project in C# using .NET 4. I have been reading about Microsoft's attempt at a design by contract framework: http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx But there are many alternatives and I'm baffled - so which is the best and why? What are the pros and cons of each? ...

Is it possible to turn on HTML encoding by default in ASP.NET 4?

In ASP.NET 4, we can use the new <%: ... %> operator to output HTML encoded strings. Is it possible to configure ASP.NET 4 (in web.config) so that the <%= ... %> operator will also HTML encode strings? ...