One or more arguments are invalid

  • C#
  • .NET (FX) 4.0

Es gibt 10 Antworten in diesem Thema. Der letzte Beitrag () ist von Runshak.

    One or more arguments are invalid

    Hallo,

    ich bekomme seit heute in meinem Projekt nen Fehler, wenn ich es beende (rotes Quadrat im VS)

    Der Fehler wird mir in Form einer Messagebox angezeigt...dort steht nur, dass es nen Fehler gab mit HRESULT 0x80070057

    keinerlei Zeilenangaben oder näheres, was nicht passt...während des Debuggens im VS werden mir keinerlei Fehler angezeigt...

    Der Fehler tritt auch nicht immer auf und ist nur sehr schwer zu reproduzieren...hat jemand Tipps, woran das liegen kann bzw wie man das herausfindet?
    Ein paar Infos mehr wären ganz cool.
    Was macht dein Code? Threading? Form-Close Events (wird da iwas ausgeführt)? etc.
    ok...

    Server:

    startet, öffnet nen Port und wartet bis sich der Client meldet...

    Client:

    macht erstmal nichts außer "hübsch" aussehen...

    Server + Client:
    wenn der User auf start klickt, wird eine Verbindung zum Server aufgebaut (mit Hilfe von WCF) die Verbindung läuft über netTCP/IPvomServer:geöffneterPortvomServer/vertragsname ...dadurch erhält der Server den Befehl auf ne DLL zuzugreifen und diese auszuführen...anschließend gibt er nen String an den Client zurück und es wurden zwei Dateien angelegt. Jetzt passiert erst wieder was, wenn der User erneut auf Start klickt (der Server gibt diesmal nen anderen String zurück und macht sonst nichts) Wenn der User auf Stop klickt, führt der Server ne andere Funktion in der DLL aus und gibt einen entsprechenden String zurück an den Client (es werden keine Dateien angelegt)...Jetzt kann man das Programm entweder schließen oder erneut Start klicken oder nochmals auf Stop klicken (was aber nur nen String ausgibt und sonst nichts macht)

    Die Strings sind Zahlenwerte zum "visualisieren" was gemacht wurde...
    1 -> die beiden dateien wurden angelegt
    2 -> es wurden bereits die dateien angelegt
    3 -> aufgabe der dll gestoppt
    4 -> dll ist bereits gestoppt

    der Fehler tritt nicht bei ner bestimmten Klickfolge auf sondern sehr sporadisch...habs jetzt 10 mal problemlos starten/beenden können ohne Fehler...
    Ok das Problem tritt also im Client auf? Ich tippe auf ein Problem mit dem Stream (der eine schließt ihn während der andere noch liest oder ähnliches).

    Runshak schrieb:

    aber ohne weitere Informationen
    Kannst Du mal das Projekt posten?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Im Anhang ist die Fehlermeldung...

    Server:

    Spoiler anzeigen

    C#-Quellcode

    1. ​using System;
    2. using System.Collections.Generic;
    3. using System.IO;
    4. using System.Linq;
    5. using System.Net;
    6. using System.Net.Sockets;
    7. using System.Reflection;
    8. using System.Runtime.InteropServices;
    9. using System.ServiceModel;
    10. using System.ServiceModel.Description;
    11. using System.Text;
    12. using System.Windows;
    13. using System.Windows.Controls;
    14. using System.Windows.Data;
    15. using System.Windows.Documents;
    16. using System.Windows.Forms;
    17. using System.Windows.Input;
    18. using System.Windows.Media;
    19. using System.Windows.Media.Imaging;
    20. using System.Windows.Navigation;
    21. using System.Windows.Shapes;
    22. using Vertrag;
    23. namespace Server
    24. {
    25. public partial class MainWindow : Window
    26. {
    27. public MainWindow()
    28. {
    29. InitializeComponent();
    30. ServiceHost sh = new ServiceHost(typeof(Cservice));
    31. string Host = System.Net.Dns.GetHostName(); // Name im Netzwerk
    32. var IPAddress = Dns.GetHostEntry(Host).AddressList.First(adr => adr.AddressFamily != AddressFamily.InterNetworkV6); //gibt ipv4 zurück
    33. FileInfo fi = new FileInfo(System.Windows.Forms.Application.ExecutablePath); // Pfad von .txt-Datei im Debug-Verzeichnis vom Server
    34. string path;
    35. path = fi.DirectoryName + "\\Portnummer.txt";
    36. string portnummer;
    37. portnummer = File.ReadAllText(path); // liest Portnummer aus .txt heraus
    38. sh.AddServiceEndpoint(typeof(Ivertrag), new NetTcpBinding(SecurityMode.None), "net.tcp://" + IPAddress + ":" + portnummer + "/IvertragAsynchron");
    39. sh.Open();
    40. string adresse;
    41. adresse = "Server läuft auf: " + "net.tcp://" + IPAddress + ":" + portnummer + "/IvertragAsynchron";
    42. txtBoxOben.Text ="Portnummer: " + portnummer+ "\r\n" + adresse;
    43. }
    44. }
    45. public class Cservice : Ivertrag
    46. {
    47. public bool Ping()
    48. {
    49. return true;
    50. }
    51. public CdatenVertrag Start()
    52. {
    53. string ergebnis = DLLCallerStart.Call();
    54. return new CdatenVertrag
    55. {
    56. Content = ergebnis //"Daten vom Server!"
    57. };
    58. }
    59. public CdatenVertrag Stop()
    60. {
    61. string ergebnis2 = DLLCallerStop.Call();
    62. return new CdatenVertrag
    63. {
    64. Content = ergebnis2
    65. };
    66. }
    67. }
    68. }

    dazu gehören noch zwei weitere Klassen:

    C#-Quellcode

    1. ​using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Runtime.InteropServices;
    5. using System.Text;
    6. namespace Server
    7. {
    8. public static class DLLCallerStart //Startet Skala
    9. {
    10. [DllImport("CallSkalaFkt.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    11. private static extern Int32 CallSkalaFkt_SkalaStart(Int32 _hWnd, string _DB_Path, string _GLOB_GUID, string _RG_PATH, Int32 _EE_ID, Int32 _EE_Par, Int32 new_Ring, Int32 _auto_Start, ref Int32 Status_Flag);
    12. public static string Call()
    13. {
    14. System.Threading.Thread.Sleep(1000);
    15. string _DB_Path = "D:\\Projekte\\Skala_Simu\\Simu\\Glob_Simu.mdb";
    16. string _GLOB_GUID = "{guid{5ACB1481-2692-4C66-8BBC-9CC8B9FDF0C2}}";
    17. string _RG_PATH = "D:\\Projekte\\Skala_Simu\\Simu\\";
    18. Int32 _hWnd = 0;
    19. Int32 _EE_ID = 1;
    20. Int32 _EE_Par = 0;
    21. Int32 new_Ring = 1;
    22. Int32 _auto_Start = 0;
    23. Int32 Status_Flag = 0;
    24. GCHandle m_gch = GCHandle.Alloc(Status_Flag, GCHandleType.Pinned);
    25. try
    26. {
    27. int tmp = CallSkalaFkt_SkalaStart(_hWnd, _DB_Path, _GLOB_GUID, _RG_PATH, _EE_ID, _EE_Par, new_Ring, _auto_Start, ref Status_Flag);
    28. m_gch.Free();
    29. return tmp.ToString();
    30. }
    31. catch (Exception ex)
    32. {
    33. return ex.Message;
    34. }
    35. }
    36. }
    37. }


    C#-Quellcode

    1. ​using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Runtime.InteropServices;
    5. using System.Text;
    6. namespace Server
    7. {
    8. class DLLCallerStop //Stopt Skala
    9. {
    10. [DllImport("CallSkalaFkt.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    11. private static extern Int32 CallSkalaFkt_SkalaStop(Int32 _EE_ID, ref Int32 Status_Flag);
    12. public static string Call()
    13. {
    14. System.Threading.Thread.Sleep(1000);
    15. Int32 _EE_ID = 1;
    16. Int32 Status_Flag = 0;
    17. GCHandle m_gch = GCHandle.Alloc(Status_Flag, GCHandleType.Pinned);
    18. try
    19. {
    20. int tmp = CallSkalaFkt_SkalaStop(_EE_ID, ref Status_Flag);
    21. m_gch.Free();
    22. return tmp.ToString();
    23. }
    24. catch (Exception ex)
    25. {
    26. return ex.Message;
    27. }
    28. }
    29. }
    30. }


    der Vertrag:
    Spoiler anzeigen

    C#-Quellcode

    1. ​using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Runtime.Serialization;
    5. using System.ServiceModel;
    6. using System.Text;
    7. namespace Vertrag
    8. {
    9. [DataContract(Name = "DemoData")]
    10. public class CdatenVertrag
    11. {
    12. [DataMember(Name = "Content")]
    13. public string Content { get; set; }
    14. }
    15. }


    C#-Quellcode

    1. ​using System.ServiceModel;
    2. namespace Vertrag
    3. {
    4. [ServiceContract(Name = "Grapefruit")]
    5. public interface Ivertrag
    6. {
    7. [OperationContract()]
    8. CdatenVertrag Start();
    9. [OperationContract()]
    10. CdatenVertrag Stop();
    11. [OperationContract()]
    12. bool Ping();
    13. }
    14. }

    C#-Quellcode

    1. ​using System;
    2. using System.ServiceModel;
    3. namespace Vertrag
    4. {
    5. [ServiceContract(Name = "Grapefruit")]
    6. public interface IvertragAsynchron
    7. {
    8. [OperationContract(AsyncPattern = true)]
    9. IAsyncResult BeginStart(AsyncCallback callback, object asyncState);
    10. CdatenVertrag EndStart(IAsyncResult result);
    11. [OperationContract(AsyncPattern = true)]
    12. IAsyncResult BeginStop(AsyncCallback callback, object asyncState);
    13. CdatenVertrag EndStop(IAsyncResult result);
    14. [OperationContract(AsyncPattern = false)]
    15. bool Ping();
    16. }
    17. }



    die beiden Hilfsklassen
    Spoiler anzeigen

    C#-Quellcode

    1. ​using System;
    2. using System.Windows.Input;
    3. namespace HilfeTools
    4. {
    5. public class Cbefehl : ICommand
    6. {
    7. private Action _execute;
    8. public Cbefehl(Action execute)
    9. {
    10. _execute = execute;
    11. }
    12. public bool CanExecute(object parameter)
    13. {
    14. return true;
    15. }
    16. public event EventHandler CanExecuteChanged;
    17. public void Execute(object parameter)
    18. {
    19. _execute();
    20. }
    21. }
    22. }


    C#-Quellcode

    1. ​using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel;
    4. using System.Diagnostics;
    5. using System.Linq;
    6. using System.Linq.Expressions;
    7. using System.Reflection;
    8. namespace HilfeTools
    9. {
    10. public abstract class Chilfe : INotifyPropertyChanged
    11. {
    12. public event PropertyChangedEventHandler PropertyChanged;
    13. public void NotifyPropertyChanged(string info)
    14. {
    15. if (PropertyChanged != null)
    16. {
    17. PropertyChanged(this, new PropertyChangedEventArgs(info));
    18. }
    19. }
    20. }
    21. }


    der Client:
    Spoiler anzeigen

    C#-Quellcode

    1. ​using System.Windows;
    2. //View (inkl. MainWindow.xaml)
    3. namespace Client
    4. {
    5. public partial class MainWindow : Window
    6. {
    7. public MainWindow()
    8. {
    9. InitializeComponent();
    10. this.DataContext = new Viewmodel.MainModel();
    11. // fürs Binding/MVVM hergestellte "Verknüpfung"
    12. }
    13. private void OnBeenden(object sender, RoutedEventArgs e)
    14. {
    15. this.Close();
    16. }
    17. }
    18. }


    C#-Quellcode

    1. ​using System.ServiceModel;
    2. using System.Windows.Input;
    3. using Vertrag;
    4. using HilfeTools;
    5. using System.Threading;
    6. using System.Net;
    7. using System.Windows;
    8. using System;
    9. using System.Diagnostics;
    10. using System.IO;
    11. //Viewmodel
    12. namespace Client.Viewmodel
    13. {
    14. public partial class MainModel : Chilfe
    15. {
    16. private IvertragAsynchron objProxy;
    17. public string _StringContent = "";
    18. public string StringContent
    19. {
    20. get { return _StringContent; }
    21. set { _StringContent = value; NotifyPropertyChanged("StringContent"); }
    22. }
    23. public string _IpAddress = "";
    24. public string IpAddress
    25. {
    26. get { return _IpAddress; }
    27. set { _IpAddress = value; NotifyPropertyChanged("ipAddress"); }
    28. }
    29. public string _PortNumber = "";
    30. public string PortNumber
    31. {
    32. get { return _PortNumber; }
    33. set { _PortNumber = value; NotifyPropertyChanged("portNumber"); }
    34. }
    35. private Cbefehl _SkalaStart;
    36. public ICommand SkalaStart
    37. {
    38. get { return (_SkalaStart ?? (_SkalaStart = new Cbefehl(Start))); }
    39. //Der Operator ?? wird NULL-Sammeloperator genannt.
    40. //Der linke Operand wird zurückgegeben, falls dieser NICHT NULL ist.
    41. //Andernfalls wird der rechte Operand zurückgegeben.
    42. }
    43. private Cbefehl _SkalaStop;
    44. public ICommand SkalaStop
    45. {
    46. get { return (_SkalaStop ?? (_SkalaStop = new Cbefehl(Stop))); }
    47. }
    48. private Cbefehl _Speichern;
    49. public ICommand Speichern
    50. {
    51. get { return (_Speichern ?? (_Speichern = new Cbefehl(OnSpeichern))); }
    52. }
    53. private Cbefehl _Laden;
    54. public ICommand Laden
    55. {
    56. get { return (_Laden ?? (_Laden = new Cbefehl(OnLaden))); }
    57. }
    58. public void OnSpeichern()
    59. {
    60. Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog();
    61. dialog.Filter = "Txt-Files(*.txt)|*.txt";
    62. Nullable<bool> result = dialog.ShowDialog();
    63. if (result == true)
    64. {
    65. File.WriteAllText(dialog.FileName, IpAddress);
    66. }
    67. Nullable<bool> result2 = dialog.ShowDialog();
    68. if (result2 == true)
    69. {
    70. File.WriteAllText(dialog.FileName, PortNumber);
    71. }
    72. }
    73. public void OnLaden()
    74. {
    75. Microsoft.Win32.OpenFileDialog dialogo = new Microsoft.Win32.OpenFileDialog();
    76. dialogo.Filter = "Txt-Files(*.txt)|*.txt";
    77. Nullable<bool> result = dialogo.ShowDialog();
    78. if (result == true)
    79. {
    80. IpAddress = File.ReadAllText(dialogo.FileName);
    81. }
    82. Nullable<bool> result2 = dialogo.ShowDialog();
    83. if (result2 == true)
    84. {
    85. PortNumber = File.ReadAllText(dialogo.FileName);
    86. }
    87. }
    88. public void Start()
    89. {
    90. try
    91. {
    92. string rmAddres = null;
    93. rmAddres = "net.tcp://" + IpAddress + ":" + PortNumber + "/IvertragAsynchron";
    94. // rmAddres = "net.tcp://" + "10.202.4.128" + ":" + "2121" + "/IvertragAsynchron";
    95. NetTcpBinding nettcpbinding = new NetTcpBinding(SecurityMode.None); // new NetTcpBinding(hier MUSS was stehen!! sonst tuts ned)
    96. ChannelFactory<IvertragAsynchron> chFactory = new ChannelFactory<IvertragAsynchron>(nettcpbinding);
    97. nettcpbinding.MaxReceivedMessageSize = 10485760; // 10485760 entspricht 10 MB
    98. TimeSpan mSpan = default(TimeSpan);
    99. mSpan = new TimeSpan(1200000000); // entspricht 2 Minuten (1 Millisekunde = 10.000 Ticks) -> 2min = 120.000ms = 1.200.000.000Ticks
    100. nettcpbinding.SendTimeout = mSpan;
    101. EndpointAddress epAddress = new EndpointAddress(rmAddres);
    102. objProxy = chFactory.CreateChannel(epAddress);
    103. this.StringContent = "Anfrage läuft...währenddessen kann das Fenster frei bewegt werden";
    104. if (objProxy.Ping())
    105. {
    106. objProxy.BeginStart(asyncResult =>
    107. {
    108. this.StringContent = objProxy.EndStart(asyncResult).Content; // hier wird die Fehlermeldung geworfen... -> CallbackException
    109. }, null);
    110. }
    111. }
    112. catch (Exception ex)
    113. {
    114. //MessageBox.Show("Leider ist ein Fehler aufgetreten:\r\n" + ex.Message);
    115. this.StringContent = ex.Message;
    116. }
    117. }
    118. public void Stop()
    119. {
    120. try
    121. {
    122. string rmAddres = null;
    123. rmAddres = "net.tcp://" + IpAddress + ":" + PortNumber + "/IvertragAsynchron";
    124. // rmAddres = "net.tcp://" + "10.202.4.128" + ":" + "2121" + "/IvertragAsynchron";
    125. NetTcpBinding nettcpbinding = new NetTcpBinding(SecurityMode.None); // new NetTcpBinding(hier MUSS was stehen!! sonst tuts ned)
    126. ChannelFactory<IvertragAsynchron> chFactory = new ChannelFactory<IvertragAsynchron>(nettcpbinding);
    127. nettcpbinding.MaxReceivedMessageSize = 10485760; // 10485760 entspricht 10 MB
    128. TimeSpan mSpan = default(TimeSpan);
    129. mSpan = new TimeSpan(1200000000); // entspricht 2 Minuten (1 Millisekunde = 10.000 Ticks) -> 2min = 120.000ms = 1.200.000.000Ticks
    130. nettcpbinding.SendTimeout = mSpan;
    131. EndpointAddress epAddress = new EndpointAddress(rmAddres);
    132. objProxy = chFactory.CreateChannel(epAddress);
    133. this.StringContent = "Anfrage läuft...währenddessen kann das Fenster frei bewegt werden";
    134. if (objProxy.Ping())
    135. {
    136. objProxy.BeginStop(asyncResult =>
    137. {
    138. this.StringContent = objProxy.EndStop(asyncResult).Content; // hier wird die Fehlermeldung geworfen... -> CallbackException
    139. }, null);
    140. }
    141. }
    142. catch (Exception ex)
    143. {
    144. this.StringContent = ex.Message;
    145. }
    146. }
    147. }
    148. }



    Vermutlich liegt es am Vertrag bzw an der Implementierung von Stop (BeginStop, EndStop)
    Bilder
    • Error.png

      20,13 kB, 511×247, 181 mal angesehen

    RodFromGermany schrieb:

    Kannst Du mal das Projekt posten?

    Runshak schrieb:

    Im Anhang
    wars nicht.
    Ich möchte das Projekt laden, starten, sehen, was passiert.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!

    Runshak schrieb:

    die darf ich nicht herausgeben
    Dann hast Du auch kein Problem. :/
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!