Imagine a situation. You have a big solution and it is already deployed. Then one day, you get to hear about an issue with one of the function implementation in one of the DLLs which required you to change type of a property. The change is not as drastic as changing an integer to string or vice versa. Rather it requires you to change type of a property from integer to double or double to integer.
We will consider change from integer to double for now. The solution compiles just fine and it looks like you are good to deploy the modified dll on running environment as there is no change in the other components that use this property. What happens next :)? For illustration, I created a Class Library named "ClassLibrary1" which has a class "Class1".
It works just fine. Now you can change the type of property "MyProperty" to double and drop the compiled dll in the bin of "NewConsoleApplication". If you run the exe, you start to encounter weird error:
Method not found. Void set_MyProperty (Int32).
But you already changed the DLL. There is no property of type integer anymore. Why is someone trying to look for integer type?
The reason is simple. The IL code generated in NewConsoleApplication assumes that the property is still Integer and has its own IL code generated like that e.g. the code required to multiply casts the MyProperty to double before multiplying.
So, there is the mystery.
Lesson: if there is a type change in one component, calling assemblies should be regenerated and replaced even if they have no change in their own code.
We will consider change from integer to double for now. The solution compiles just fine and it looks like you are good to deploy the modified dll on running environment as there is no change in the other components that use this property. What happens next :)? For illustration, I created a Class Library named "ClassLibrary1" which has a class "Class1".
public class Class1
{
public int MyProperty { get; set; }
}
I have another component "NewConsoleApplication" which has following method:
class Program
{
static void Main(string[] args)
{
double doubleValue = 0.4f;
var c = new ClassLibrary1.Class1() { MyProperty = 100 };
Console.WriteLine(doubleValue
* c.MyProperty);
}
}
It works just fine. Now you can change the type of property "MyProperty" to double and drop the compiled dll in the bin of "NewConsoleApplication". If you run the exe, you start to encounter weird error:
Method not found. Void set_MyProperty (Int32).
But you already changed the DLL. There is no property of type integer anymore. Why is someone trying to look for integer type?
The reason is simple. The IL code generated in NewConsoleApplication assumes that the property is still Integer and has its own IL code generated like that e.g. the code required to multiply casts the MyProperty to double before multiplying.
double num = 0.40000000596046448;
Class1 @class = new Class1();
@class.set_MyProperty(100);
Class1 class2 = @class;
Console.WriteLine(num * (double)class2.get_MyProperty());
Class1 @class = new Class1();
@class.set_MyProperty(100);
Class1 class2 = @class;
Console.WriteLine(num * (double)class2.get_MyProperty());
So, there is the mystery.
Lesson: if there is a type change in one component, calling assemblies should be regenerated and replaced even if they have no change in their own code.