Click here to Skip to main content
15,915,777 members
Home / Discussions / C#
   

C#

 
QuestionHow to get what are all the objects created at runtime using c#.net Pin
kiranchandu616-Nov-05 21:34
kiranchandu616-Nov-05 21:34 
AnswerRe: How to get what are all the objects created at runtime using c#.net Pin
Mark Hahn CA17-Nov-05 13:41
Mark Hahn CA17-Nov-05 13:41 
AnswerRe: How to get what are all the objects created at runtime using c#.net Pin
Robert Rohde17-Nov-05 20:01
Robert Rohde17-Nov-05 20:01 
Question[.net 2.0] PropertyGrid - DropDown-ComboBox Pin
suamikim16-Nov-05 21:09
suamikim16-Nov-05 21:09 
QuestionNew Web Control Additional Code Pin
Brendan Vogt16-Nov-05 18:59
Brendan Vogt16-Nov-05 18:59 
QuestionC# Right and Left Methods Pin
Brendan Vogt16-Nov-05 18:41
Brendan Vogt16-Nov-05 18:41 
AnswerRe: C# Right and Left Methods Pin
jonny516-Nov-05 19:02
jonny516-Nov-05 19:02 
QuestionInvalidCastException thrown in Service code but not in Form code Pin
Jasejc16-Nov-05 11:51
Jasejc16-Nov-05 11:51 
This is truly a wierd phenomenon. So I have this service that is going to backup files in realtime that get dumped into folders specified by the user. The user specifies various information for this service to use through a Windows.Forms GUI. That GUI uses a BinaryFormatter to both serialize the data into a file when the user exists the GUI, and deserialize that data when the GUI is opened again to load the data into the GUI. This works fine...no errors and it functions as expected.

So I need my service to deserialize the same information from the file so it can do its thing given the settings the user set up right? Well I use practically the same approach that I used for the GUI, but in the service for some reason there is an explicit cast that causes a InvalidCastException to be thrown at runtime...This SAME cast does not throw an exception in the Forms GUI. Any ideas? Here is two snippets of code from the GUI and the Service. The explicit cast that causes the problem in the Service but not the GUI is the cast from the object "item" to an object of type OffSiteBackupServiceNamespace.Location.

Note: fs is a filestream linked to the data file generated by the GUI

GUI code (no compile time or run time errors):
<br />
Object item = formatter.Deserialize(fs);<br />
...<br />
if(item.GetType().ToString().Equals("OffSiteBackupServiceNamespace.Location"))<br />
					{<br />
						locations.Add((OffSiteBackupServiceNamespace.Location)item);<br />
						addLocationSaveToView();<br />
					}<br />


Service code (no compile time errors, throws runtime InvalidCastException):
<br />
Object item = formatter.Deserialize(fs);<br />
...<br />
if(item.GetType().ToString().Equals("OffSiteBackupServiceNamespace.Location"))<br />
					{<br />
						//check if location is an active location? <br />
						//then use it as a connection for the previous watchers<br />
						//the code below throws the InvalidCastException<br />
						if(((OffSiteBackupServiceNamespace.Location)item).Checked)<br />
						{<br />
							saveToLocations.Add((OffSiteBackupServiceNamespace.Location)item);<br />
							this.myEventLog.WriteEntry("Active Location read: " + <br />
								((OffSiteBackupServiceNamespace.Location)item).ToString());<br />
						}<br />
					}<br />


thx,
jason
QuestionSocket / Network Stuff question Pin
Tom Wright16-Nov-05 10:00
Tom Wright16-Nov-05 10:00 
QuestionCheckBox(es) with a number attached? Pin
naglbitur16-Nov-05 9:47
naglbitur16-Nov-05 9:47 
AnswerRe: CheckBox(es) with a number attached? Pin
mav.northwind16-Nov-05 10:03
mav.northwind16-Nov-05 10:03 
QuestionHide the application from the process list? Pin
Wronex16-Nov-05 9:15
Wronex16-Nov-05 9:15 
AnswerRe: Hide the application from the process list? Pin
Dan Neely16-Nov-05 9:55
Dan Neely16-Nov-05 9:55 
AnswerRe: Hide the application from the process list? Pin
Dave Kreskowiak16-Nov-05 16:39
mveDave Kreskowiak16-Nov-05 16:39 
QuestionHow to Send XML to an ASP page? Pin
v9316-Nov-05 9:09
v9316-Nov-05 9:09 
AnswerRe: How to Send XML to an ASP page? Pin
Rob Philpott16-Nov-05 12:21
Rob Philpott16-Nov-05 12:21 
GeneralRe: How to Send XML to an ASP page? Pin
v9317-Nov-05 0:27
v9317-Nov-05 0:27 
QuestionBad programming ethics Pin
eggie516-Nov-05 9:03
eggie516-Nov-05 9:03 
AnswerRe: Bad programming ethics Pin
jonny516-Nov-05 20:41
jonny516-Nov-05 20:41 
QuestionAssembley error loadign Pin
webhay16-Nov-05 8:56
webhay16-Nov-05 8:56 
QuestionMDI - Child in foreign app Pin
franzz16-Nov-05 8:22
franzz16-Nov-05 8:22 
AnswerRe: MDI - Child in foreign app Pin
Dave Kreskowiak16-Nov-05 8:38
mveDave Kreskowiak16-Nov-05 8:38 
GeneralMDI - Child in foreign app Pin
franzz16-Nov-05 8:42
franzz16-Nov-05 8:42 
Questionc# and sql Pin
vandread116-Nov-05 7:41
vandread116-Nov-05 7:41 
AnswerRe: c# and sql Pin
mikanu16-Nov-05 8:42
mikanu16-Nov-05 8:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.