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:\项目\ Esfand \ Esfand \ classname.cs:行   2661}

有帮助吗?

解决方案

请确保所有实习医生正确定义。 CLR将无法加载类型,如果它不能找到你所定义的外部方法的实现。

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

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

请确保您使用[DllImport("user32.dll")]就可以了。每个TypeLoadException应该告诉对于没有执行发现的方法。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top