DesignerSerializer code throws exception duering design time

DesignerSerializer code throws exception duering design time

Post by Doron Neuman » Thu, 06 Mar 2003 21:00:23



I have this design-time code I wrote for my CF component.
When I add a custom designer serialized I get the following exception when
trying to set one of its properties through the designer: Invalid Property
value. Details: Specified cast not valid.
if I remove the DesignerSerializer attribute, everything works fine.
When trying to debug the code, and setting breakpoints in the Serialize and
Deserialize functions, I see that they aren't even being called.

Maybe a MS bug? or maybe I am doing something wrong?
Thanks,
Doron.

Here are all the details of code:

////////////////////////////////////////////////////////
/// The Component /////////////////////////
/////////////////////////////////////////////////////
[DesignerSerializer(typeof(MyComponentSerializer),typeof(CodeDomSerializer))
]
 [
 ToolboxItemFilter("System.CF.Windows.Forms", ToolboxItemFilterType.Custom),
 ToolboxItemFilter("NETCF", ToolboxItemFilterType.Require)
 ]
 public class MyComponent : Component
 {
  private string myString;
  public string MyString
  {
   get
   {
    return myString;
   }
   set
   {
    myString = value;
   }
  }
 }

And the serialized looks like that and does nothing:

////////////////////////////////////////////////////////
/// The DesignerSerializer /////////////////////////
/////////////////////////////////////////////////////
 internal class MyComponentSerializer: CodeDomSerializer
 {
  public override object Deserialize(IDesignerSerializationManager manager,
object codeObject)
  {
   CodeDomSerializer baseSerializer =
    (CodeDomSerializer)manager.GetSerializer(
    typeof(MyComponentSerializer).BaseType,
    typeof(CodeDomSerializer));
   return baseSerializer.Deserialize(manager, codeObject);
  }
  public override object Serialize(IDesignerSerializationManager manager,
object value)
  {
   CodeDomSerializer baseSerializer =
    (CodeDomSerializer)manager.GetSerializer(
    typeof(MyComponentSerializer).BaseType,
    typeof(CodeDomSerializer));
   return baseSerializer.Serialize(manager, value);
  }
 }

The exception Stack trace (it happens somewhere in
Microsoft.VisualStudio.dll

microsoft.visualstudio.dll!Microsoft.VisualStudio.Designer.Serialization.Und
oManager.TakeSnapshot(System.Collections.ICollection undoEntries =
{System.Array},
Microsoft.VisualStudio.Designer.Serialization.UndoManager.UndoSnapshot
snapshot =
{Microsoft.VisualStudio.Designer.Serialization.UndoManager.UndoSnapshot}) +
0x4cd bytes

microsoft.visualstudio.dll!Microsoft.VisualStudio.Designer.Serialization.Und
oManager.UndoUnit.ComponentChanging(System.Object comp =
{OrsusCF.MyComponent}, System.ComponentModel.MemberDescriptor member =
{System.ComponentModel.ReflectPropertyDescriptor}) + 0x2ba bytes

microsoft.visualstudio.dll!Microsoft.VisualStudio.Designer.Serialization.Und
oManager.OnComponentChanging(System.Object sender =
{Microsoft.VisualStudio.Designer.Host.DesignerHost},
System.ComponentModel.Design.ComponentChangingEventArgs e =
{System.ComponentModel.Design.ComponentChangingEventArgs}) + 0x215 bytes

microsoft.visualstudio.dll!Microsoft.VisualStudio.Designer.Host.DesignerHost
.OnComponentChanging(System.Object component = {OrsusCF.MyComponent},
System.ComponentModel.MemberDescriptor member =
{System.ComponentModel.ReflectPropertyDescriptor}) + 0x83 bytes

system.dll!System.ComponentModel.ReflectPropertyDescriptor.SetValue(System.O
bject component = {OrsusCF.MyComponent}, System.Object value = "ddd") +
0x121 bytes

system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyD
escriptorGridEntry.SetPropertyValueCore(System.Object obj =
{OrsusCF.MyComponent}, System.Object value = "ddd", bool doUndo = true) +
0x140 bytes

system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyD
escriptorGridEntry.SetPropertyValue(System.Object obj =
{OrsusCF.MyComponent}, System.Object objVal = "ddd") + 0x48e bytes

system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyD
escriptorGridEntry.set_PropertyValue(System.Object value = "ddd") + 0x21
bytes

system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyG
ridView.CommitValue(System.Object value = "ddd") + 0x14b bytes

system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyG
ridView.CommitText(string text = "ddd") + 0xf1 bytes

system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyG
ridView.Commit() + 0xca bytes

system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyG
ridView._Commit() + 0xc bytes

system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyG
ridView.GridViewEdit.OnClickHooked() + 0x12 bytes
  system.windows.forms.dll!Mouse*.ProcessMouseDown(int hWnd = 198198,
int x = 156, int y = 713) + 0x15d bytes
  system.windows.forms.dll!Mouse*.MouseHookProc(int nCode = 0, int
wparam = 513, int lparam = 1243764) + 0xca bytes
  system.windows.forms.dll!Mouse*.MouseHookObject.Callback(int nCode =
0, int wparam = 513, int lparam = 1243764) + 0x66 bytes

 
 
 

DesignerSerializer code throws exception duering design time

Post by Benjamin Wul » Thu, 13 Mar 2003 09:06:32


This does not reproduce for me.  I do not see exactly what you are doing
incorrectly, but below is exact steps I took and got a working serializer
without an exception.
One thing you should know is that since you are creating a component, the
component can be tested on desktop as well to see if there is a bug
specific to the device designer.  You can do this by removing the
ToolBoxItemFilter attributes.
Here are the steps I took to attempt to reproduce your error:

1. Created a Desktop ClassLibrary Project in Everett RTM
2. Added System.Design to the reference list
3. Added System.CF.Design to the reference list
4. replace the code in class1.cs with:

using System;
using System.Design;
using System.ComponentModel.Design.Serialization;
using System.ComponentModel.Design;
using System.ComponentModel;
using System.Windows.Forms;

[assembly:System.CF.Design.RuntimeAssembly("")]

namespace test_comp
{
        [

DesignerSerializer(typeof(MyComponentSerializer),typeof(CodeDomSerializer)),
        ToolboxItemFilter("System.CF.Windows.Forms", ToolboxItemFilterType.Custom),
        ToolboxItemFilter("NETCF", ToolboxItemFilterType.Require)
        ]
        public class MyComponent : Component
        {
                private string myString;
                public string MyString
                {
                        get
                        {
                                return myString;
                        }
                        set
                        {
                                myString = value;
                        }
                }
        }

        ////////////////////////////////////////////////////////
        /// The DesignerSerializer /////////////////////////
        /////////////////////////////////////////////////////
        internal class MyComponentSerializer: CodeDomSerializer
        {
                public override object Deserialize(IDesignerSerializationManager manager,
                        object codeObject)
                {
                        CodeDomSerializer baseSerializer =
                                (CodeDomSerializer)manager.GetSerializer(
                                typeof(MyComponentSerializer).BaseType,
                                typeof(CodeDomSerializer));
                        return baseSerializer.Deserialize(manager, codeObject);
                }
                public override object Serialize(IDesignerSerializationManager manager,
                        object value)
                {
                        MessageBox.Show("Hello There!");
                        CodeDomSerializer baseSerializer =
                                (CodeDomSerializer)manager.GetSerializer(
                                typeof(MyComponentSerializer).BaseType,
                                typeof(CodeDomSerializer));
                        return baseSerializer.Serialize(manager, value);
                }
        }

}

5.  note that the "runtimeassemblyattribute" tells our designer that this
class is meant for design time -- so it will not be added to your solution
explorer reference list when you drag the control from the toolbox.  If the
string in this attribute contains a fully qualified assembly name, then
that assembly is added as a reference to your project.  
This is meant to point to your device assembly so that your code compiles.  
That is, you should have DeviceControl.dll and DesignTimeStuff.dll.  When
the control from DesignTimeStuff.dll gets added to your form, it will add a
reference to DeviceControl.dll so new code using your control will compile.

6.  I then created a PPC Winform project in the same solution, added the
item to the toolbox manually, and was able to set the string property and
got the "Hello There!" message during serialization.

Let me know if I can be of further help.  I usually refer people to 1 of
the following 2 links for design time support of device controls:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnne...
tml/customctrlscompactfx.asp
http://www.intelliprog.com/articles/index.html

since you are writing your own serializers, you are probably past these.

-Ben

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: "Doron Neumann"
<_no_spam_mail_remove_doron_I_mean_it@nospam_again_remove_orsus.com>
| Subject: DesignerSerializer code throws exception duering design time
| Date: Wed, 5 Mar 2003 14:00:23 +0200
| Lines: 134
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <uuWpP7w4CHA.1...@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 212.199.114.192
| Path:
cpmsftngxa08.phx.gbl!cpmsftngxa06!cpmsftngxa10!TK2MSFTNGXA05.phx.gbl!TK2MSFT
NGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa08.phx.gbl
microsoft.public.dotnet.framework.compactframework:18347
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| I have this design-time code I wrote for my CF component.
| When I add a custom designer serialized I get the following exception when
| trying to set one of its properties through the designer: Invalid Property
| value. Details: Specified cast not valid.
| if I remove the DesignerSerializer attribute, everything works fine.
| When trying to debug the code, and setting breakpoints in the Serialize
and
| Deserialize functions, I see that they aren't even being called.
|
| Maybe a MS bug? or maybe I am doing something wrong?
| Thanks,
| Doron.
|
| Here are all the details of code:
|
| ////////////////////////////////////////////////////////
| /// The Component /////////////////////////
| /////////////////////////////////////////////////////
|
[DesignerSerializer(typeof(MyComponentSerializer),typeof(CodeDomSerializer))
| ]
|  [
|  ToolboxItemFilter("System.CF.Windows.Forms",
ToolboxItemFilterType.Custom),
|  ToolboxItemFilter("NETCF", ToolboxItemFilterType.Require)
|  ]
|  public class MyComponent : Component
|  {
|   private string myString;
|   public string MyString
|   {
|    get
|    {
|     return myString;
|    }
|    set
|    {
|     myString = value;
|    }
|   }
|  }
|
| And the serialized looks like that and does nothing:
|
| ////////////////////////////////////////////////////////
| /// The DesignerSerializer /////////////////////////
| /////////////////////////////////////////////////////
|  internal class MyComponentSerializer: CodeDomSerializer
|  {
|   public override object Deserialize(IDesignerSerializationManager
manager,
| object codeObject)
|   {
|    CodeDomSerializer baseSerializer =
|     (CodeDomSerializer)manager.GetSerializer(
|     typeof(MyComponentSerializer).BaseType,
|     typeof(CodeDomSerializer));
|    return baseSerializer.Deserialize(manager, codeObject);
|   }
|   public override object Serialize(IDesignerSerializationManager manager,
| object value)
|   {
|    CodeDomSerializer baseSerializer =
|     (CodeDomSerializer)manager.GetSerializer(
|     typeof(MyComponentSerializer).BaseType,
|     typeof(CodeDomSerializer));
|    return baseSerializer.Serialize(manager, value);
|   }
|  }
|
| The exception Stack trace (it happens somewhere in
| Microsoft.VisualStudio.dll
|
| >
|
microsoft.visualstudio.dll!Microsoft.VisualStudio.Designer.Serialization.Und
| oManager.TakeSnapshot(System.Collections.ICollection undoEntries =
| {System.Array},
| Microsoft.VisualStudio.Designer.Serialization.UndoManager.UndoSnapshot
| snapshot =
| {Microsoft.VisualStudio.Designer.Serialization.UndoManager.UndoSnapshot})
+
| 0x4cd bytes
|
|
microsoft.visualstudio.dll!Microsoft.VisualStudio.Designer.Serialization.Und
| oManager.UndoUnit.ComponentChanging(System.Object comp =
| {OrsusCF.MyComponent}, System.ComponentModel.MemberDescriptor member =
| {System.ComponentModel.ReflectPropertyDescriptor}) + 0x2ba bytes
|
|
microsoft.visualstudio.dll!Microsoft.VisualStudio.Designer.Serialization.Und
| oManager.OnComponentChanging(System.Object sender =
| {Microsoft.VisualStudio.Designer.Host.DesignerHost},
| System.ComponentModel.Design.ComponentChangingEventArgs e =
| {System.ComponentModel.Design.ComponentChangingEventArgs}) + 0x215 bytes
|
|
microsoft.visualstudio.dll!Microsoft.VisualStudio.Designer.Host.DesignerHost
| .OnComponentChanging(System.Object component = {OrsusCF.MyComponent},
| System.ComponentModel.MemberDescriptor member =
| {System.ComponentModel.ReflectPropertyDescriptor}) + 0x83 bytes
|
|
system.dll!System.ComponentModel.ReflectPropertyDescriptor.SetValue(System.O
| bject component = {OrsusCF.MyComponent}, System.Object value = "ddd") +
| 0x121 bytes
|
|
system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyD
| escriptorGridEntry.SetPropertyValueCore(System.Object obj =
| {OrsusCF.MyComponent}, System.Object value = "ddd", bool doUndo = true) +
| 0x140 bytes
|
|
system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyD
| escriptorGridEntry.SetPropertyValue(System.Object obj =
| {OrsusCF.MyComponent}, System.Object objVal = "ddd") + 0x48e bytes
|
|
system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyD
| escriptorGridEntry.set_PropertyValue(System.Object value = "ddd") + 0x21
| bytes
|
|
system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyG
| ridView.CommitValue(System.Object value = "ddd") + 0x14b bytes
|
|
system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyG
| ridView.CommitText(string text = "ddd") + 0xf1 bytes
|
|
system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyG
| ridView.Commit() + 0xca bytes
|
|
system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyG
| ridView._Commit() + 0xc bytes
|
|
system.windows.forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyG
| ridView.GridViewEdit.OnClickHooked() + 0x12 bytes
|   system.windows.forms.dll!MouseHooker.ProcessMouseDown(int hWnd = 198198,
| int x = 156, int y = 713) + 0x15d bytes
|   system.windows.forms.dll!MouseHooker.MouseHookProc(int nCode = 0, int
| wparam = 513, int lparam = 1243764) + 0xca bytes
|   system.windows.forms.dll!MouseHooker.MouseHookObject.Callback(int nCode
=
| 0, int wparam = 513, int lparam = 1243764) + 0x66 bytes
|
|
|
|

 
 
 

1. Using DesignerSerializer for CF components throws exception.

Please see my related thread.  I do not repro an exception when deleting
the component either.  The only way I can think that you could be getting
an invalid cast exception is if you are using desktop winform or drawing
types in your serializer.  You should be careful not to do this and not to
expect that any design time control has, as a property or reference, any
desktop type except those that appear in System.dll, System.Design.dll, and
mscorlib.  All other types should come from System.CF.Windows.Forms.dll and
System.CF.Drawing.dll.

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

| Subject: Using DesignerSerializer for CF components throws exception.
| Date: Sun, 9 Mar 2003 10:27:32 +0200
| Lines: 312
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 212.199.114.192
| Path: cpmsftngxa06!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06
microsoft.public.dotnet.framework.compactframework:18501
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Microsoft CF experts - This one is for you.
|
| I managed to create a small code example that causes an exception.
| When I place my custom component on a form of a Smart Device Application I
| get an Invalid cast exception.
| Sometime this exception is not shown but if you try and delete the
| component, you will see the exception in a message box.
| If I remove the DesignerSerializer attribute from the class everything
works
| fine, but then I don't have the custom code generation capabilities.
| Thanks, Doron.
|
| How to reproduce:
|
| Attached are 2 projects of a custom component (runtime and design-time).
| 1. Compile each one of them.
| 2. Put the OrsusCF.dll in D:\Program Files\Microsoft Visual Studio .NET
| 2003\CompactFrameworkSDK\v1.0.5000\Windows CE
| 3. Put the OrsusCFDesign.dll in D:\Program Files\Microsoft Visual Studio
| .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows CE\Designer
| 4. Open a VS and add the OrsusCFDesign.dll to the toolbox.
| 5. Place an OrsusCOMBaseClass component on the form, and then try to
delete
| it.
|
| You will notice the exception.
|
|
|

2. Create an ABC without a pure virtual function?

3. Run-time exception thrown : System.NullReferenceException - Object reference not set to an instance of an object.

4. SPTS Wizard doesn't create relative paths??????

5. IDE throws exception that it shouldn't be throwing

6. Proposed State & Federal Regulations for the INTERNET!

7. Custom server controls remain the same in design time after code has changed

8. Got Pro - can I use old CW for BeOS?

9. How can I let the design time generate codes I want automatically?

10. Problems with controls made in managed C++ code at design time.

11. Stopping synchronizing with code window at design time for an composite control

12. Render code which .Net renders in DESIGN - TIME HTML

13. Design time control in Run time program?