Assembly Loader Error

System.IO.FileLoadException: Could not load file or assembly ‘NLog, Version=2.1.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Jika suatu saat anda mendapat error seperti di atas, artinya assembly loader tidak menemukan assembly yang di reference. Ternyata untuk kasus saya, di app.config ternyata mereference assembly version yang berbeda.

<dependentAssembly>
    <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
 </dependentAssembly>

Ada 2 cara untuk menyelesaikan issue ini.

  1. hapus configurasi tersebut di app.config
  2. Kita paksa untuk semua version tertentu dalam kasus ini versi .4.0.0.0 di redirect ke version 2.1.0.0.
<dependentAssembly>
     <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
     <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="2.1.0.0" />
</dependentAssembly>

 

Pemrograman Beriorentasi Object Menggunakan Javascript (Part II)

  1. Menggunakan Module Pattern Object Literal

Object Literal digambarkan dalam kumpulan comma-separated name/value pairs yang diapit oleh curly braces ({}). Object literal tidak memerlukan instanisasi.

ar myObjectLiteral = {

variableKey: variableValue,

functionKey: function () {
// ...
}
};

var personModule = {

name: "nila",

// object literals can contain properties and methods.
// e.g we can define a further object for module configuration:
dob: {
place: "campalagian",
date: "10-10-1990"
},

// a very basic method
saySomething: function () {
console.log( "hello!!" );
},

// output a value based on the current configuration
showName: function () {
console.log( "my name is " + this.name );
},

// override the current configuration
updateDob: function( newDob ) {

if ( typeof newDob  === "object" ) {
this.dob = newDob;
console.log( this.dob.place);
}
}
};

// Outputs: hello!!
personModule.saySomething();

// Outputs: my name is nila
personModule.showName();

// Outputs: semarang
personModule.updateDob({
place: "semarang",
date: "10-10-1990"
});

Pemrograman Beriorentasi Object Menggunakan Javascript (Part I)

Hampir semua programmer tidak asing dengan pradigma pemrograman beriorentasi object (OOP), jadi tidak perlu saya jelaskan lagi di sini. Kebanyakan bahasa pengantar untuk mata kuliah OOP adalah java atau c++. Bagaimana dengan OOP menggunakan javascript??  yang terbiasa menggunakan javascript di sisi server seperti Node JS atau framework javascript di sisi client seperti AngularJS atau Backbone.Js tentu akan menjadi penting. Ok, mari kita mulai!..

  1. Menggunakan Prototype-based programming.

Javascript adalah sebuah prototype-based language, jadi kita tidak akan menemukan statement class seperti pada bahasa yang lain (Java, C++, C#..). Fungsi-fungsi pada Javascript memiliki property yang disebut “prototype”.  Berikut contoh membuat class menggunakan pendekatan Prototype.

function Person(name, age) {
 this.name = name;
 this.age = age;
}
Person.prototype = {
 getName: function() {
   return this.name;
},
 getAge: function() {
  return this.age;
}
}

instanisasi class person tersebut dengan cara seperti ini.

var alice = new Person('Alice', 93);
var bill = new Person('Bill', 30);
console.log(alice.getName()); //result is "Alice"
console.log(alice.getAge()); //result is "93"

Dengan mengakses prototype class person di atas bisa juga ditulis seperti ini:

Person.prototype.getName = function(){
return this.name;
};Person.prototype.getAge = function(){
return this.age;
};