Remote object URL fails from hardcoded string but works from appsettings - very odd

Remote object URL fails from hardcoded string but works from appsettings - very odd

Old forum URL: forums.lhotka.net/forums/t/3347.aspx


phillipjohnson posted on Wednesday, August 08, 2007

I have a dll that uses Rocky Lhotka's CSLA.  The CSLA relies on some settings in an app.config for remoting but my dll is not used by one of my apps so I have no control over the app.config.

The point where the string is set with the url of the remote object is:

string data = ConfigurationSettings.AppSettings["PortalServer"];

and the setting in app.config is:

<add key="PortalServer" value="http://localhost/RemotingTest2/dataportal.rem" />

BUT when I change the initialization of the string to be hardcoded rather than from appsettings, like this:

string data = "http://localhost/RemotingTest2/dataportal.rem";

I get this error at the point the code tries to create the remote object:

"The Type System.Xml.XmlDocument in Assembly System.Xml, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 is not marked as serializable."

If I switch the line back to the original one getting the url from the appsettings, it all works again..... This is the only thing I am changing and it works every time from appsettings but never when I hardcode the string!

I have tried escaping the string and casting it to a string etc, like this:

string data = (string)@"http://localhost/RemotingTest2/dataportal.rem".ToString();

and every time, the string variable looks exactly the same as setting it from the appsettings but I get the error when the url is hardcoded.

This is a real showstopper for me, so I would really appreciate any help that anybody can give me.

I even emailed Rocky himself but he could not think of why it could be happening.

Thanks.

--
Regards,

Phil Johnson (MCAD)

JoeFallon1 replied on Wednesday, August 08, 2007

There should be 2 config files involved. One on the web server and one on the remoting server.

Did you change the settings for both of them?

Joe

 

phillipjohnson replied on Thursday, August 09, 2007

Hi Joe,

Thanks for the response.

This is where my problems start... I am creating a dll with shell namespace extensions (i.e. a plugin for internet explorer) so on the client, the dlls will run in the process of explorer.exe (i.e. Windows Explorer). 

The dll is expecting to find the settings in explorer.exe.config.... I really want to avoid creating a one (or modifying one if one already exists when deployed on the client) so I was looking to either hardcode the urls for the remoting config or change the CSLA dll to use a resource file for the settings rather than the appsettings.

Every time I cahnge the code though that gets the setting from appsettings, or even modify that static property, I get the XmlDocument serialization error.  But when I change it back, or comment out the changes, it works!

The strange thing is... if I get the setting from appsettings, but then return a hardcoded string, the code works.... but the instant I comment out the line that gets the appsetting I get the error.

Strangest behaviour I have ever seen.

At least I have the fallback of creating an explorer.exe.config file I suppose.

If anybody can think of anything that could make this change work though, please let me know.

Thanks,

Phil.

RockfordLhotka replied on Thursday, August 09, 2007

Is it possible that your hardcoded string is then also being used on the app server?

Normally the app server wouldn't have any data portal config values set, so it would run in local mode. But if you are hardcoding the values, and deploying your assembly to both client and server, then the server might be in some sort of nasty loop because it would also be configured for remote data portal calls.

Also, are you testing inside or outside of IE? Are you aware of the special serialization issues you encounter when hosting in IE (similar to those in COM+ or other hosts)?

Copyright (c) Marimer LLC