C# – “Type is not resolved for member” SerializationException in Connection.get_LocalIP() RESOLVED!

Running a web application in the VS 2008′s built in localhost webserver using a custom IIdentity (but not a custom IPrincipal) that you set to the Thread.CurrentPrincipal using a GenericPrincipal causes an exception begining with “Type is not resolved for member” to be thrown when accessing Microsoft.VisualStudio.WebHost.Connection.get_LocalIP().

To resolve this, for your custom IIdentity class add the Serializable attribute, ComVisible(true) attribute, and make it inherit from MarshalByRefObject.

I don’t know exactly why this works, but it does.

One Response to “C# – “Type is not resolved for member” SerializationException in Connection.get_LocalIP() RESOLVED!”

  1. jmorris Says:

    Funny, I just ran into this. It actually happens when you assign the IPrincipal implementation to the Thread.CurrentPrincipal property. Setting the Context.User field is fine, however. It also only failed in my case when I called the Page.ClientScript.GetCallbackEventReference method!

    I tried your suggestion with the ComVisible and deriving from MarshalByRefObject and then ran into trouble with serialization/deserialization using the DataContractJsonSerializer. I stopped short there and just removed the Thread.CurrentPrincipal = principal code, since this is a cassini specific error and I’ll be on IIS next week.

    -Jeff

Leave a Reply