0
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._GetTypesInternal(StackCrawlMark& stackMark) 在 System.Reflection.Assembly.GetTypes() 在 NameSpace.SurrogateSelector..ctor() 在 D:\Projects\Esfand\Esfand\classname.cs:line 2661}

4

1 回答 1

0

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

例如,如果您定义一个方法,例如,

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

确保你使用[DllImport("user32.dll")]它。每个都TypeLoadException应该告诉没有找到实现的方法。

于 2010-03-18T11:52:31.240 回答