How Type.GetType works when given partially qualified type name?

前端 未结 5 943
谎友^
谎友^ 2020-11-30 13:50

In numerous places do I encounter partially qualified type names of the form FullTypeName, AssemblyName, i.e. like Type.AssemblyQualifiedName only

5条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 14:21

    Having just gone through a similar issue with some legacy code, I don't think that the first statement in the accepted answer is correct. It doesn't matter whether or not the assembly is already loaded.

    According to the documentation, Type.GetType(string) requires an AssemblyQualifiedName, unless the type in question is in the currently executing assembly or in mscorlib, in which case the namespace-qualified type name is all that is required.

    Note that an AssemblyQualifiedName includes the full DisplayName of the type's assembly (with version, culture and public key token).

    The short version won't work unless you intercept the failed type load with a custom AssemblyResolver (which was actually the case with my issue, masking another problem).

提交回复
热议问题