So how do you patch a deployed Nuget package

Quite some time ago, this blog post went past on the usual Microsoft RSS feed, discussing how Microsoft are going to make it possible to patch NuGet libraries. Using the standard mechanism of putting an assembly in the GAC and redirecting clients to use it via a publisher policy is a way to deploy a patch, but the article hints at an attribute that signals to Microsoft Update that such an updated assembly needs to be installed. I thought that it is was probably time to see what was happening.

Adding a NuGet reference to SignalR and then using Reflector to look at the assembly attributes, there is now a use of
[assembly: AssemblyMetadata(“Serviceable”, “True”)]
to flag the assembly to the runtime.

Looking in the CoreClr source code on github, in the assembly.cpp file there’s a GenerateBreadCrumbForServicing method which writes details about the assembly under c:\programData\Microsoft\NetFramework\BreadcrumbStore\ and sure enough when I look at that folder in explorer I see a mass of NuGet packages that my applications have loaded. These take the form of empty files with names such as

EntityFramework, Version=5.0.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089

It will be interesting to see how well this mechanism works in practice – if I xcopy deploy something, there is going to be a delay between the first time I load the assembly (leading to the breadcrumb being set) and Microsoft Update running and fixing it up. I’m also interested in what other AssemblyMetadata attribute values there are being used, but investigating that is going to have to wait.

Posted in Uncategorized | Leave a comment

F# Deep Dives

F# Deep Dives by various

I was really looking forward to reading this book, and it was well worth waiting for. The book has many contributing authors, each of whom provides one of the 12 chapters. Of course, with such a diverse set of contributors, some of the chapters are more interesting than others, but many emphasise the benefits of F# as a functional first programming language.

There is an interesting opening chapter on how functional first programming languages can be effectively used in industry, but there were five chapters that I found particularly interesting. Parsing text-based languages looks at the task of writing a parser in F# and uses some interesting techniques such as active patterns to make it easy to read the resulting code. Chapter 6, integrating stock data into the F# language, offers a brief introduction to type providers, and then shows most of the steps to implementing type provider for CSV and YQL.

In the following section on developing complete systems, there are chapters on developing rich user interfaces using the MVC pattern which shows how F# can be used to write an application that uses WPF for its UI, a great chapter on asynchronous and agent-based programming that looks at ETL (extract, transform and load) models, and a chapter on writing games using XNA which emphasises the async workflow which can help keep the state machines of a game understandable.

You’ll learn something from all of the chapters and the book is well worth a read.

Posted in Uncategorized | Leave a comment

Time Reborn

Time Reborn: From the Crisis in Physics to the Future of the Universe by Lee Smolin

This was a very interesting read in the popular science category. It centres on the position on time in the laws of physics, first describing how time lost its place as a central focus of many theories, and then discusses the problems that this causes when physicists try to apply their theories to the universe as a whole. Smolin discusses how the reductionist approach of deriving laws by observing a system from the outside, is inapplicable to the discovery of the laws that govern the universe as a whole. The book is a mash up of interesting ideas from new theories and discussions around existing ideas and theories, all pitched at the popular science level with understandable explanations.

Posted in Uncategorized | Leave a comment

You can have your own CLR too

I was surprised when the source to the CoreCLR was published on GitHub a few weeks ago. Over the weekend I thought I’d start to build it and begin looking through the code in detail. I was amazed at how easy it is to build.

First you check out the sources from GitHub. Next you down the latest version of CMake and put it on your path. Then you run the build.cmd script. Your PC gets a bit busy for 30 minutes and then you have your own version of the CLR and the associated mscorlib.dll. [There is one gotcha concerning the DIA SDK that the script will warn you about – the fix is a copy from an older VS installation to the newest]

You can then use your existing C# compiler to compile against this version of the CLR.

c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /nostdlib /r:D:\git\coreclr\binaries\Product\x64\debug\mscorlib.dll test.cs

and then run it using CoreRun

D:\git\coreclr\binaries\Product\x64\debug\CoreRun.exe test.exe

Brilliantly painless.

Posted in Computers and Internet | Leave a comment

JavaScript Ninja Secrets

Secrets of the JavaScript Ninja by John Resig and Bear Bibeault

This is a very good book which is so much more than a simple JavaScript language text. Sure, it covers some of the subtle points of the JavaScript language, and you are expected to have knowledge of JavaScript before reading the book, but it also offers a lot of information about some of the practical problems you will meet as a JavaScript programmer.

It starts in a slightly odd manner. There is a chapter discussing the benefits of cross browser development, followed by a chapter in which the  author writes a simple testing framework.  This framework allows you to embed tests inside an HTML page, and displays the results of the assertions inside the tests in an easy to read manner. Lots of the explanations that follow in the book will be expressed as assertions in the language of this testing framework. This way of working works very well.

The next section of the book, Apprentice Training, consisting of six chapters, has five chapters that focus on the subtle parts of the JavaScript language. The book focuses on the functional nature of JavaScript, discusses why it is important and then gives a very good explanation of scope and the four ways that you can invoke a function object – as a function, as a method, as a constructor and via apply and call. There is a good discussion of recursion followed by an example of memorisation, showing the big benefits of pure functional code. This is followed by a chapter on closures, which describes what they are and then shows how they can be used to implement partial application and temporary scopes with private local variables. We then go object-oriented in a discussion of prototypes and how they can be used to get features like those of standard OO languages. The author defines a JavaScript mini-framework that defines inheritance hierarchies that support a super operation to access base types. There is then a chapter on regular expressions, showing their great power (though you’ll need to be responsible to use them).

The last chapter of this section talks about the single threaded nature of browsers, the typical JavaScript host, and discusses how timers can be set and cleared. There is also lots of cross browser detail in how these things are implemented, and the book covers some of the common gotchas.

The next section, Ninja Training, first talks about runtime code evaluation, at first using eval and Function to make new function objects, but then moving on to describe the inbuilt decompilation (as you can ask a Function for its source code). There is then an interesting section showing some of the uses of these techniques.

The next chapter looks at with statements, a feature of JavaScript that you either love or hate. There is a small concise example that shows a powerful micro-templating engine that is written in a tiny amount of code, which shows the power of the features we have been shown before.

There are then two chapters on cross-browser strategies for using the DOM. Lots of practical discussion of the differences between browsers which taught me a lot about the DOM and how it should be used.

The last section, Master Training, also looks at browser differences, looking at the differences in the event model and CSS selectors.

The book is a really good read. It explains the parts of JavaScript that it covers really well, and you’ll learn loads about browsers and the DOM which is very interesting and useful if you do cross-browser work. The browsers that it discusses are a little behind the times, but that is probably the only complaint I have.

Posted in Books | Leave a comment

Understanding the CLR via its assembly code

Expert .NET 2.0 IL Assembler by Serge Lidin

I have read large parts of this book multiple times, but have never sat down and read it cover to cover before. It’s a great book for understanding the CLR. The book isn’t just about IL assembly language as a programming language. The book covers this but also covers the translated form of the IL, discussing the format and sections of a PE file including the various metadata tables of the various types (think assembly or module or class) and heaps. It also gives a great explanation of the various IL instructions and discusses the semantics of generics and exceptions. All in all, I think it is a great book for understanding the CLR and I always (re)learn something every time I reread it.

For example, when you want to call the methods on a valuetype via an interface, you typically need to box it. If the struct is not mutable this is usually not the semantics you want. When you instantiate a generic class using a structure type, the user would like the interface method to be invoked without any boxing, and the CLR version 2 got a new IL instruction, constrained to deal with this.

class Holder<T> where T : IFoo
{
T field;
public Holder(T x)
{
field = x;
}
public void DoInc()
{
field.Increment();
}
}

leads to the following code for the DoInc method

IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldflda !0 class ConsoleApplication10.Holder`1<!T>::’field’
IL_0007: constrained. !T
IL_000d: callvirt instance void ConsoleApplication10.IFoo::Increment()
IL_0012: nop
IL_0013: ret

The book also warns you of some of the times when C# isn’t the assembly language of .NET… if you satisfy an interface using a non-virtual method, the C# compiler silently makes it sealed virtual, or if you nest a non-generic class inside a generic class the compiler silently makes the nested class generic so that you have access to the type parameter.

The book teaches you loads of miscellaneous facts about the CLR – debug information and various security attributes for example, and how unmanaged mixed-mode assemblies work. The emphasis on using ILDASM/ILASM to round trip code with modification is also very informative.

A thoroughly great book!

Posted in Books | Leave a comment

Category theory seems to pop up everywhere

Basic Category Theory For Computer Scientists by Benjamin C. Pierce

I have looked at this book before, but decided to try to give it another read over the holiday. The content is rather dry, but for each of the concepts the author provides a mass of examples that make it easier to understand the concepts.

The book is fairly short with only four chapters, and the fourth chapter is just descriptions of additional material with a paragraph describing each items relevance. However, it does what it says on the cover – providing a way to understand terms that appear to crop up all over the place in Computer Science these days. Chapter three on applications covers some domain theory and Cartesian Closed Categories in a few pages.

I’m not sure I’d recommend this as an end to end read, but more as something to dip into when terms need to be understood.

Posted in Books | Leave a comment