DotNet Core “Unable to load DLL ‘System.Security.Cryptography.Native” error

I was trying to play with DotNet Core in Visual Studio Code, and I was following the instructions as stated here.

After installed Brew I installed the latest version of OpenSSL as required by DotNet Core and then I tried to run the classic “Hello World” program, but the command

dotnet restore

failed with this error:

“Unable to load DLL ‘System.Security.Cryptography.Native”

This error has to do with OpenSSL, or even better with Brew that refuseed to correctly link OpenSSL.

Here is the correct command sequence that needs to correctly setting up OpenSSL for DotNet Core.

brew update
brew install openssl
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/Cellar/openssl/1.0.2j/bin/openssl openssl

Hope this helps

Blog moved to WordPress

It’s long time I don’t write anything on this blog, I was very busy in recent times, but now the time has come and I intend to regain the time lost.

When I came back to this blog, the first thing I noticed were the look & feel and the software engine on which it was based, SubText, a very old bog software, but still widely used, so I decided to move it to another platform, possibly in step with times, and my choice was WordPress.

Now this blog is based on WordPress engine the most popular online publishing platform, currently powering more than 20% of the web.

Here are the necessary steps (and troubleshooting) to move an entire blog content based on SubText to WordPress:

STEP 1: Subtext – Export your blog content

This is a “one choice” step, because SubText exports its content only in BlogML format, based on XML, and creates an XML file with all your posts, your categories and son forth. To accomplish this, logon to SubText as administrator, go to “Options > Import/Export” and click on the Save button. The check “embed attachment” must remain unchecked otherwise WordPress won’t be able to import the file.

The file’s content is base64 encoded, so I was recommended to convert it as normal text. Don’t worry, fortunately there always are other people who had before the same problem as you had. Not that writing a very little program that convert the file’s content from base64 encode to normal text is a particularly difficult task, but if things are already done it’s better! So if you surf here you can copy and past the code, compile it, run it, and have the file correctly converted.

STEP 2: WordPress – configure the permalink structure

This step is strongly recommended if you don’t want that the structure of all URL’s doesn’t change compared to the URL’s structure of the SubText as not to lose the Google indexing of your blog. Then the URL’s structure of the WordPress based blog must remain the same.

To accomplish this, you need to change the permalink structure in WordPress. After you login as administrator, go to “Settings > Permalink” and check “Custom structure”, then typing this URL structure:


This is exactly the URL’s structure used by SubText. Note the “ASPX” suffix, even if WordPress isn’t an ASP .NET application.

This picture may helps:

Schermata 2014-09-18 alle 22.59.53.png

STEP 3: WordPress – import your blog using the BlogML WordPress plugin importer.

This plugin is built in into WordPress installation, so it’s nothing to download and install. Just click to “Tools > Import” and then choose BlogMl importer, upload the file XML generated at step 1 and click the button “Upload file and import”

Schermata 2014-09-18 alle 23.10.10.png

Just a few seconds and your blog is imported in WordPress and is up and running!

STEP 4: WordPress – troubleshooting.

1) The BlogML Importer plugin doesn’t import blog categories correctly. They have been imported with the ID they had in SqlServer SubText repository in place of description. You must correct them manually.

2) The RSS Feed wasn’t generated correctly; the procedure ended with a XML parsing error, as shown in this picture:

Schermata 2014-09-18 alle 23.34.06.png

and it seems to be related to some whitespace or blank lines into the various *.php files of the WordPress installation, or with custom permalinks that break RSS feed, like they said here

This problem was quite difficult to resolve and it took several time and Google searching.

Initially I founded this WordPress Fix plugin, I tried it but it fixed anything, on the contrary it said that my RSS feed was working well and that all was fine!

After an hour of Google searching, I found the solution in this Peter Krzyzek’s post, and I can never be grateful enough to the author for having solved this problem.

These are the steps you have to do:

– Download this: (this is a php file)

– Copy this file in the ROOT folder of your WordPress installation

– Edit the index.php file in the ROOT folder and add the followings:


after the first line, e.g. just after the <?php line

– Reload the page and….BOOM….IT WORKED!!!!!!

I don’t know anything about php, I’m a .Net developer, and without that post I will never solve this problem.

Thank you Peter!

NHibernate QueryOver is not a Linq provider (that is how to do join with QueryOver API)

Starting from NHibernate 3.0 a new API was build as a wrapper around the ICriteria object.

Obviously I’m talking about the powerful API called QueryOver. With this API you can build a wide range of query object, from the simplest to the more complicated one. But you need to remember that this API is not a Linq provider, and then you cannot apply those constructs typically applied in a Linq query. I explain with an example what I really mean.

Introduction: you have a data model with 2 table, Category and Customer, with a one-to-many relationship between them.

With Entity Framework and Linq To Entities it’s pretty simple to query data that belong to both entities, thanks to navigation properties and Linq provider, i.e. all customers that belong to a category with a specified Id, as shown in this example:

var customerList = customers.Where(c => c.CategoryId == 1);

If you try to execute the same query with the same where conditions applied to a QueryOverObject, like this example:

QueryOver<Customer>; qu = QueryOver.Of<Customer>()
      .Where(c => c.CategoryId == 1);

This code throws a NHibernateException saying that “could not resolve property: Category.Id of : MyNamespace.Customer”, suggesting to verify the mapping as property “Category.Id” could not be found”.

Obviously such a property doesn’t exist at all, it’s only the QueryOver API that concatenates the Navigation property and and its field named Id (in this example).

This means that: you cannot make a query with QueryOver API that refers to fields belonging to a navigation property in where clause….without explicitly defying a join between the object itself and its navigation property. An example will help to understand better.

Category cat = null;
QueryOver<Customer> query = QueryOver.Of<Customer>()
 .JoinAlias(x => x.Category, () =>; cat)
 .Where(x => cat.Id == 1);

I have defined a join with the JoinAlias method, which uses an alias (the Category object declared two rows before) to project the object under the navigation property. After that you can use this alias inside the others method (such as “Where” in this example) to refer to the navigation property field (cat.Id).

As you can see, the way you write the lambda expression inside a Linq provider’s where clause is quite different than the “”Where” condition of a QueryObject object.

Not even the logical operator “And” can be used in the same way. To apply this logical operator to the “where” filter you have to use the “And” method, as shown here:

Category cat = null;
QueryOver<Customer> query = QueryOver.Of<Customer>()
   .JoinAlias(x => x.Category, () => cat)
   .Where(x => cat.Id == 1)
   .And(x => cat.IsEnabled);

Pluralisation services in .Net Framework

Starting from .Net Framework version 4.0 developers have available a new service for converting a single word from singular to plural form, or from plural to singular form.

I’m talking about the class PluralizationService contained in namespace System.Data.Entity.Design.PluralizationServices in assembly System.Data.Entity.Design.

it’s very simple to use it:

string plural = System.Data.Entity.Design.PluralizationServices
        .PluralizationService.CreateService(new System.Globalization.CultureInfo("en-US"))
// returns "dresses";


string singular = "woman";
string plural = System.Data.Entity.Design.PluralizationServices
         .PluralizationService.CreateService(new System.Globalization.CultureInfo("en-US"))
// returns "women";

I don’t know how reliable a translation service inside a framework can be, but it’s use can be very useful.

Be careful because the only supported culture is “English” (so far). Then if you call the service with another culture, i.e. Italian (it-IT), you end up with a NotImplementedException, as shown here:

Technorati Tags: ,

Dynamic build of generics types at runtime

How to create dynamically a type in .Net when it’s only known a string representation of that type, I think it’s an operation known to almost all .Net programmers, but what happened with types with type parameters (or generics) ?

In .Net is possible to create dynamically both generics with a known type, i.e. List<>, and generics with type in turn dynamically built.

Here’s an example:

a) Dynamic generated both type parameter and type

Type collectionType = Type.GetType("System.Collections.Generic.List`1, mscorlib");
if (collectionType == "null")
    throw new InvalidOperationException("Invalid type");
Type genericType = Type.GetType("MyNamespace.MyType, MyAssembly");
Type listWithGeneric = collectionType.MakeGenericType(genericType);
var myList = Activator.CreateInstance(listWithGeneric) as IList;

b) Dynamic generated type parameter with a known type (System.Collection.Generic.List in this case):

Type genericType = Type.GetType("MyNamespace.MyType, MyAssembly");
Type listWithGeneric = typeof(List<>).MakeGenericType(genericType);
var myList = Activator.CreateInstance(listWithGeneric) as IList;
Technorati Tags: ,,

[ASP .NET] How to access Request data when HttpContext.Current.Request is unavailable

What happened if you need to access the HttpRequest object whitin the event Application_Start of an ASP .NET Web Application ?

Response: you end up with an exception.

Someone might observe that such event is not a valid place for a task like that, but sometimes things are simply different from those that appear at first sight.

So, if you want to get for example the virtual path or the physical path of a web application before the HttpRequest object is constructed  this is a valid solution:


Simply use HttpRuntime instead of HttpContext.Current.Request!

Technorati Tags: ,

How to enable Visual Studio Intellisense for NHibernate configuration files

If you are an NHibernate’s user and you want to benefit of the Intellisense support during the editing of its configuration files in Visual Studio 2010 environment, just copy these 2 files: nhibernate-configuration.xsd and nhibernate-mapping.xsd,  from the NHibernate zip into the following folder:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas

where C:\Program Files (x86)\Microsoft Visual Studio 10.0 is your Visual Studio 2010 installation folder.

Technorati Tags: ,

Javascript code block formatting

For those who develop applications using C# or Javascript, but I think Java too, (I’m not a Java developer and then I don’t know if what I’m going to say is true for them as well) ,  there are two kind of writing styles for indentation and code’s blocks formatting .

These styles, known as K&R (Kernighan & Ritchie) style and Allman style, concern the way the opening curly brace is opened, when defining a block of code.

The former places the brace in the same line as the preceding line of code, as you can see in this example:

return {
   name: "Joe"

the latter places the curly brace in its own line, as shown here:

        name: "Joe"

So, the question is:

Can I use both of these styles or not when writing code ?

The answer is: yes, except for Javascript code.

In Javascript you must always use the K&R style if you want to avoid some subtle bugs that may be very difficult to identify.

For example, if you used the code in Allman style showed below

the return value would be “undefined” and not an object as expected, because the browser insert a semicolon after the word “return”.

If the code below had written in K&R (Kernighan & Ritchie) style:

as shown in first example, the return value would have been an object as expected.

Tag di Technorati: ,

Raven2Go posts editor portable application

Raven2Go is a valid alternative to blog posts editor much more famous like Word or Windows Live Writer, and it can even be installed as a portable application in a USB pen drive, feature very useful for people who often move from one pc to another.

Main features are:

  • Tabbed true WYSIWYG Editing
  • Manage multiple media storage services
  • Improved content management
  • Manage multiple blogs offline
  • WordPress 2.2+ Page & Tag support


Powered by Zoundry Raven

HeidiSQL – Free portable client for Sql server and MySql

Free portable client for Sql server and MySql.

This is the software I always needed!


Entity Framework for Oracle is dependent by an environment variable

Those who using Entity Framework Provider for Oracle have certainly already run into this issue, i.e., the proper functioning of this provider depends on an environment variable! It’s a bit strange, but it’s the truth.

If you forget (or if you simply don’t know) to setup an environment variable named “TNS_ADMIN” which contains the full path used by Oracle software to search for the “tnsnames” file, which in turn is used for reading the necessary parameters to establish a connection to the database server, attempting to open a connection will fail.

After setup the environment variable you have to reboot Visual Studio, if already opened, in order to apply the change.

After applying the environment variable if you try to create a new Oracle connection using the Visual Studio wizard, if all is working fine you will see the list of the tnsnames file entries in the data source dropdown list instead of a blank list.

Also, this environment variable needs only to Entity Framework for Oracle, as other software, like Toad for example, doesn’t need it to search for tnsnames files.

You can obtain the same result by adding a registry key, but it’s certainly easier to create an environment variable than modifying the registry.

Hope this helps.

Coding Horror #2

Some time ago I started writing a series of blog post (only one for precision) about some “absurd” code I meet in my daily work.

I called this series “Coding horror”, and, so far I have written only one post, this one.

This is the second one.

About the code below, I thing that every comment is unnecessary because it speaks for itself.

if (myVar == null)
    return myVar = null;

As an additional reason, the Resharper tooltip about the row number 2 is:

“Destination has the same value before assignment”.

It could not be much clearer than that.

Technorati Tags:

WCF 4.0 and its defaults

The default endpoint and default binding provided by WCF 4.0 are obviously great features that can save developing and testing time, but sometimes this conventional configuration don’t help in case you have some trouble with certain setting that doesn’t work.

The setting I mean in this case concern the Windows Authentication over HTTP.

To enable this setting you have only to configure the basic http bindings with a specified security mode, and then, obviously, configure the IIS authentication for the site/virtual directory that host your service to enable Windows Authentication and disable Anonymous access.

If you make this two simple change, you end up with an ASP .Net error page which says this:

“Security settings for this service require Anonymous Authentication, but it is not enabled for the IIS application that hosts this service”,

that is to say that the Windows Authentication isn’t working and the service requires Anonymous Authentication that is not enabled and then here’s the error.

Why although the configuration is it not working? Because you have not specified a binding for your service, and then the default binding comes into play, and the default binding requires Anonymous Authentication, which is not enabled.

The next logical step is to provide a specific binding configuration,  which maps the binding named “BasicHttpEndpointBinding” defined early with your service.

But when you run the service the error is always the same. What’s wrong with this configuration ?

The problem here is the service name you provided. This name must match with the service name written inside the .svc file of your service. If this name doesn’t match, the explicit binding configuration doesn’t match with those provides by your service as well, and then you fall into the default binding behavior again.

Otherwise, if the service name matches everything works fine.

Moral of the story: “Pay always attention to the default values of any configuration”!

Web services Contract First development is a great tool for developing web services in a Contract First mode.

Develop in such a way means that you start from a WSDL contract that describes everything is concerned with a web service, and only after that you can write code which  that contract is based on.

Working with a WSDL can be a very error-prone task because a WSDL is a XML file. The tool is able (among other things) building the server code you need from that file.

But this tool is also useful in some particular scenario where you have to change the web service code that “answers” to a particular call. I will explain it better.

Imagine you have a old application using a old web service developed by a third part, and you don’t have the source code of that service. What if you have to rewrite the web service for changed requirements without affecting the application which use it by simply changing the service’s url in configuration files ?. in other words, it needs to create another web service’s implementation without changing the WSDL in any way. In this case can greatly save your time recreating the server code starting from the WSDL input, and with this server code you can write the new implementation. At this point you can just change the url of the service in application which was using the old implementation.

As unit test, it is possible to add a proxy reference to the old implementation of the service. After that you can create a new instance of the service by the proxy, change the url property and invoke methods and obviously the new service’s implementation at the new url will respond.

How to debug Log4Net

If you use Log4Net as log engine for your applications (in my opinion is the best choice), this simple row in application configuration file can save you by a waste of time and probably by a headache too.

When Log4Net doesn’t log anything due to a configuration error it never throw an exception, and this is the expected (and correct) behavior of a log system which should never block an application due to its internal error. Unfortunately when something went wrong it is quite difficult discover the reason if you don’t have a break in your code.

With that configuration instruction Log4Net “logs” its initialization process in output windows and in Trace system.

If you add a trace listener you can also save this output in a file.

Here’s an example:

This is very useful in production environment where Visual Studio is not installed and then an output window is not available.

Technorati Tags: ,

Entity Framework #3–my scattered notes

When using Entity Framework 4.x Code First you can put your validation code in Data Annotations or inside the DbContext class (this is my preferred mode).

It’s possible to override the virtual method ValidateEntity exposed by the DbContext class and then define your own validation logic in one place.

This method is called once for each distinct entity being modified in your context, and it provides an opportunity for developers to stop the entity update process when some properties are in invalid state.

Here’s an example:

This code will be invoked only if the “ValidateOnSaveEnabled” property of the class DbContextConfiguration is set to true.

Entity Framework #2–my scattered notes Part 2

This is my second post about my Entity Framework Code First usage experience. You can find my first post here.

The Entity Framework Power Tool is a must-have tool for those who use EF in Code First mode, especially with fluent API. With this tool you can reverse-engineering an existing data source and then generate both domain classes (POCO) and the mapping configuration files. The latter are generated by creating a class which inherits from EntityConfiguration<T>, where T is your domain entity type. The tools is able to understand all the existing relations in the database and to transform them in the correct relation mapping in code.