C# Error when saving a list to file -


program create use recording mouse , keyboard events. when create part saving record , use play later error below occur.

code:

public list<macroevent> events = new list<macroevent>(); stream stream = file.open("macro.bin", filemode.create); binaryformatter bin= new binaryformatter(); bin.serialize(stream, events); stream.close(); 

error getting:

an unhandled exception of type 'system.runtime.serialization.serializationexception' occurred in mscorlib.dll

additional information: type 'system.windows.forms.mouseeventargs' in assembly "system.windows.forms, version=4.0.0.0, culture=neutral, publickeytoken = b77a5c561934e089" not marked serializable.

full stack trace

a first chance exception of type 'system.runtime.serialization.serializationexception' occurred in mscorlib.dll stacktrace: '   @ system.environment.getstacktrace(exception e, boolean needfileinfo)    @ system.environment.get_stacktrace()    @ globalmacrorecorder.macroform.savemacro(object sender, eventargs e) in c:\users\cy\desktop\automated setup solution\automatedsetup\macroform.cs:line 465    @ system.windows.forms.button.onmouseup(mouseeventargs mevent)    @ system.windows.forms.control.wmmouseup(message& m, mousebuttons button, int32 clicks)    @ system.windows.forms.control.wndproc(message& m)    @ system.windows.forms.buttonbase.wndproc(message& m)    @ system.windows.forms.button.wndproc(message& m)    @ system.windows.forms.nativewindow.debuggablecallback(intptr hwnd, int32 msg, intptr wparam, intptr lparam)    @ system.windows.forms.unsafenativemethods.dispatchmessagew(msg& msg)    @ system.windows.forms.unsafenativemethods.dispatchmessagew(msg& msg)    @ system.windows.forms.application.componentmanager.system.windows.forms.unsafenativemethods.imsocomponentmanager.fpushmessageloop(intptr dwcomponentid, int32 reason, int32 pvloopdata)    @ system.windows.forms.application.threadcontext.runmessageloopinner(int32 reason, applicationcontext context)    @ system.windows.forms.application.threadcontext.runmessageloop(int32 reason, applicationcontext context)    @ globalmacrorecorder.program.main() in c:\users\cy\desktop\automated setup solution\automatedsetup\program.cs:line 17    @ system.appdomain._nexecuteassembly(runtimeassembly assembly, string[] args)    @ microsoft.visualstudio.hostingprocess.hostproc.runusersassembly()    @ system.threading.executioncontext.runinternal(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx)    @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx)    @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state)    @ system.threading.threadhelper.threadstart()' thread 0x1ad0 has exited code 0 (0x0). 

macroevent

[serializable]     public class macroevent     {          public macroeventtype macroeventtype;         public eventargs eventargs;         public int timesincelastevent;          public macroevent(macroeventtype macroeventtype, eventargs eventargs, int timesincelastevent)         {             macroeventtype = macroeventtype;             eventargs = eventargs;             timesincelastevent = timesincelastevent;         }     } 

you cannot that, because mouseeventargs not serializable. need create serializable class properties (x,y) similar of mouseeventargs , serialize class binary file.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -