开发者

how does a TypeLoadException Happen?

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.N开发者_JS百科amespace == "NameSpace")
                this.AddSurrogate(t, new System.Runtime.Serialization.StreamingContext(System.Runtime.Serialization.StreamingContextStates.All), ISS);
        }
    }
}

{System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark) at System.Reflection.Assembly.GetTypes() at NameSpace.SurrogateSelector..ctor() in D:\Projects\Esfand\Esfand\classname.cs:line 2661}


Make sure that all externs are correctly defined. The CLR will be unable to load the types if it cannot find the implementation for the external methods you defined.

For example if you define a method like,

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

make sure that you use the [DllImport("user32.dll")] on it. Each TypeLoadException should tell the method for which no implementation was found.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜