Visual Studio Community 2013–issue with NuGet packages

I have recently stepped into the issue while rebuilding an existing project which I have checked out. NuGet correctly downloads the packages from its repositories on my hard-drive but VS seems not to see them in all projects in the solution.

I have reported this bug on Microsoft Connect page and will investigate this issue further.

What is interesting:

1. Libraries are on the disk.
2. In one of the project (this solution has only 3) referenced library works fine, and VS sees it.
3. When Uninstalled and then Installed (Re-Installed?) – everything is fine.
4. I tried changing “maximum number of parallel builds” to 1 – as it was suggested in a different bug which seemed to be the same issue (dependent projects etc.) – but this does not work neither.

NoSQL–dive into graph DB

I am used to relational databases – I used to work in Oracle DBS, a little bit with MySQL and currently Microsoft SQL Server. The problem with these databases is that it is hard to easily show relationship between objects.

In the relational DB tables are objects and relation between is either a part of this table or (what makes such schemas more complicated!) additional tables with many-to-many relations.

One of the ideas to solve this issue is to use different approach – graph databases. The ones use structures of graphs to represent and store data. There are three main elements used in them – nodes, properties and edges. Nodes, as it used to be – are objects such as people, accounts, cars. And this is easy to understand.

Properties are details about particular node – for example, about a person we can store property such as name, surname, age.

The connection between nodes are called edges and these represent the relationship between two edges. This is the place where most of the important information is really stored. And this is also the main difference from relational databases.

I would like to investigate this topic a little bit more deeper so I planned to play with Neo4j database (I know it’s in Java, but thanks to REST web API we can access it through many programming languages and obviously I will use .NET platform) – which is an open source graph database which supports ACID.

Hashtable and Dictionary

As I have mentioned in the previous post – the .NET runtime is now open source. This means that we can dive into it’s code. What is important – most of the code is written in C++ (as expected obviously!).

As part of the runtime I have go through the mscorlib project. What got me interested were Dictionary and Hashtable implementations. There is quite sophisticated arithmetic there as we might have expected.

They share the code

The main difference between this two is obvious – the idea is the same, using hashes to store values in buckets. But it is more important that Dictionary code is just the copy of the initial Hashtable implementation. This means that if any bug fix is implemented in either of them, it needs to be made in the other one as well.

Hashtable has thread safety for multiple readers and single writer build into some of its methods and properties. As you probably know the hash table (aka hash map) is a data structure that maps keys to values and uses hash function for calculating the key (index) to put values into buckets.

In .NET implementation the hash function uses double hashing which looks like this:

h(key, n) = h1(key) + n*h2(key)

where n is the number of collisions for a bucket. h1 is our implementation of GetHash(key) (or the default if we did not override it). More complicated is the h2 one which uses h1 and calculates the value between 1 and hashsize-1.

The table where values are stored is initialized with 3 elements when we do not specify the size (we should not treat this as the constant value from version to version – this can differ). Even when we specify smaller number – there is a check to the “awfully small sizes” are avoided. Very interesting is the procedure for extending the size of the array.

Resize hash array

When the procedure reaches the maximum number of buckets in the array (load factor reaches the maximum load factor) – it needs to be resized. The number of buckets in the hashtable is “automatically increased by approximately a factor of two”. What does it mean? It means that that the size is increased to the smallest prime number which is larger than the current size of hashtable.

How is this organized in the code? First of all – the first 72 prime numbers are stored as the readonly array – so there is no need to calculate them. The biggest one is 7 199 369 (that’s quite big number). When the hashtable size is even bigger – the next prime number is going to be calculated.

We know that by doubling we are preserving the asymptotic complexity of the hashtable operations such as add. What is more important – by having a prime guarantees that double hashing does not lead to infinite loops or just one bucket with plenty of collisions.

Summary

By releasing .NET Framework as open source Microsoft allowed us, developers, to verify the code they wrote. We can even make changes and build our own version of the .NET Framework. I think it is very interesting to check how some of the objects were implemented by devs at Microsoft.

In this short post I dig a little bit into the Hashtable implementation in mscorlib.

CoreCLR–.NET runtime is now open source

.NET team has just announced that .NET Runtime is open source starting now. You can find the repo on GitHub – here to be precise.

This repo contains an execution engine for .NET apps – this is up-to-date CoreCLR codebase which includes RyuJIT, GC, native interop and plenty of other .NET runtime components. This means that we can fork, clone and build our own version of runtime!

I will keep digging into the details of the repo – until then I highly recommend .NET team blog where you can find more details about the release.

Work on C# 7 has already started

When version 6 of the C# language is on its way to the release, the design process for ver. 7 has started. The notes from the design meeting was released couple of days ago. According to Mads Torgersten’s notes – this was the first design meeting.

We can find there couple very interesting parts about future of the language itself but the consequences of making the .NET open source as well.

Design team is still in charge

This is quite important information from these notes – the design process for C# language is not a democratic process. This means that all that community will suggest will be verified by the team but in the end the governance model for C# is benevolent dictatorship. I personally think that having people responsible for the language is a good choice – with community involvement, the language can gain more than it used to be.

The dictatorship does not mean that team will not listen to the community – as the write in notes, they are open for other ideas and suggestions. We must also remember that the day is limited to 24 hours so not all ideas will be verified at the same level.

New version parts (aka themes)

Team has prepared areas on which they want to focus during next version design process. But this is also important that they are willing to add a feature whether it fits in a theme or not.

Working with data

The volume of data in our applications is growing. We can see that more and more interest is focused on functional programming. We have LINQ which is functional-kind-of in the C# language. The design team will investigate further the possibilities to add more features to make working with data much more plesant and easy. They mentioned couple of areas they will investigate – such as pattern matching, immutability, tuples and many other.

Performance and reliability

C# and .NET have areas where the performance and reliability are not the best. There are research projects inside Microsoft which focus on that topic, especially the connection with unmanaged code – the team will investigate this and decide how C# 7 and .NET Framework will be supplemented.

Componentization

This area would probably not influence language itself but they want  to be sure that change how .NET programs are factored and combined could be done.

Distribution

We got async-await in C# 5 for single values – but the area for sequences should be explored. They are also into serialization topic for C#7 – which is quite interesting, as they write “we may no longer be into directly providing built-in serialization“.

Metaprogramming

They are aware that for some reasons in enterprise applications developers are forced to generate code based on some constraints or values from other files. There are areas and ideas to reduce the need to generate code (i.e. virtual extension methods, static ctor constraints, default interface implementations). We may see some of these features in next C# version.

Null

In we will (we got? 🙂 ) get null-conditional operator (x?.Sth) but there are some some more places where such features could be added (i.e. null in foreach statement).

They are also considering non-nullable reference types – which they see as very hard to fully support.

Other

There are number of other not so big feature which are also considered to be implemented/added to version 7.

New version features

Mads makes great effort to fully describe features considered for new version of C# – I think there is no better way as if just read this section from his post. In a nutshell they are interested in:

1. Pattern matching – especially making is operator more powerful, and making case in switch statement more pattern-like than just simple values matching.

2. Array Slices – there is ArraySegment<T> as mentioned in comments but these would be a little bit more language support. This basically mean that the arrays would be better divided into “windows” which could provide us better performance.

3. ref locals and ref returns – this got me thinking that using this is going be not so easy. They are aware that assignment to the getter-only property with ref value – this would create nightmare. They are considering this feature with lots of conditions and explanation how and when use it.

4. Method contracts – we have CodeContracts but there is no language support. What is more important, the runtime has pre- and postconditions for methods – they are considering adding this into the language.

Summary

This is fast! We are waiting for C# 6 release – and we hear about version 7. I expect more information from them as they progress with the design and they will start making decisions. What is more important – they expect us, developers to take part and post ideas on GitHub. The voting system will be used so other developers will have possibility to show which features are more important for real-life applications.