[runtime] Don't insta-fail when a faulty COM type is encountered. (#5616)
[mono.git] / mcs / tests / gtest-186.cs
1 using System;
2 using System.IO;
3 using System.Runtime.Serialization;
4 using System.Runtime.Serialization.Formatters.Binary;
5
6 [Serializable]
7 public class Tuple <a,b> {
8   public a field1;
9   public b field2;
10
11   public Tuple (a x, b y) {
12     field1 = x;
13     field2 = y;
14   }
15 }
16
17
18 public class Test {
19    public static void Main()  {
20
21       //Creates a new TestSimpleObject object.
22       TestSimpleObject obj = new TestSimpleObject();
23
24       Console.WriteLine("Before serialization the object contains: ");
25       obj.Print();
26
27       //Opens a file and serializes the object into it in binary format.
28       Stream stream = File.Open("data.xml", FileMode.Create);
29       BinaryFormatter formatter = new BinaryFormatter();
30
31       //BinaryFormatter formatter = new BinaryFormatter();
32
33       formatter.Serialize(stream, obj);
34       stream.Close();
35    
36       //Empties obj.
37       obj = null;
38    
39       //Opens file "data.xml" and deserializes the object from it.
40       stream = File.Open("data.xml", FileMode.Open);
41       formatter = new BinaryFormatter();
42
43       //formatter = new BinaryFormatter();
44
45       obj = (TestSimpleObject)formatter.Deserialize(stream);
46       stream.Close();
47
48       Console.WriteLine("");
49       Console.WriteLine("After deserialization the object contains: ");
50       obj.Print();
51    }
52 }
53
54
55 // A test object that needs to be serialized.
56 [Serializable()]        
57 public class TestSimpleObject  {
58
59     public Tuple <string,int>  member6;
60     
61     public TestSimpleObject() {
62         member6 = new Tuple <string, int> ("aa", 22);
63     }
64
65
66     public void Print() {
67         Console.WriteLine("member6 = '{0}'", member6);
68     }
69 }