Unable to cast object of type 'FormData' to type 'FormData'.

A

Andrus

When I try to open any of my Windows form in VS2008 windows form designer
which is based my Baseform class I got error

Unable to cast object of type 'FormData' to type 'FormData'.

Error message points to the method
public static T Load<T>(string id) where T : class {

IsolatedStorageFile store = IsolatedStorageFile.

GetUserStoreForAssembly();

Stream stream;

try {

stream = new IsolatedStorageFileStream(FileName(typeof(T), id),

FileMode.Open, store);

} catch (System.IO.FileNotFoundException) {

return null;

}

error line is

stream = new IsolatedStorageFileStream(FileName(typeof(T), id),

FileMode.Open, store);



This method is called from my base form Load event.

How to fix ?

Andrus.


Call Stack:

at MyApp.UserSettings.Load[T](String id) in
I:\MyApp\0 Util\Serialization.cs:line 107
at
MyApp.Windows.Forms.BaseForm.RestoreWindowState()
at
MyApp.Windows.Forms.BaseForm.BaseForm_Load(Object sender, EventArgs
e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean
fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.OnVisibleChanged(EventArgs
e)
at
System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Form.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.SetVisibleCore(Boolean
value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Design.DesignerFrame.Initialize(Control view)
at
System.Windows.Forms.Design.DocumentDesigner.Initialize(IComponent
component)
at
System.Windows.Forms.Design.FormDocumentDesigner.Initialize(IComponent
component)
at
System.ComponentModel.Design.DesignerHost.AddToContainerPostProcess(IComponent
component, String name, IContainer containerToAddTo)
at
System.ComponentModel.Design.DesignerHost.Add(IComponent component, String
name)
at
System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(Type
componentType, String name)
at
System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance(Type
type, ICollection arguments, String name, Boolean addToContainer)
at
System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.CreateInstance(Type
type, ICollection arguments, String name, Boolean addToContainer)
at
System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager
manager, CodeTypeDeclaration declaration)
at
System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager
manager)
at
Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager
serializationManager)
at
Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32
fReload)
 
P

Peter Duniho

When I try to open any of my Windows form in VS2008 windows form designer
which is based my Baseform class I got error

Unable to cast object of type 'FormData' to type 'FormData'.

You haven't posted nearly enough code for a specific answer to be
provided. I don't see anything, for example, that actually is casting
anything so whatever the exception says it doesn't appear to match the
code you've provided.

That said, the error you're describing sounds a lot like a case of having
two different types using the same name, declared in two different
places. Assuming that's the case, the fix is to make sure that when you
instantiate a FormData object, you are always using the same assembly as
the reference for the type.

If that doesn't help, you need to post a concise-but-complete sample of
code that reliably demonstrates the problem.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top