440e1c82f05fa37ba6aac7ecefc1242597042773
[mono.git] / mcs / class / Mono.Debugger.Soft / Mono.Debugger.Soft / VirtualMachine.cs
1 using System;
2 using System.IO;
3 using System.Threading;
4 using System.Net;
5 using System.Diagnostics;
6 using System.Collections;
7 using System.Collections.Generic;
8 using Mono.Cecil.Metadata;
9
10 namespace Mono.Debugger.Soft
11 {
12         public class VirtualMachine : Mirror
13         {
14                 Queue queue;
15                 object queue_monitor;
16                 object startup_monitor;
17                 AppDomainMirror root_domain;
18                 Dictionary<int, EventRequest> requests;
19                 ITargetProcess process;
20
21                 internal Connection conn;
22
23                 VersionInfo version;
24
25                 internal VirtualMachine (ITargetProcess process, Connection conn) : base () {
26                         SetVirtualMachine (this);
27                         queue = new Queue ();
28                         queue_monitor = new Object ();
29                         startup_monitor = new Object ();
30                         requests = new Dictionary <int, EventRequest> ();
31                         this.conn = conn;
32                         this.process = process;
33                         conn.ErrorHandler += ErrorHandler;
34                 }
35
36                 // The standard output of the process is available normally through Process
37                 public StreamReader StandardOutput { get; set; }
38                 public StreamReader StandardError { get; set; }
39
40                 
41                 public Process Process {
42                         get {
43                                 ProcessWrapper pw = process as ProcessWrapper;
44                                 if (pw == null)
45                                     throw new InvalidOperationException ("Process instance not available");
46                                 return pw.Process;
47                         }
48                 }
49
50                 public ITargetProcess TargetProcess {
51                         get {
52                                 return process;
53                         }
54                 }
55
56                 public AppDomainMirror RootDomain {
57                         get {
58                                 return root_domain;
59                         }
60             }
61
62                 public EndPoint EndPoint {
63                         get {
64                                 var tcpConn = conn as TcpConnection;
65                                 if (tcpConn != null)
66                                         return tcpConn.EndPoint;
67                                 return null;
68                         }
69                 }
70
71                 public VersionInfo Version {
72                         get {
73                                 return version;
74                         }
75                 }
76
77                 EventSet current_es;
78                 int current_es_index;
79
80                 /*
81                  * It is impossible to determine when to resume when using this method, since
82                  * the debuggee is suspended only once per event-set, not event.
83                  */
84                 [Obsolete ("Use GetNextEventSet () instead")]
85                 public Event GetNextEvent () {
86                         lock (queue_monitor) {
87                                 if (current_es == null || current_es_index == current_es.Events.Length) {
88                                         if (queue.Count == 0)
89                                                 Monitor.Wait (queue_monitor);
90                                         current_es = (EventSet)queue.Dequeue ();
91                                         current_es_index = 0;
92                                 }
93                                 return current_es.Events [current_es_index ++];
94                         }
95                 }
96
97                 public Event GetNextEvent (int timeout) {
98                         throw new NotImplementedException ();
99                 }
100
101                 public EventSet GetNextEventSet () {
102                         lock (queue_monitor) {
103                                 if (queue.Count == 0)
104                                         Monitor.Wait (queue_monitor);
105
106                                 current_es = null;
107                                 current_es_index = 0;
108
109                                 return (EventSet)queue.Dequeue ();
110                         }
111                 }
112
113                 [Obsolete ("Use GetNextEventSet () instead")]
114                 public T GetNextEvent<T> () where T : Event {
115                         return GetNextEvent () as T;
116                 }
117
118                 public void Suspend () {
119                         conn.VM_Suspend ();
120             }
121
122                 public void Resume () {
123                         try {
124                                 conn.VM_Resume ();
125                         } catch (CommandException ex) {
126                                 if (ex.ErrorCode == ErrorCode.NOT_SUSPENDED)
127                                         throw new InvalidOperationException ("The vm is not suspended.");
128                                 else
129                                         throw;
130                         }
131             }
132
133                 public void Exit (int exitCode) {
134                         conn.VM_Exit (exitCode);
135                 }
136
137                 public void Dispose () {
138                         conn.VM_Dispose ();
139                         conn.Close ();
140                         conn.Dispose ();
141                         notify_vm_event (EventType.VMDisconnect, SuspendPolicy.None, 0, 0, null);
142                 }
143
144                 public IList<ThreadMirror> GetThreads () {
145                         long[] ids = vm.conn.VM_GetThreads ();
146                         ThreadMirror[] res = new ThreadMirror [ids.Length];
147                         for (int i = 0; i < ids.Length; ++i)
148                                 res [i] = GetThread (ids [i]);
149                         return res;
150                 }
151
152                 // Same as the mirrorOf methods in JDI
153                 public PrimitiveValue CreateValue (object value) {
154                         if (value == null)
155                                 return new PrimitiveValue (vm, null);
156
157                         if (!value.GetType ().IsPrimitive)
158                                 throw new ArgumentException ("value must be of a primitive type instead of '" + value.GetType () + "'", "value");
159
160                         return new PrimitiveValue (vm, value);
161                 }
162
163                 public EnumMirror CreateEnumMirror (TypeMirror type, PrimitiveValue value) {
164                         return new EnumMirror (this, type, value);
165                 }
166
167                 //
168                 // Enable send and receive timeouts on the connection and send a keepalive event
169                 // every 'keepalive_interval' milliseconds.
170                 //
171
172                 public void SetSocketTimeouts (int send_timeout, int receive_timeout, int keepalive_interval)
173                 {
174                         conn.SetSocketTimeouts (send_timeout, receive_timeout, keepalive_interval);
175                 }
176
177                 //
178                 // Methods to create event request objects
179                 //
180                 public BreakpointEventRequest CreateBreakpointRequest (MethodMirror method, long il_offset) {
181                         return new BreakpointEventRequest (this, method, il_offset);
182                 }
183
184                 public BreakpointEventRequest CreateBreakpointRequest (Location loc) {
185                         if (loc == null)
186                                 throw new ArgumentNullException ("loc");
187                         CheckMirror (loc);
188                         return new BreakpointEventRequest (this, loc.Method, loc.ILOffset);
189                 }
190
191                 public StepEventRequest CreateStepRequest (ThreadMirror thread) {
192                         return new StepEventRequest (this, thread);
193                 }
194
195                 public MethodEntryEventRequest CreateMethodEntryRequest () {
196                         return new MethodEntryEventRequest (this);
197                 }
198
199                 public MethodExitEventRequest CreateMethodExitRequest () {
200                         return new MethodExitEventRequest (this);
201                 }
202
203                 public ExceptionEventRequest CreateExceptionRequest (TypeMirror exc_type) {
204                         return new ExceptionEventRequest (this, exc_type, true, true);
205                 }
206
207                 public ExceptionEventRequest CreateExceptionRequest (TypeMirror exc_type, bool caught, bool uncaught) {
208                         return new ExceptionEventRequest (this, exc_type, caught, uncaught);
209                 }
210
211                 public AssemblyLoadEventRequest CreateAssemblyLoadRequest () {
212                         return new AssemblyLoadEventRequest (this);
213                 }
214
215                 public TypeLoadEventRequest CreateTypeLoadRequest () {
216                         return new TypeLoadEventRequest (this);
217                 }
218
219                 public void EnableEvents (params EventType[] events) {
220                         foreach (EventType etype in events) {
221                                 if (etype == EventType.Breakpoint)
222                                         throw new ArgumentException ("Breakpoint events cannot be requested using EnableEvents", "events");
223                                 conn.EnableEvent (etype, SuspendPolicy.All, null);
224                         }
225                 }
226
227                 public BreakpointEventRequest SetBreakpoint (MethodMirror method, long il_offset) {
228                         BreakpointEventRequest req = CreateBreakpointRequest (method, il_offset);
229
230                         req.Enable ();
231
232                         return req;
233                 }
234
235                 public void ClearAllBreakpoints () {
236                         conn.ClearAllBreakpoints ();
237                 }
238                 
239                 public void Disconnect () {
240                         conn.Close ();
241                 }
242
243                 //
244                 // Return a list of TypeMirror objects for all loaded types which reference the
245                 // source file FNAME. Might return false positives.
246                 // Since protocol version 2.7.
247                 //
248                 public IList<TypeMirror> GetTypesForSourceFile (string fname, bool ignoreCase) {
249                         long[] ids = conn.VM_GetTypesForSourceFile (fname, ignoreCase);
250                         var res = new TypeMirror [ids.Length];
251                         for (int i = 0; i < ids.Length; ++i)
252                                 res [i] = GetType (ids [i]);
253                         return res;
254                 }
255
256                 //
257                 // Return a list of TypeMirror objects for all loaded types named 'NAME'.
258                 // NAME should be in the the same for as with Assembly.GetType ().
259                 // Since protocol version 2.9.
260                 //
261                 public IList<TypeMirror> GetTypes (string name, bool ignoreCase) {
262                         long[] ids = conn.VM_GetTypes (name, ignoreCase);
263                         var res = new TypeMirror [ids.Length];
264                         for (int i = 0; i < ids.Length; ++i)
265                                 res [i] = GetType (ids [i]);
266                         return res;
267                 }
268                 
269                 internal void queue_event_set (EventSet es) {
270                         lock (queue_monitor) {
271                                 queue.Enqueue (es);
272                                 Monitor.Pulse (queue_monitor);
273                         }
274                 }
275
276                 internal void ErrorHandler (object sender, ErrorHandlerEventArgs args) {
277                         switch (args.ErrorCode) {
278                         case ErrorCode.INVALID_OBJECT:
279                                 throw new ObjectCollectedException ();
280                         case ErrorCode.INVALID_FRAMEID:
281                                 throw new InvalidStackFrameException ();
282                         case ErrorCode.NOT_SUSPENDED:
283                                 throw new InvalidOperationException ("The vm is not suspended.");
284                         case ErrorCode.NOT_IMPLEMENTED:
285                                 throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
286                         case ErrorCode.ABSENT_INFORMATION:
287                                 throw new AbsentInformationException ();
288                         case ErrorCode.NO_SEQ_POINT_AT_IL_OFFSET:
289                                 throw new ArgumentException ("Cannot set breakpoint on the specified IL offset.");
290                         default:
291                                 throw new CommandException (args.ErrorCode);
292                         }
293                 }
294
295                 /* Wait for the debuggee to start up and connect to it */
296                 internal void connect () {
297                         conn.Connect ();
298
299                         // Test the connection
300                         version = conn.Version;
301                         if (version.MajorVersion != Connection.MAJOR_VERSION)
302                                 throw new NotSupportedException (String.Format ("The debuggee implements protocol version {0}.{1}, while {2}.{3} is required.", version.MajorVersion, version.MinorVersion, Connection.MAJOR_VERSION, Connection.MINOR_VERSION));
303
304                         long root_domain_id = conn.RootDomain;
305                         root_domain = GetDomain (root_domain_id);
306                 }
307
308                 internal void notify_vm_event (EventType evtype, SuspendPolicy spolicy, int req_id, long thread_id, string vm_uri) {
309                         //Console.WriteLine ("Event: " + evtype + "(" + vm_uri + ")");
310
311                         switch (evtype) {
312                         case EventType.VMStart:
313                                 /* Notify the main thread that the debuggee started up */
314                                 lock (startup_monitor) {
315                                         Monitor.Pulse (startup_monitor);
316                                 }
317                                 queue_event_set (new EventSet (this, spolicy, new Event[] { new VMStartEvent (vm, req_id, thread_id) }));
318                                 break;
319                         case EventType.VMDeath:
320                                 queue_event_set (new EventSet (this, spolicy, new Event[] { new VMDeathEvent (vm, req_id) }));
321                                 break;
322                         case EventType.VMDisconnect:
323                                 queue_event_set (new EventSet (this, spolicy, new Event[] { new VMDisconnectEvent (vm, req_id) }));
324                                 break;
325                         default:
326                                 throw new Exception ();
327                         }
328                 }
329
330                 //
331                 // Methods to create instances of mirror objects
332                 //
333
334                 /*
335                 class MirrorCache<T> {
336                         static Dictionary <long, T> mirrors;
337                         static object mirror_lock = new object ();
338
339                         internal static T GetMirror (VirtualMachine vm, long id) {
340                                 lock (mirror_lock) {
341                                 if (mirrors == null)
342                                         mirrors = new Dictionary <long, T> ();
343                                 T obj;
344                                 if (!mirrors.TryGetValue (id, out obj)) {
345                                         obj = CreateMirror (vm, id);
346                                         mirrors [id] = obj;
347                                 }
348                                 return obj;
349                                 }
350                         }
351
352                         internal static T CreateMirror (VirtualMachine vm, long id) {
353                         }
354                 }
355                 */
356
357                 // FIXME: When to remove items from the cache ?
358
359                 Dictionary <long, MethodMirror> methods;
360                 object methods_lock = new object ();
361
362                 internal MethodMirror GetMethod (long id) {
363                         lock (methods_lock) {
364                                 if (methods == null)
365                                         methods = new Dictionary <long, MethodMirror> ();
366                                 MethodMirror obj;
367                                 if (id == 0)
368                                         return null;
369                                 if (!methods.TryGetValue (id, out obj)) {
370                                         obj = new MethodMirror (this, id);
371                                         methods [id] = obj;
372                                 }
373                                 return obj;
374                         }
375             }
376
377                 Dictionary <long, AssemblyMirror> assemblies;
378                 object assemblies_lock = new object ();
379
380                 internal AssemblyMirror GetAssembly (long id) {
381                         lock (assemblies_lock) {
382                                 if (assemblies == null)
383                                         assemblies = new Dictionary <long, AssemblyMirror> ();
384                                 AssemblyMirror obj;
385                                 if (id == 0)
386                                         return null;
387                                 if (!assemblies.TryGetValue (id, out obj)) {
388                                         obj = new AssemblyMirror (this, id);
389                                         assemblies [id] = obj;
390                                 }
391                                 return obj;
392                         }
393             }
394
395                 Dictionary <long, ModuleMirror> modules;
396                 object modules_lock = new object ();
397
398                 internal ModuleMirror GetModule (long id) {
399                         lock (modules_lock) {
400                                 if (modules == null)
401                                         modules = new Dictionary <long, ModuleMirror> ();
402                                 ModuleMirror obj;
403                                 if (id == 0)
404                                         return null;
405                                 if (!modules.TryGetValue (id, out obj)) {
406                                         obj = new ModuleMirror (this, id);
407                                         modules [id] = obj;
408                                 }
409                                 return obj;
410                         }
411             }
412
413                 Dictionary <long, AppDomainMirror> domains;
414                 object domains_lock = new object ();
415
416                 internal AppDomainMirror GetDomain (long id) {
417                         lock (domains_lock) {
418                                 if (domains == null)
419                                         domains = new Dictionary <long, AppDomainMirror> ();
420                                 AppDomainMirror obj;
421                                 if (id == 0)
422                                         return null;
423                                 if (!domains.TryGetValue (id, out obj)) {
424                                         obj = new AppDomainMirror (this, id);
425                                         domains [id] = obj;
426                                 }
427                                 return obj;
428                         }
429             }
430
431                 Dictionary <long, TypeMirror> types;
432                 object types_lock = new object ();
433
434                 internal TypeMirror GetType (long id) {
435                         lock (types_lock) {
436                                 if (types == null)
437                                         types = new Dictionary <long, TypeMirror> ();
438                                 TypeMirror obj;
439                                 if (id == 0)
440                                         return null;
441                                 if (!types.TryGetValue (id, out obj)) {
442                                         obj = new TypeMirror (this, id);
443                                         types [id] = obj;
444                                 }
445                                 return obj;
446                         }
447             }
448
449                 internal TypeMirror[] GetTypes (long[] ids) {
450                         var res = new TypeMirror [ids.Length];
451                         for (int i = 0; i < ids.Length; ++i)
452                                 res [i] = GetType (ids [i]);
453                         return res;
454                 }
455
456                 Dictionary <long, ObjectMirror> objects;
457                 object objects_lock = new object ();
458
459                 internal T GetObject<T> (long id, long domain_id, long type_id) where T : ObjectMirror {
460                         lock (objects_lock) {
461                                 if (objects == null)
462                                         objects = new Dictionary <long, ObjectMirror> ();
463                                 ObjectMirror obj;
464                                 if (!objects.TryGetValue (id, out obj)) {
465                                         /*
466                                          * Obtain the domain/type of the object to determine the type of
467                                          * object we need to create.
468                                          */
469                                         if (domain_id == 0 || type_id == 0) {
470                                                 if (conn.Version.AtLeast (2, 5)) {
471                                                         var info = conn.Object_GetInfo (id);
472                                                         domain_id = info.domain_id;
473                                                         type_id = info.type_id;
474                                                 } else {
475                                                         if (domain_id == 0)
476                                                                 domain_id = conn.Object_GetDomain (id);
477                                                         if (type_id == 0)
478                                                                 type_id = conn.Object_GetType (id);
479                                                 }
480                                         }
481                                         AppDomainMirror d = GetDomain (domain_id);
482                                         TypeMirror t = GetType (type_id);
483
484                                         if (t.Assembly == d.Corlib && t.Namespace == "System.Threading" && t.Name == "Thread")
485                                                 obj = new ThreadMirror (this, id, t, d);
486                                         else if (t.Assembly == d.Corlib && t.Namespace == "System" && t.Name == "String")
487                                                 obj = new StringMirror (this, id, t, d);
488                                         else if (typeof (T) == typeof (ArrayMirror))
489                                                 obj = new ArrayMirror (this, id, t, d);
490                                         else
491                                                 obj = new ObjectMirror (this, id, t, d);
492                                         objects [id] = obj;
493                                 }
494                                 return (T)obj;
495                         }
496             }
497
498                 internal T GetObject<T> (long id) where T : ObjectMirror {
499                         return GetObject<T> (id, 0, 0);
500                 }
501
502                 internal ObjectMirror GetObject (long objid) {
503                         return GetObject<ObjectMirror> (objid);
504                 }
505
506                 internal ThreadMirror GetThread (long id) {
507                         return GetObject <ThreadMirror> (id);
508                 }
509
510                 object requests_lock = new object ();
511
512                 internal void AddRequest (EventRequest req, int id) {
513                         lock (requests_lock) {
514                                 requests [id] = req;
515                         }
516                 }
517
518                 internal void RemoveRequest (EventRequest req, int id) {
519                         lock (requests_lock) {
520                                 requests.Remove (id);
521                         }
522                 }
523
524                 internal EventRequest GetRequest (int id) {
525                         lock (requests_lock) {
526                                 return requests [id];
527                         }
528                 }
529
530                 internal Value DecodeValue (ValueImpl v) {
531                         if (v.Value != null)
532                                 return new PrimitiveValue (this, v.Value);
533
534                         switch (v.Type) {
535                         case ElementType.Void:
536                                 return null;
537                         case ElementType.SzArray:
538                         case ElementType.Array:
539                                 return GetObject<ArrayMirror> (v.Objid);
540                         case ElementType.String:
541                                 return GetObject<StringMirror> (v.Objid);
542                         case ElementType.Class:
543                         case ElementType.Object:
544                                 return GetObject (v.Objid);
545                         case ElementType.ValueType:
546                                 if (v.IsEnum)
547                                         return new EnumMirror (this, GetType (v.Klass), DecodeValues (v.Fields));
548                                 else
549                                         return new StructMirror (this, GetType (v.Klass), DecodeValues (v.Fields));
550                         case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
551                                 return new PrimitiveValue (this, null);
552                         default:
553                                 throw new NotImplementedException ("" + v.Type);
554                         }
555                 }
556
557                 internal Value[] DecodeValues (ValueImpl[] values) {
558                         Value[] res = new Value [values.Length];
559                         for (int i = 0; i < values.Length; ++i)
560                                 res [i] = DecodeValue (values [i]);
561                         return res;
562                 }
563
564                 internal ValueImpl EncodeValue (Value v) {
565                         if (v is PrimitiveValue) {
566                                 object val = (v as PrimitiveValue).Value;
567                                 if (val == null)
568                                         return new ValueImpl { Type = (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL, Objid = 0 };
569                                 else
570                                         return new ValueImpl { Value = val };
571                         } else if (v is ObjectMirror) {
572                                 return new ValueImpl { Type = ElementType.Object, Objid = (v as ObjectMirror).Id };
573                         } else if (v is StructMirror) {
574                                 return new ValueImpl { Type = ElementType.ValueType, Klass = (v as StructMirror).Type.Id, Fields = EncodeValues ((v as StructMirror).Fields) };
575                         } else {
576                                 throw new NotSupportedException ();
577                         }
578                 }
579
580                 internal ValueImpl[] EncodeValues (IList<Value> values) {
581                         ValueImpl[] res = new ValueImpl [values.Count];
582                         for (int i = 0; i < values.Count; ++i)
583                                 res [i] = EncodeValue (values [i]);
584                         return res;
585                 }
586
587                 internal void CheckProtocolVersion (int major, int minor) {
588                         if (!conn.Version.AtLeast (major, minor))
589                                 throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
590                 }
591     }
592
593         class EventHandler : MarshalByRefObject, IEventHandler
594         {               
595                 VirtualMachine vm;
596
597                 public EventHandler (VirtualMachine vm) {
598                         this.vm = vm;
599                 }
600
601                 public void Events (SuspendPolicy suspend_policy, EventInfo[] events) {
602                         var l = new List<Event> ();
603
604                         for (int i = 0; i < events.Length; ++i) {
605                                 EventInfo ei = events [i];
606                                 int req_id = ei.ReqId;
607                                 long thread_id = ei.ThreadId;
608                                 long id = ei.Id;
609                                 long loc = ei.Location;
610
611                                 switch (ei.EventType) {
612                                 case EventType.VMStart:
613                                         vm.notify_vm_event (EventType.VMStart, suspend_policy, req_id, thread_id, null);
614                                         break;
615                                 case EventType.VMDeath:
616                                         vm.notify_vm_event (EventType.VMDeath, suspend_policy, req_id, thread_id, null);
617                                         break;
618                                 case EventType.ThreadStart:
619                                         l.Add (new ThreadStartEvent (vm, req_id, id));
620                                         break;
621                                 case EventType.ThreadDeath:
622                                         l.Add (new ThreadDeathEvent (vm, req_id, id));
623                                         break;
624                                 case EventType.AssemblyLoad:
625                                         l.Add (new AssemblyLoadEvent (vm, req_id, thread_id, id));
626                                         break;
627                                 case EventType.AssemblyUnload:
628                                         l.Add (new AssemblyUnloadEvent (vm, req_id, thread_id, id));
629                                         break;
630                                 case EventType.TypeLoad:
631                                         l.Add (new TypeLoadEvent (vm, req_id, thread_id, id));
632                                         break;
633                                 case EventType.MethodEntry:
634                                         l.Add (new MethodEntryEvent (vm, req_id, thread_id, id));
635                                         break;
636                                 case EventType.MethodExit:
637                                         l.Add (new MethodExitEvent (vm, req_id, thread_id, id));
638                                         break;
639                                 case EventType.Breakpoint:
640                                         l.Add (new BreakpointEvent (vm, req_id, thread_id, id, loc));
641                                         break;
642                                 case EventType.Step:
643                                         l.Add (new StepEvent (vm, req_id, thread_id, id, loc));
644                                         break;
645                                 case EventType.Exception:
646                                         l.Add (new ExceptionEvent (vm, req_id, thread_id, id, loc));
647                                         break;
648                                 case EventType.AppDomainCreate:
649                                         l.Add (new AppDomainCreateEvent (vm, req_id, thread_id, id));
650                                         break;
651                                 case EventType.AppDomainUnload:
652                                         l.Add (new AppDomainUnloadEvent (vm, req_id, thread_id, id));
653                                         break;
654                                 case EventType.UserBreak:
655                                         l.Add (new UserBreakEvent (vm, req_id, thread_id));
656                                         break;
657                                 case EventType.UserLog:
658                                         l.Add (new UserLogEvent (vm, req_id, thread_id, ei.Level, ei.Category, ei.Message));
659                                         break;
660                                 default:
661                                         break;
662                                 }
663                         }
664                         
665                         if (l.Count > 0)
666                                 vm.queue_event_set (new EventSet (vm, suspend_policy, l.ToArray ()));
667                 }
668
669                 public void VMDisconnect (int req_id, long thread_id, string vm_uri) {
670                         vm.notify_vm_event (EventType.VMDisconnect, SuspendPolicy.None, req_id, thread_id, vm_uri);
671         }
672     }
673
674         internal class CommandException : Exception {
675
676                 public CommandException (ErrorCode error_code) : base ("Debuggee returned error code " + error_code + ".") {
677                         ErrorCode = error_code;
678                 }
679
680                 public ErrorCode ErrorCode {
681                         get; set;
682                 }
683         }
684 }