.Net: Running code when assembly is loaded

后端 未结 6 513
不思量自难忘°
不思量自难忘° 2020-11-27 05:02

Is it possible to run some code when an assembly is loaded, without doing anything specific in the loading code? What I am looking for is like a static constructor on a type

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 05:20

    You should probably revisit your serialization approach to mitigate this problem. If you serialize using ISerializable and the SerializableAttribute attribute, you can make it such that the serialization graph will load assembly B when necessary without assembly A ever having to explicitly know about assembly B.

提交回复
热议问题