代码之家  ›  专栏  ›  技术社区  ›  Behrooz

TypeLoadException是如何发生的?

  •  0
  • Behrooz  · 技术社区  · 16 年前
    public sealed class SurrogateSelector : System.Runtime.Serialization.SurrogateSelector, System.Runtime.Serialization.ISurrogateSelector
    {
        System.Runtime.Serialization.ISerializationSurrogate ISS = System.Runtime.Serialization.FormatterServices.GetSurrogateForCyclicalReference(new SerializationSurrogate());
        public SurrogateSelector()
        {
            foreach (Type t in typeof(NameSpace.ASampleClass).Assembly.GetTypes())
            {
                if (t.Namespace == "NameSpace")
                    this.AddSurrogate(t, new System.Runtime.Serialization.StreamingContext(System.Runtime.Serialization.StreamingContextStates.All), ISS);
            }
        }
    }
    

    {System.Reflection.ReflectionTypeLoadException:反射类型: 请求的类型。检索 详细信息的LoaderExceptions属性 信息。在 System.Reflection.Module.\u GetTypesInternal(堆栈爬网标记& System.Reflection.Assembly.GetTypes() 在里面 D:\Projects\Esfand\Esfand\classname.cs:行

    1 回复  |  直到 16 年前
        1
  •  0
  •   João Angelo    16 年前

    确保正确定义了所有外部。如果CLR找不到您定义的外部方法的实现,它将无法加载类型。

    例如,如果你定义了一个方法,

    public static extern IntPtr SendMessage(IntPtr w, uint m, IntPtr p1, IntPtr p2);
    

    [DllImport("user32.dll")] 在上面。每个 TypeLoadException 应该告诉找不到实现的方法。