.net-4.0

How to validate Data Annotations with a MetaData class

I'm trying to validate a class using Data Annotations but with a metadata class. [MetadataType(typeof(TestMetaData))] public class Test { public string Prop { get; set; } internal class TestMetaData { [Required] public string Prop { get; set; } } } [Test] [ExpectedException(typeof(ValidationException))...

.NET 4.0 - CultureNotFoundException.

Hi. I have migrated my ASP.NET MVC 2 project to VS 2010 + .NET 4.0. Now when i start the application i get a lot of "CultureNotFoundException" in IntelliTrace and Output/Gebug window : A first chance exception of type 'System.Globalization.CultureNotFoundException' occurred in mscorlib.dll I know what "A first chance exception" means, ...

Return Tuple from EF select

How can I retrieve Tuples at Select using EF4? var productCount = (from product in context.products select new Tuple<Product, int>(product, products.Orders.Count)); Or var productCount = (from product in context.products select Tuple.Create(product, products.Orders.Count)); En...

Size of managed structures

The .NET 4.0 Framework introduces classes for reading and writing memory mapped files. The classes are centred around methods for reading and writing structures. These are not marshalled but copied from and to the file in the form in which they are laid out in managed memory. Let's say I want to write two structures sequentially to a me...

c# element sort

I have a problem trying to sort a Dictionary<int,Elem>/SortedList<int,Elem> of elements. I have a list of N elements that should appear X times on the list, but if an element is on i index then it cannot reappear on i - 1 or i + 1. I also must respect list limits (elem N is before elem 1 and elem 1 is next to elem N). I have two possi...

Are State Machines created in Windows Workflow 3.5 compatible with version 4.0?

If I have a State Machine created in version 3.5 will I be able to upgrade to .Net/WF 4.0, or will I have to re-create the functionality? I heard / read that 4.0 does not support State Machines. Finally, if you have a State Machine in 3.5, what is your plan for migrating to 4.0? ...

Using Reflection to analyze Parameters and their values

I've seen older posts here on SO, about one year old which would mean that they do not really cover .NET 4 or maybe even 3.5 on this topic. So here goes. If you with reflection were to fetch parameters for the current method ParameterInfo[] methodParams = MethodInfo.GetCurrentMethod().GetParameters(); Looping through each parameter w...

IDictionary<TKey, TValue> in .NET 4 not covariant

The IDictionary<TKey, TValue> in .NET 4 / Silverlight 4 does not support covariance, i.e. I can't do a IDictionary<string, object> myDict = new Dictionary<string, string>(); analog to what I can do with IEnumerable<T>s now. Probably boils down to the KeyValuePair<TKey, TValue> not being covariant either. I feel that covariance should...

Converting IEnumberable<T> to List<T> on a LINQ result, huge performance loss.

On a LINQ-result you like this: var result = from x in Items select x; List<T> list = result.ToList<T>(); However, the ToList<T> is Really Slow, does it make the list mutable and therefore the conversion is slow? In most cases I can manage to just have my IEnumerable or as Paralell.DistinctQuery but now I want to bind the items to a...

Is there a neat workaround to the lack of foreign key identity columns in Entity Framework 3.5?

I'm having to downgrade a site from .NET 4 beta 2 to .NET 3.5. The biggest hurdle is all the foreign key identity values I reference/lookup, as this isn't supported natively in EF 3.5. Does anyone know of a reasonable work-around for this? An example of what I mean is: contacts.Where(contact => contact.TypeGuid == guid) [TypeGuid] ...

EF4 Update model from Database VistaDB issue

Does VistaDB support 'Update model from Database' feature in EF4? I'm receiving this message: " ... 'System.ArgumentNullException' 'Value Cannot be Null' Parameter name: providerInvariantName" ...

Detailed Changelog for .NET Framework 4.0

Is there a detailed list of changes in .NET 4.0? Please add any changes you know about. ...

Excel get_Range missing when interop assembly is embedded in .NET 4.0

I build an assembly referencing a COM interop DLL. If I embed the COM interop types by setting Embed Interop Types to True in the Reference's properties (VS2010), at run-time an error occurs "object does not contain a definition for get_Range". If COM interop types are not embedded then no error occurs. Does anyone know why a particul...

WCF ServiceModelReg.exe erased system.serviceModel section in machine.config

The problem (after much head scratching) is fixed now, so I'm just trying to understand what went wrong with my WCF settings. I just had a problem where I ran ServiceModelReg.exe to fix some .svc handler mappings in IIS7 and started getting HTTP 500 errors and event log entries like this: WebHost failed to process a request. Sender Info...

How will Code Access Security work under .NET Framework 4?

I've heard that Code Access Security is changing completely under .NET Framework 4. Can anyone confirm how this will now work, and what the implications will be for legacy applications? ...

Generic Variance in C# 4.0

Generic Variance in C# 4.0 has been implemented in such a way that it's possible to write the following without an exception (which is what would happen in C# 3.0): List<int> intList = new List<int>(); List<object> objectList = intList; [Example non-functional: See Jon Skeet's answer] I recently attended a conference where Jon Ske...

Convert an Icon to IPicture in .NET 4.0?

One of the standard and (somewhat) supported answers was to use Support.IconToIPicture from the Microsoft.VisualBasic.Compatibility assembly. However, in .NET 4.0, "This API is now obsolete". Yes, there are various solutions out there, but I would think that if Microsoft was obsoleting this method, there would be another "supported" al...

Is it safe to install .net 4.0 RC on a 3.5 development machine?

I want to try a few things with the new version of the framework, but I use my machine to develop quite a few .NET 3.5 applications. Will I be able to uninstall the framework and Vs 2010 without problems or incompatibilities? Has anyone tried it? ...

EF4: There is no property with name 'CountryId' defined in type referred by Role 'Customer'.

Within my database (SQL2008), I have a customer table and a country table (among others) and there is a foreign key relationship defined in the database between these tables based upon "Country.Id -> Customer.CountryId". I have created an EF model using VS2010 RC and built this model from the database. When generating the model, I selec...

How to get next object in IEnumberable / IQueryable if ID key is not consistent?

Hello everybody, After hacking more on my current app - once again, I am running into an issue which kills some of the joy I expected from my domain model. The problem here is that the aggregate root / most important class in my domain model doesn't have consistent ID values for its entries. (E.g messed up : 1..3..5..12..150..157.. an...