I understand that there are basically two different kinds of dependencies in C#: Those needed for compiling and those needed to run. While it is pretty obvious that building/compiling fails when there are missing references, it is not that clear to me how an application might still break at runtime because of missing or mismatching dependencies at runtime.
CodePudding user response:
There are basically two possibilities.
1 Missing dependency at runtime
If you compile your application against a dependency (mostly an Assembly as a .dll file), but you do not have it on the machine / folder where your application runs, it will fail at runtime.
Example: You have a .dll in your source folder but forgot to copy it to the output filder.
2 Version incompatibility
If you compiled your application against a dependency with Version A and at runtime it uses Version B, it might fail if the methods you are calling are incompatible or missing. This will result in a MissingMethodException
Example: The method at compile time looks like this Foo(string bar)
, but the method at runtime looks like this Foo(string bar, string baz)
.