Ik probeer items van een Entity Class te serializen naar XML, de code doet zijn werk onder normale omstandigheden, maar als ik de Assembly waar de Entity in zit dynamisch laad krijg ik een error:
calling code in de exe, werkt als 1e lijn niet in commentaar, en dus de functie niet gebruikt wordt:
(code wat ingeknipt voor readability)
de assembly
geeft dus bij dynamisch laden van de dll :
(ex.message)
There was an error generating the XML document.
(ex.innerexception.message)
[A]System.Collections.Generic.List`1[CBackup.WolBackup] cannot be cast to [B]System.Collections.Generic.List`1[CBackup.WolBackup]. Type A originates from 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'. Type B originates from 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'.
waar zitten de C# / .NET experts , want ik raak er niet uit
calling code in de exe, werkt als 1e lijn niet in commentaar, en dus de functie niet gebruikt wordt:
(code wat ingeknipt voor readability)
C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| // main applicatie private void button_Click(object sender, RoutedEventArgs e) { //CBackup.CBackup.AppCloseBackup(); // --> werkt als uncommented BackupByRef(); // --> throw error } private void BackupByRef() { const string AssName = @"T:\CWPFPROJECT\CBackup\bin\Debug\CBackup"; MethodInfo mi = null; Type type = null; //Load assembly & query info Type[] ts = Assembly.LoadFrom(AssName + ".dll").GetExportedTypes(); for (int i = 0; i < ts.Count(); i++) { type = ts[i]; if (type.Name == "CBackup") { break; } } mi = type.GetMethod("AppStartBackup"); object returnObject = mi.Invoke(null, null); MessageBox.Show(((bool)returnObject).ToString()); |
de assembly
C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| public static bool AppStartBackup() { WolBackup wb = new WolBackup(); wb.MakeBackup(); return true; } //knip from class wolbackup public void MakeBackup() { var q = from l in ent.WolLijst // ent = Entity framework select l; if (q.Count() > 0) { List<WolBackup> lw = q.ToList(); FileStream fs = new FileStream(@"T:\test.xml", FileMode.OpenOrCreate); XmlSerializer s = new XmlSerializer(typeof(List<WolBackup>)); try { s.Serialize(fs, lw); } catch (System.InvalidOperationException ex) { MessageBox.Show(ex.InnerException.Message + " " + ex.Message); } fs.Close(); } } |
geeft dus bij dynamisch laden van de dll :
(ex.message)
There was an error generating the XML document.
(ex.innerexception.message)
[A]System.Collections.Generic.List`1[CBackup.WolBackup] cannot be cast to [B]System.Collections.Generic.List`1[CBackup.WolBackup]. Type A originates from 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'. Type B originates from 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'.
waar zitten de C# / .NET experts , want ik raak er niet uit