views:

141

answers:

1
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: 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}

A: 

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.

João Angelo