2

Lets say the type static class MyClass fails to load during AppDomain.AssemblyLoad. Maybe the class contains a static property which reads the connection string from the config. Will further references to types in said DLL cause AppDomain.AssemblyLoad to attempt to re-load the DLL?

In other words, will AppDomain.AssemblyLoad retry a DLL that has previously failed to load?

4

2 回答 2

4

so will it reload again for further calls on some methods on that class?

No. If type initialization fails for a particular type, that type is effectively useless throught the lifecycle of the AppDomain. Any further attempt to use the type will simply throw the same TypeInitializationException again immediately, without retrying. Avoid fallible type initialization wherever possible.

If you create a new AppDomain then that will try to initialize the type again.

于 2013-11-11T16:31:13.680 回答
0

For sure not, if design of your class does not do that.

For example if for every method access you check either class was initialized or not, and if not initialize it, you can actually simulate that behavior.

But, to be honest, it's not so good design pattern.

于 2013-11-11T16:34:05.863 回答