DataException.cs 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479
  1. //------------------------------------------------------------------------------
  2. // <copyright file="DataException.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. // <owner current="true" primary="true">[....]</owner>
  6. // <owner current="true" primary="false">[....]</owner>
  7. //------------------------------------------------------------------------------
  8. namespace System.Data {
  9. using System;
  10. using System.ComponentModel;
  11. using System.Diagnostics;
  12. using System.Globalization;
  13. using System.Runtime.Serialization;
  14. // [....]: This functions are major point of localization.
  15. // We need to have a rules to enforce consistency there.
  16. // The dangerous point there are the string arguments of the exported (internal) methods.
  17. // This string can be argument, table or constraint name but never text of exception itself.
  18. // Make an invariant that all texts of exceptions coming from resources only.
  19. [Serializable]
  20. public class DataException : SystemException {
  21. protected DataException(SerializationInfo info, StreamingContext context)
  22. : base(info, context) {
  23. }
  24. public DataException()
  25. : base(Res.GetString(Res.DataSet_DefaultDataException)) {
  26. HResult = HResults.Data;
  27. }
  28. public DataException(string s)
  29. : base(s) {
  30. HResult = HResults.Data;
  31. }
  32. public DataException(string s, Exception innerException)
  33. : base(s, innerException) {
  34. }
  35. };
  36. [Serializable]
  37. public class ConstraintException : DataException {
  38. protected ConstraintException(SerializationInfo info, StreamingContext context)
  39. : base(info, context) {
  40. }
  41. public ConstraintException() : base(Res.GetString(Res.DataSet_DefaultConstraintException)) {
  42. HResult = HResults.DataConstraint;
  43. }
  44. public ConstraintException(string s) : base(s) {
  45. HResult = HResults.DataConstraint;
  46. }
  47. public ConstraintException(string message, Exception innerException) : base(message, innerException) {
  48. HResult = HResults.DataConstraint;
  49. }
  50. }
  51. [Serializable]
  52. public class DeletedRowInaccessibleException : DataException {
  53. protected DeletedRowInaccessibleException(SerializationInfo info, StreamingContext context)
  54. : base(info, context) {
  55. }
  56. /// <devdoc>
  57. /// <para>
  58. /// Initializes a new instance of the <see cref='System.Data.DeletedRowInaccessibleException'/> class.
  59. /// </para>
  60. /// </devdoc>
  61. public DeletedRowInaccessibleException() : base(Res.GetString(Res.DataSet_DefaultDeletedRowInaccessibleException)) {
  62. HResult = HResults.DataDeletedRowInaccessible;
  63. }
  64. /// <devdoc>
  65. /// <para>
  66. /// Initializes a new instance of the <see cref='System.Data.DeletedRowInaccessibleException'/> class with the specified string.
  67. /// </para>
  68. /// </devdoc>
  69. public DeletedRowInaccessibleException(string s) : base(s) {
  70. HResult = HResults.DataDeletedRowInaccessible;
  71. }
  72. public DeletedRowInaccessibleException(string message, Exception innerException) : base(message, innerException) {
  73. HResult = HResults.DataDeletedRowInaccessible;
  74. }
  75. }
  76. [Serializable]
  77. public class DuplicateNameException : DataException {
  78. protected DuplicateNameException(SerializationInfo info, StreamingContext context)
  79. : base(info, context) {
  80. }
  81. public DuplicateNameException() : base(Res.GetString(Res.DataSet_DefaultDuplicateNameException)) {
  82. HResult = HResults.DataDuplicateName;
  83. }
  84. public DuplicateNameException(string s) : base(s) {
  85. HResult = HResults.DataDuplicateName;
  86. }
  87. public DuplicateNameException(string message, Exception innerException) : base(message, innerException) {
  88. HResult = HResults.DataDuplicateName;
  89. }
  90. }
  91. [Serializable]
  92. public class InRowChangingEventException : DataException {
  93. protected InRowChangingEventException(SerializationInfo info, StreamingContext context)
  94. : base(info, context) {
  95. }
  96. public InRowChangingEventException() : base(Res.GetString(Res.DataSet_DefaultInRowChangingEventException)) {
  97. HResult = HResults.DataInRowChangingEvent;
  98. }
  99. public InRowChangingEventException(string s) : base(s) {
  100. HResult = HResults.DataInRowChangingEvent;
  101. }
  102. public InRowChangingEventException(string message, Exception innerException) : base(message, innerException) {
  103. HResult = HResults.DataInRowChangingEvent;
  104. }
  105. }
  106. [Serializable]
  107. public class InvalidConstraintException : DataException {
  108. protected InvalidConstraintException(SerializationInfo info, StreamingContext context)
  109. : base(info, context) {
  110. }
  111. public InvalidConstraintException() : base(Res.GetString(Res.DataSet_DefaultInvalidConstraintException)) {
  112. HResult = HResults.DataInvalidConstraint;
  113. }
  114. public InvalidConstraintException(string s) : base(s) {
  115. HResult = HResults.DataInvalidConstraint;
  116. }
  117. public InvalidConstraintException(string message, Exception innerException) : base(message, innerException) {
  118. HResult = HResults.DataInvalidConstraint;
  119. }
  120. }
  121. [Serializable]
  122. public class MissingPrimaryKeyException : DataException {
  123. protected MissingPrimaryKeyException(SerializationInfo info, StreamingContext context)
  124. : base(info, context) {
  125. }
  126. public MissingPrimaryKeyException() : base(Res.GetString(Res.DataSet_DefaultMissingPrimaryKeyException)) {
  127. HResult = HResults.DataMissingPrimaryKey;
  128. }
  129. public MissingPrimaryKeyException(string s) : base(s) {
  130. HResult = HResults.DataMissingPrimaryKey;
  131. }
  132. public MissingPrimaryKeyException(string message, Exception innerException) : base(message, innerException) {
  133. HResult = HResults.DataMissingPrimaryKey;
  134. }
  135. }
  136. [Serializable]
  137. public class NoNullAllowedException : DataException {
  138. protected NoNullAllowedException(SerializationInfo info, StreamingContext context)
  139. : base(info, context) {
  140. }
  141. public NoNullAllowedException() : base(Res.GetString(Res.DataSet_DefaultNoNullAllowedException)) {
  142. HResult = HResults.DataNoNullAllowed;
  143. }
  144. public NoNullAllowedException(string s) : base(s) {
  145. HResult = HResults.DataNoNullAllowed;
  146. }
  147. public NoNullAllowedException(string message, Exception innerException) : base(message, innerException) {
  148. HResult = HResults.DataNoNullAllowed;
  149. }
  150. }
  151. [Serializable]
  152. public class ReadOnlyException : DataException {
  153. protected ReadOnlyException(SerializationInfo info, StreamingContext context)
  154. : base(info, context) {
  155. }
  156. public ReadOnlyException() : base(Res.GetString(Res.DataSet_DefaultReadOnlyException)) {
  157. HResult = HResults.DataReadOnly;
  158. }
  159. public ReadOnlyException(string s) : base(s) {
  160. HResult = HResults.DataReadOnly;
  161. }
  162. public ReadOnlyException(string message, Exception innerException) : base(message, innerException) {
  163. HResult = HResults.DataReadOnly;
  164. }
  165. }
  166. [Serializable]
  167. public class RowNotInTableException : DataException {
  168. protected RowNotInTableException(SerializationInfo info, StreamingContext context)
  169. : base(info, context) {
  170. }
  171. public RowNotInTableException() : base(Res.GetString(Res.DataSet_DefaultRowNotInTableException)) {
  172. HResult = HResults.DataRowNotInTable;
  173. }
  174. public RowNotInTableException(string s) : base(s) {
  175. HResult = HResults.DataRowNotInTable;
  176. }
  177. public RowNotInTableException(string message, Exception innerException) : base(message, innerException) {
  178. HResult = HResults.DataRowNotInTable;
  179. }
  180. }
  181. [Serializable]
  182. public class VersionNotFoundException : DataException {
  183. protected VersionNotFoundException(SerializationInfo info, StreamingContext context)
  184. : base(info, context) {
  185. }
  186. public VersionNotFoundException() : base(Res.GetString(Res.DataSet_DefaultVersionNotFoundException)) {
  187. HResult = HResults.DataVersionNotFound;
  188. }
  189. public VersionNotFoundException(string s) : base(s) {
  190. HResult = HResults.DataVersionNotFound;
  191. }
  192. public VersionNotFoundException(string message, Exception innerException) : base(message, innerException) {
  193. HResult = HResults.DataVersionNotFound;
  194. }
  195. }
  196. internal static class ExceptionBuilder {
  197. // The class defines the exceptions that are specific to the DataSet.
  198. // The class contains functions that take the proper informational variables and then construct
  199. // the appropriate exception with an error string obtained from the resource Data.txt.
  200. // The exception is then returned to the caller, so that the caller may then throw from its
  201. // location so that the catcher of the exception will have the appropriate call stack.
  202. // This class is used so that there will be compile time checking of error messages.
  203. // The resource Data.txt will ensure proper string text based on the appropriate
  204. // locale.
  205. [BidMethod] // this method accepts BID format as an argument, this attribute allows FXCopBid rule to validate calls to it
  206. static private void TraceException(
  207. string trace,
  208. [BidArgumentType(typeof(String))] Exception e) {
  209. Debug.Assert(null != e, "TraceException: null Exception");
  210. if (null != e) {
  211. Bid.Trace(trace, e.Message);
  212. if (Bid.AdvancedOn) {
  213. try {
  214. Bid.Trace(", StackTrace='%ls'", Environment.StackTrace);
  215. }
  216. catch(System.Security.SecurityException) {
  217. // if you don't have permission - you don't get the stack trace
  218. }
  219. }
  220. Bid.Trace("\n");
  221. }
  222. }
  223. static internal void TraceExceptionAsReturnValue(Exception e) {
  224. TraceException("<comm.ADP.TraceException|ERR|THROW> Message='%ls'", e);
  225. }
  226. static internal void TraceExceptionForCapture(Exception e) {
  227. TraceException("<comm.ADP.TraceException|ERR|CATCH> Message='%ls'", e);
  228. }
  229. static internal void TraceExceptionWithoutRethrow(Exception e) {
  230. TraceException("<comm.ADP.TraceException|ERR|CATCH> Message='%ls'", e);
  231. }
  232. //
  233. // COM+ exceptions
  234. //
  235. static internal ArgumentException _Argument(string error) {
  236. ArgumentException e = new ArgumentException(error);
  237. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  238. return e;
  239. }
  240. static internal ArgumentException _Argument(string paramName, string error) {
  241. ArgumentException e = new ArgumentException(error);
  242. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  243. return e;
  244. }
  245. static internal ArgumentException _Argument(string error, Exception innerException) {
  246. ArgumentException e = new ArgumentException(error, innerException);
  247. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  248. return e;
  249. }
  250. static private ArgumentNullException _ArgumentNull(string paramName, string msg) {
  251. ArgumentNullException e = new ArgumentNullException(paramName, msg);
  252. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  253. return e;
  254. }
  255. static internal ArgumentOutOfRangeException _ArgumentOutOfRange(string paramName, string msg) {
  256. ArgumentOutOfRangeException e = new ArgumentOutOfRangeException(paramName, msg);
  257. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  258. return e;
  259. }
  260. static private IndexOutOfRangeException _IndexOutOfRange(string error) {
  261. IndexOutOfRangeException e = new IndexOutOfRangeException(error);
  262. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  263. return e;
  264. }
  265. static private InvalidOperationException _InvalidOperation(string error) {
  266. InvalidOperationException e = new InvalidOperationException(error);
  267. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  268. return e;
  269. }
  270. static private InvalidEnumArgumentException _InvalidEnumArgumentException(string error) {
  271. InvalidEnumArgumentException e = new InvalidEnumArgumentException(error);
  272. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  273. return e;
  274. }
  275. static private InvalidEnumArgumentException _InvalidEnumArgumentException<T>(T value) {
  276. string msg = Res.GetString(Res.ADP_InvalidEnumerationValue, typeof(T).Name, value.ToString());
  277. return _InvalidEnumArgumentException(msg);
  278. }
  279. //
  280. // System.Data exceptions
  281. //
  282. static private DataException _Data(string error) {
  283. DataException e = new DataException(error);
  284. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  285. return e;
  286. }
  287. /// <summary>trace and throw a DataException</summary>
  288. /// <param name="error">exception Message</param>
  289. /// <param name="innerException">exception InnerException</param>
  290. /// <exception cref="DataException">always thrown</exception>
  291. static private void ThrowDataException(string error, Exception innerException)
  292. {
  293. DataException e = new DataException(error, innerException);
  294. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  295. throw e;
  296. }
  297. static private ConstraintException _Constraint(string error) {
  298. ConstraintException e = new ConstraintException(error);
  299. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  300. return e;
  301. }
  302. static private InvalidConstraintException _InvalidConstraint(string error) {
  303. InvalidConstraintException e = new InvalidConstraintException(error);
  304. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  305. return e;
  306. }
  307. static private DeletedRowInaccessibleException _DeletedRowInaccessible(string error) {
  308. DeletedRowInaccessibleException e = new DeletedRowInaccessibleException(error);
  309. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  310. return e;
  311. }
  312. static private DuplicateNameException _DuplicateName(string error) {
  313. DuplicateNameException e = new DuplicateNameException(error);
  314. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  315. return e;
  316. }
  317. static private InRowChangingEventException _InRowChangingEvent(string error) {
  318. InRowChangingEventException e = new InRowChangingEventException(error);
  319. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  320. return e;
  321. }
  322. static private MissingPrimaryKeyException _MissingPrimaryKey(string error) {
  323. MissingPrimaryKeyException e = new MissingPrimaryKeyException(error);
  324. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  325. return e;
  326. }
  327. static private NoNullAllowedException _NoNullAllowed(string error) {
  328. NoNullAllowedException e = new NoNullAllowedException(error);
  329. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  330. return e;
  331. }
  332. static private ReadOnlyException _ReadOnly(string error) {
  333. ReadOnlyException e = new ReadOnlyException(error);
  334. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  335. return e;
  336. }
  337. static private RowNotInTableException _RowNotInTable(string error) {
  338. RowNotInTableException e = new RowNotInTableException(error);
  339. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  340. return e;
  341. }
  342. static private VersionNotFoundException _VersionNotFound(string error) {
  343. VersionNotFoundException e = new VersionNotFoundException(error);
  344. ExceptionBuilder.TraceExceptionAsReturnValue(e);
  345. return e;
  346. }
  347. // Consider: whether we need to keep our own texts from Data_ArgumentNull and Data_ArgumentOutOfRange?
  348. // Unfortunately ours and the system ones are not consisten between each other. Try to raise this isue in "URT user comunity"
  349. static public Exception ArgumentNull(string paramName) {
  350. return _ArgumentNull(paramName, Res.GetString(Res.Data_ArgumentNull, paramName));
  351. }
  352. static public Exception ArgumentOutOfRange(string paramName) {
  353. return _ArgumentOutOfRange(paramName, Res.GetString(Res.Data_ArgumentOutOfRange, paramName));
  354. }
  355. static public Exception BadObjectPropertyAccess(string error) {
  356. return _InvalidOperation(Res.GetString(Res.DataConstraint_BadObjectPropertyAccess, error));
  357. }
  358. static public Exception ArgumentContainsNull(string paramName) {
  359. return _Argument(paramName, Res.GetString(Res.Data_ArgumentContainsNull, paramName));
  360. }
  361. //
  362. // Collections
  363. //
  364. static public Exception CannotModifyCollection() {
  365. return _Argument(Res.GetString(Res.Data_CannotModifyCollection));
  366. }
  367. static public Exception CaseInsensitiveNameConflict(string name) {
  368. return _Argument(Res.GetString(Res.Data_CaseInsensitiveNameConflict, name));
  369. }
  370. static public Exception NamespaceNameConflict(string name) {
  371. return _Argument(Res.GetString(Res.Data_NamespaceNameConflict, name));
  372. }
  373. static public Exception InvalidOffsetLength() {
  374. return _Argument(Res.GetString(Res.Data_InvalidOffsetLength));
  375. }
  376. //
  377. // DataColumnCollection
  378. //
  379. static public Exception ColumnNotInTheTable(string column, string table) {
  380. return _Argument(Res.GetString(Res.DataColumn_NotInTheTable, column, table));
  381. }
  382. static public Exception ColumnNotInAnyTable() {
  383. return _Argument(Res.GetString(Res.DataColumn_NotInAnyTable));
  384. }
  385. static public Exception ColumnOutOfRange(int index) {
  386. return _IndexOutOfRange(Res.GetString(Res.DataColumns_OutOfRange, (index).ToString(CultureInfo.InvariantCulture)));
  387. }
  388. static public Exception ColumnOutOfRange(string column) {
  389. return _IndexOutOfRange(Res.GetString(Res.DataColumns_OutOfRange, column));
  390. }
  391. static public Exception CannotAddColumn1(string column) {
  392. return _Argument(Res.GetString(Res.DataColumns_Add1, column));
  393. }
  394. static public Exception CannotAddColumn2(string column) {
  395. return _Argument(Res.GetString(Res.DataColumns_Add2, column));
  396. }
  397. static public Exception CannotAddColumn3() {
  398. return _Argument(Res.GetString(Res.DataColumns_Add3));
  399. }
  400. static public Exception CannotAddColumn4(string column) {
  401. return _Argument(Res.GetString(Res.DataColumns_Add4, column));
  402. }
  403. static public Exception CannotAddDuplicate(string column) {
  404. return _DuplicateName(Res.GetString(Res.DataColumns_AddDuplicate, column));
  405. }
  406. static public Exception CannotAddDuplicate2(string table) {
  407. return _DuplicateName(Res.GetString(Res.DataColumns_AddDuplicate2, table));
  408. }
  409. static public Exception CannotAddDuplicate3(string table) {
  410. return _DuplicateName(Res.GetString(Res.DataColumns_AddDuplicate3, table));
  411. }
  412. static public Exception CannotRemoveColumn() {
  413. return _Argument(Res.GetString(Res.DataColumns_Remove));
  414. }
  415. static public Exception CannotRemovePrimaryKey() {
  416. return _Argument(Res.GetString(Res.DataColumns_RemovePrimaryKey));
  417. }
  418. static public Exception CannotRemoveChildKey(string relation) {
  419. return _Argument(Res.GetString(Res.DataColumns_RemoveChildKey, relation));
  420. }
  421. static public Exception CannotRemoveConstraint(string constraint, string table) {
  422. return _Argument(Res.GetString(Res.DataColumns_RemoveConstraint, constraint, table));
  423. }
  424. static public Exception CannotRemoveExpression(string column, string expression) {
  425. return _Argument(Res.GetString(Res.DataColumns_RemoveExpression, column, expression));
  426. }
  427. static public Exception ColumnNotInTheUnderlyingTable(string column, string table) {
  428. return _Argument(Res.GetString(Res.DataColumn_NotInTheUnderlyingTable, column, table));
  429. }
  430. static public Exception InvalidOrdinal(string name, int ordinal) {
  431. return _ArgumentOutOfRange(name, Res.GetString(Res.DataColumn_OrdinalExceedMaximun, (ordinal).ToString(CultureInfo.InvariantCulture)));
  432. }
  433. //
  434. // _Constraint and ConstrainsCollection
  435. //
  436. static public Exception AddPrimaryKeyConstraint() {
  437. return _Argument(Res.GetString(Res.DataConstraint_AddPrimaryKeyConstraint));
  438. }
  439. static public Exception NoConstraintName() {
  440. return _Argument(Res.GetString(Res.DataConstraint_NoName));
  441. }
  442. static public Exception ConstraintViolation(string constraint) {
  443. return _Constraint(Res.GetString(Res.DataConstraint_Violation, constraint));
  444. }
  445. static public Exception ConstraintNotInTheTable(string constraint) {
  446. return _Argument(Res.GetString(Res.DataConstraint_NotInTheTable,constraint));
  447. }
  448. static public string KeysToString(object[] keys) {
  449. string values = String.Empty;
  450. for (int i = 0; i < keys.Length; i++) {
  451. values += Convert.ToString(keys[i], null) + (i < keys.Length - 1 ? ", " : String.Empty);
  452. }
  453. return values;
  454. }
  455. static public string UniqueConstraintViolationText(DataColumn[] columns, object[] values) {
  456. if (columns.Length > 1) {
  457. string columnNames = String.Empty;
  458. for (int i = 0; i < columns.Length; i++) {
  459. columnNames += columns[i].ColumnName + (i < columns.Length - 1 ? ", " : "");
  460. }
  461. return Res.GetString(Res.DataConstraint_ViolationValue, columnNames, KeysToString(values));
  462. }
  463. else {
  464. return Res.GetString(Res.DataConstraint_ViolationValue, columns[0].ColumnName, Convert.ToString(values[0], null));
  465. }
  466. }
  467. static public Exception ConstraintViolation(DataColumn[] columns, object[] values) {
  468. return _Constraint(UniqueConstraintViolationText(columns, values));
  469. }
  470. static public Exception ConstraintOutOfRange(int index) {
  471. return _IndexOutOfRange(Res.GetString(Res.DataConstraint_OutOfRange, (index).ToString(CultureInfo.InvariantCulture)));
  472. }
  473. static public Exception DuplicateConstraint(string constraint) {
  474. return _Data(Res.GetString(Res.DataConstraint_Duplicate, constraint));
  475. }
  476. static public Exception DuplicateConstraintName(string constraint) {
  477. return _DuplicateName(Res.GetString(Res.DataConstraint_DuplicateName, constraint));
  478. }
  479. static public Exception NeededForForeignKeyConstraint(UniqueConstraint key, ForeignKeyConstraint fk) {
  480. return _Argument(Res.GetString(Res.DataConstraint_NeededForForeignKeyConstraint, key.ConstraintName, fk.ConstraintName));
  481. }
  482. static public Exception UniqueConstraintViolation() {
  483. return _Argument(Res.GetString(Res.DataConstraint_UniqueViolation));
  484. }
  485. static public Exception ConstraintForeignTable() {
  486. return _Argument(Res.GetString(Res.DataConstraint_ForeignTable));
  487. }
  488. static public Exception ConstraintParentValues() {
  489. return _Argument(Res.GetString(Res.DataConstraint_ParentValues));
  490. }
  491. static public Exception ConstraintAddFailed(DataTable table) {
  492. return _InvalidConstraint(Res.GetString(Res.DataConstraint_AddFailed, table.TableName));
  493. }
  494. static public Exception ConstraintRemoveFailed() {
  495. return _Argument(Res.GetString(Res.DataConstraint_RemoveFailed));
  496. }
  497. static public Exception FailedCascadeDelete(string constraint) {
  498. return _InvalidConstraint(Res.GetString(Res.DataConstraint_CascadeDelete, constraint));
  499. }
  500. static public Exception FailedCascadeUpdate(string constraint) {
  501. return _InvalidConstraint(Res.GetString(Res.DataConstraint_CascadeUpdate, constraint));
  502. }
  503. static public Exception FailedClearParentTable(string table, string constraint, string childTable) {
  504. return _InvalidConstraint(Res.GetString(Res.DataConstraint_ClearParentTable, table, constraint, childTable));
  505. }
  506. static public Exception ForeignKeyViolation(string constraint, object[] keys) {
  507. return _InvalidConstraint(Res.GetString(Res.DataConstraint_ForeignKeyViolation, constraint, KeysToString(keys)));
  508. }
  509. static public Exception RemoveParentRow(ForeignKeyConstraint constraint) {
  510. return _InvalidConstraint(Res.GetString(Res.DataConstraint_RemoveParentRow, constraint.ConstraintName));
  511. }
  512. static public string MaxLengthViolationText(string columnName) {
  513. return Res.GetString(Res.DataColumn_ExceedMaxLength, columnName);
  514. }
  515. static public string NotAllowDBNullViolationText(string columnName) {
  516. return Res.GetString(Res.DataColumn_NotAllowDBNull, columnName);
  517. }
  518. static public Exception CantAddConstraintToMultipleNestedTable(string tableName) {
  519. return _Argument(Res.GetString(Res.DataConstraint_CantAddConstraintToMultipleNestedTable, tableName));
  520. }
  521. //
  522. // DataColumn Set Properties conflicts
  523. //
  524. static public Exception AutoIncrementAndExpression() {
  525. return _Argument(Res.GetString(Res.DataColumn_AutoIncrementAndExpression));
  526. }
  527. static public Exception AutoIncrementAndDefaultValue() {
  528. return _Argument(Res.GetString(Res.DataColumn_AutoIncrementAndDefaultValue));
  529. }
  530. static public Exception AutoIncrementSeed() {
  531. return _Argument(Res.GetString(Res.DataColumn_AutoIncrementSeed));
  532. }
  533. static public Exception CantChangeDataType() {
  534. return _Argument(Res.GetString(Res.DataColumn_ChangeDataType));
  535. }
  536. static public Exception NullDataType() {
  537. return _Argument(Res.GetString(Res.DataColumn_NullDataType));
  538. }
  539. static public Exception ColumnNameRequired() {
  540. return _Argument(Res.GetString(Res.DataColumn_NameRequired));
  541. }
  542. static public Exception DefaultValueAndAutoIncrement() {
  543. return _Argument(Res.GetString(Res.DataColumn_DefaultValueAndAutoIncrement));
  544. }
  545. static public Exception DefaultValueDataType(string column, Type defaultType, Type columnType, Exception inner) {
  546. if (column.Length == 0) {
  547. return _Argument(Res.GetString(Res.DataColumn_DefaultValueDataType1, defaultType.FullName, columnType.FullName), inner);
  548. }
  549. else {
  550. return _Argument(Res.GetString(Res.DataColumn_DefaultValueDataType, column, defaultType.FullName, columnType.FullName), inner);
  551. }
  552. }
  553. static public Exception DefaultValueColumnDataType(string column, Type defaultType, Type columnType, Exception inner) {
  554. return _Argument(Res.GetString(Res.DataColumn_DefaultValueColumnDataType, column, defaultType.FullName, columnType.FullName), inner);
  555. }
  556. static public Exception ExpressionAndUnique() {
  557. return _Argument(Res.GetString(Res.DataColumn_ExpressionAndUnique));
  558. }
  559. static public Exception ExpressionAndReadOnly() {
  560. return _Argument(Res.GetString(Res.DataColumn_ExpressionAndReadOnly));
  561. }
  562. static public Exception ExpressionAndConstraint(DataColumn column, Constraint constraint) {
  563. return _Argument(Res.GetString(Res.DataColumn_ExpressionAndConstraint, column.ColumnName, constraint.ConstraintName));
  564. }
  565. static public Exception ExpressionInConstraint(DataColumn column) {
  566. return _Argument(Res.GetString(Res.DataColumn_ExpressionInConstraint, column.ColumnName));
  567. }
  568. static public Exception ExpressionCircular() {
  569. return _Argument(Res.GetString(Res.DataColumn_ExpressionCircular));
  570. }
  571. static public Exception NonUniqueValues(string column) {
  572. return _InvalidConstraint(Res.GetString(Res.DataColumn_NonUniqueValues, column));
  573. }
  574. static public Exception NullKeyValues(string column) {
  575. return _Data(Res.GetString(Res.DataColumn_NullKeyValues, column));
  576. }
  577. static public Exception NullValues(string column) {
  578. return _NoNullAllowed(Res.GetString(Res.DataColumn_NullValues, column));
  579. }
  580. static public Exception ReadOnlyAndExpression() {
  581. return _ReadOnly(Res.GetString(Res.DataColumn_ReadOnlyAndExpression));
  582. }
  583. static public Exception ReadOnly(string column) {
  584. return _ReadOnly(Res.GetString(Res.DataColumn_ReadOnly, column));
  585. }
  586. static public Exception UniqueAndExpression() {
  587. return _Argument(Res.GetString(Res.DataColumn_UniqueAndExpression));
  588. }
  589. static public Exception SetFailed(object value, DataColumn column, Type type, Exception innerException) {
  590. return _Argument(innerException.Message + Res.GetString(Res.DataColumn_SetFailed, value.ToString(), column.ColumnName, type.Name), innerException);
  591. }
  592. static public Exception CannotSetToNull(DataColumn column) {
  593. return _Argument(Res.GetString(Res.DataColumn_CannotSetToNull, column.ColumnName));
  594. }
  595. static public Exception LongerThanMaxLength(DataColumn column) {
  596. return _Argument(Res.GetString(Res.DataColumn_LongerThanMaxLength, column.ColumnName));
  597. }
  598. static public Exception CannotSetMaxLength(DataColumn column, int value) {
  599. return _Argument(Res.GetString(Res.DataColumn_CannotSetMaxLength, column.ColumnName, value.ToString(CultureInfo.InvariantCulture)));
  600. }
  601. static public Exception CannotSetMaxLength2(DataColumn column) {
  602. return _Argument(Res.GetString(Res.DataColumn_CannotSetMaxLength2, column.ColumnName));
  603. }
  604. static public Exception CannotSetSimpleContentType(String columnName, Type type) {
  605. return _Argument(Res.GetString(Res.DataColumn_CannotSimpleContentType, columnName, type));
  606. }
  607. static public Exception CannotSetSimpleContent(String columnName, Type type) {
  608. return _Argument(Res.GetString(Res.DataColumn_CannotSimpleContent, columnName, type));
  609. }
  610. static public Exception CannotChangeNamespace(String columnName) {
  611. return _Argument(Res.GetString(Res.DataColumn_CannotChangeNamespace, columnName));
  612. }
  613. static public Exception HasToBeStringType(DataColumn column) {
  614. return _Argument(Res.GetString(Res.DataColumn_HasToBeStringType, column.ColumnName));
  615. }
  616. static public Exception AutoIncrementCannotSetIfHasData(string typeName) {
  617. return _Argument(Res.GetString(Res.DataColumn_AutoIncrementCannotSetIfHasData, typeName));
  618. }
  619. static public Exception INullableUDTwithoutStaticNull(string typeName) {
  620. return _Argument(Res.GetString( Res.DataColumn_INullableUDTwithoutStaticNull, typeName));
  621. }
  622. static public Exception IComparableNotImplemented(string typeName) {
  623. return _Data(Res.GetString(Res.DataStorage_IComparableNotDefined, typeName));
  624. }
  625. static public Exception UDTImplementsIChangeTrackingButnotIRevertible(string typeName) {
  626. return _InvalidOperation(Res.GetString(Res.DataColumn_UDTImplementsIChangeTrackingButnotIRevertible, typeName));
  627. }
  628. static public Exception SetAddedAndModifiedCalledOnnonUnchanged() {
  629. return _InvalidOperation(Res.GetString(Res.DataColumn_SetAddedAndModifiedCalledOnNonUnchanged));
  630. }
  631. static public Exception InvalidDataColumnMapping(Type type) {
  632. return _Argument(Res.GetString(Res.DataColumn_InvalidDataColumnMapping, type.AssemblyQualifiedName));
  633. }
  634. static public Exception CannotSetDateTimeModeForNonDateTimeColumns() {
  635. return _InvalidOperation(Res.GetString(Res.DataColumn_CannotSetDateTimeModeForNonDateTimeColumns));
  636. }
  637. static public Exception InvalidDateTimeMode(DataSetDateTime mode) {
  638. return _InvalidEnumArgumentException<DataSetDateTime>(mode);
  639. }
  640. static public Exception CantChangeDateTimeMode(DataSetDateTime oldValue, DataSetDateTime newValue) {
  641. return _InvalidOperation(Res.GetString(Res.DataColumn_DateTimeMode, oldValue.ToString(), newValue.ToString()));
  642. }
  643. static public Exception ColumnTypeNotSupported() {
  644. return System.Data.Common.ADP.NotSupported(Res.GetString(Res.DataColumn_NullableTypesNotSupported));
  645. }
  646. //
  647. // DataView
  648. //
  649. static public Exception SetFailed(string name) {
  650. return _Data(Res.GetString(Res.DataView_SetFailed, name));
  651. }
  652. static public Exception SetDataSetFailed() {
  653. return _Data(Res.GetString(Res.DataView_SetDataSetFailed));
  654. }
  655. static public Exception SetRowStateFilter() {
  656. return _Data(Res.GetString(Res.DataView_SetRowStateFilter));
  657. }
  658. static public Exception CanNotSetDataSet() {
  659. return _Data(Res.GetString(Res.DataView_CanNotSetDataSet));
  660. }
  661. static public Exception CanNotUseDataViewManager() {
  662. return _Data(Res.GetString(Res.DataView_CanNotUseDataViewManager));
  663. }
  664. static public Exception CanNotSetTable() {
  665. return _Data(Res.GetString(Res.DataView_CanNotSetTable));
  666. }
  667. static public Exception CanNotUse() {
  668. return _Data(Res.GetString(Res.DataView_CanNotUse));
  669. }
  670. static public Exception CanNotBindTable() {
  671. return _Data(Res.GetString(Res.DataView_CanNotBindTable));
  672. }
  673. static public Exception SetTable() {
  674. return _Data(Res.GetString(Res.DataView_SetTable));
  675. }
  676. static public Exception SetIListObject() {
  677. return _Argument(Res.GetString(Res.DataView_SetIListObject));
  678. }
  679. static public Exception AddNewNotAllowNull() {
  680. return _Data(Res.GetString(Res.DataView_AddNewNotAllowNull));
  681. }
  682. static public Exception NotOpen() {
  683. return _Data(Res.GetString(Res.DataView_NotOpen));
  684. }
  685. static public Exception CreateChildView() {
  686. return _Argument(Res.GetString(Res.DataView_CreateChildView));
  687. }
  688. static public Exception CanNotDelete() {
  689. return _Data(Res.GetString(Res.DataView_CanNotDelete));
  690. }
  691. static public Exception CanNotEdit() {
  692. return _Data(Res.GetString(Res.DataView_CanNotEdit));
  693. }
  694. static public Exception GetElementIndex(Int32 index) {
  695. return _IndexOutOfRange(Res.GetString(Res.DataView_GetElementIndex, (index).ToString(CultureInfo.InvariantCulture)));
  696. }
  697. static public Exception AddExternalObject() {
  698. return _Argument(Res.GetString(Res.DataView_AddExternalObject));
  699. }
  700. static public Exception CanNotClear() {
  701. return _Argument(Res.GetString(Res.DataView_CanNotClear));
  702. }
  703. static public Exception InsertExternalObject() {
  704. return _Argument(Res.GetString(Res.DataView_InsertExternalObject));
  705. }
  706. static public Exception RemoveExternalObject() {
  707. return _Argument(Res.GetString(Res.DataView_RemoveExternalObject));
  708. }
  709. static public Exception PropertyNotFound(string property, string table) {
  710. return _Argument(Res.GetString(Res.DataROWView_PropertyNotFound, property, table));
  711. }
  712. static public Exception ColumnToSortIsOutOfRange(string column) {
  713. return _Argument(Res.GetString(Res.DataColumns_OutOfRange, column));
  714. }
  715. //
  716. // Keys
  717. //
  718. static public Exception KeyTableMismatch() {
  719. return _InvalidConstraint(Res.GetString(Res.DataKey_TableMismatch));
  720. }
  721. static public Exception KeyNoColumns() {
  722. return _InvalidConstraint(Res.GetString(Res.DataKey_NoColumns));
  723. }
  724. static public Exception KeyTooManyColumns(int cols) {
  725. return _InvalidConstraint(Res.GetString(Res.DataKey_TooManyColumns, (cols).ToString(CultureInfo.InvariantCulture)));
  726. }
  727. static public Exception KeyDuplicateColumns(string columnName) {
  728. return _InvalidConstraint(Res.GetString(Res.DataKey_DuplicateColumns, columnName));
  729. }
  730. //
  731. // Relations, constraints
  732. //
  733. static public Exception RelationDataSetMismatch() {
  734. return _InvalidConstraint(Res.GetString(Res.DataRelation_DataSetMismatch));
  735. }
  736. static public Exception NoRelationName() {
  737. return _Argument(Res.GetString(Res.DataRelation_NoName));
  738. }
  739. static public Exception ColumnsTypeMismatch() {
  740. return _InvalidConstraint(Res.GetString(Res.DataRelation_ColumnsTypeMismatch));
  741. }
  742. static public Exception KeyLengthMismatch() {
  743. return _Argument(Res.GetString(Res.DataRelation_KeyLengthMismatch));
  744. }
  745. static public Exception KeyLengthZero() {
  746. return _Argument(Res.GetString(Res.DataRelation_KeyZeroLength));
  747. }
  748. static public Exception ForeignRelation() {
  749. return _Argument(Res.GetString(Res.DataRelation_ForeignDataSet));
  750. }
  751. static public Exception KeyColumnsIdentical() {
  752. return _InvalidConstraint(Res.GetString(Res.DataRelation_KeyColumnsIdentical));
  753. }
  754. static public Exception RelationForeignTable(string t1, string t2) {
  755. return _InvalidConstraint(Res.GetString(Res.DataRelation_ForeignTable, t1, t2));
  756. }
  757. static public Exception GetParentRowTableMismatch(string t1, string t2) {
  758. return _InvalidConstraint(Res.GetString(Res.DataRelation_GetParentRowTableMismatch, t1, t2));
  759. }
  760. static public Exception SetParentRowTableMismatch(string t1, string t2) {
  761. return _InvalidConstraint(Res.GetString(Res.DataRelation_SetParentRowTableMismatch, t1, t2));
  762. }
  763. static public Exception RelationForeignRow() {
  764. return _Argument(Res.GetString(Res.DataRelation_ForeignRow));
  765. }
  766. static public Exception RelationNestedReadOnly() {
  767. return _Argument(Res.GetString(Res.DataRelation_RelationNestedReadOnly));
  768. }
  769. static public Exception TableCantBeNestedInTwoTables(string tableName) {
  770. return _Argument(Res.GetString(Res.DataRelation_TableCantBeNestedInTwoTables, tableName));
  771. }
  772. static public Exception LoopInNestedRelations(string tableName) {
  773. return _Argument(Res.GetString(Res.DataRelation_LoopInNestedRelations, tableName));
  774. }
  775. static public Exception RelationDoesNotExist() {
  776. return _Argument(Res.GetString(Res.DataRelation_DoesNotExist));
  777. }
  778. static public Exception ParentRowNotInTheDataSet() {
  779. return _Argument(Res.GetString(Res.DataRow_ParentRowNotInTheDataSet));
  780. }
  781. static public Exception ParentOrChildColumnsDoNotHaveDataSet() {
  782. return _InvalidConstraint(Res.GetString(Res.DataRelation_ParentOrChildColumnsDoNotHaveDataSet));
  783. }
  784. static public Exception InValidNestedRelation(string childTableName) {
  785. return _InvalidOperation(Res.GetString(Res.DataRelation_InValidNestedRelation, childTableName));
  786. }
  787. static public Exception InvalidParentNamespaceinNestedRelation(string childTableName) {
  788. return _InvalidOperation(Res.GetString(Res.DataRelation_InValidNamespaceInNestedRelation, childTableName));
  789. }
  790. //
  791. // Rows
  792. //
  793. static public Exception RowNotInTheDataSet() {
  794. return _Argument(Res.GetString(Res.DataRow_NotInTheDataSet));
  795. }
  796. static public Exception RowNotInTheTable() {
  797. return _RowNotInTable(Res.GetString(Res.DataRow_NotInTheTable));
  798. }
  799. static public Exception EditInRowChanging() {
  800. return _InRowChangingEvent(Res.GetString(Res.DataRow_EditInRowChanging));
  801. }
  802. static public Exception EndEditInRowChanging() {
  803. return _InRowChangingEvent(Res.GetString(Res.DataRow_EndEditInRowChanging));
  804. }
  805. static public Exception BeginEditInRowChanging() {
  806. return _InRowChangingEvent(Res.GetString(Res.DataRow_BeginEditInRowChanging));
  807. }
  808. static public Exception CancelEditInRowChanging() {
  809. return _InRowChangingEvent(Res.GetString(Res.DataRow_CancelEditInRowChanging));
  810. }
  811. static public Exception DeleteInRowDeleting() {
  812. return _InRowChangingEvent(Res.GetString(Res.DataRow_DeleteInRowDeleting));
  813. }
  814. static public Exception ValueArrayLength() {
  815. return _Argument(Res.GetString(Res.DataRow_ValuesArrayLength));
  816. }
  817. static public Exception NoCurrentData() {
  818. return _VersionNotFound(Res.GetString(Res.DataRow_NoCurrentData));
  819. }
  820. static public Exception NoOriginalData() {
  821. return _VersionNotFound(Res.GetString(Res.DataRow_NoOriginalData));
  822. }
  823. static public Exception NoProposedData() {
  824. return _VersionNotFound(Res.GetString(Res.DataRow_NoProposedData));
  825. }
  826. static public Exception RowRemovedFromTheTable() {
  827. return _RowNotInTable(Res.GetString(Res.DataRow_RemovedFromTheTable));
  828. }
  829. static public Exception DeletedRowInaccessible() {
  830. return _DeletedRowInaccessible(Res.GetString(Res.DataRow_DeletedRowInaccessible));
  831. }
  832. static public Exception RowAlreadyDeleted() {
  833. return _DeletedRowInaccessible(Res.GetString(Res.DataRow_AlreadyDeleted));
  834. }
  835. static public Exception RowEmpty() {
  836. return _Argument(Res.GetString(Res.DataRow_Empty));
  837. }
  838. static public Exception InvalidRowVersion() {
  839. return _Data(Res.GetString(Res.DataRow_InvalidVersion));
  840. }
  841. static public Exception RowOutOfRange() {
  842. return _IndexOutOfRange(Res.GetString(Res.DataRow_RowOutOfRange));
  843. }
  844. static public Exception RowOutOfRange(int index) {
  845. return _IndexOutOfRange(Res.GetString(Res.DataRow_OutOfRange, (index).ToString(CultureInfo.InvariantCulture)));
  846. }
  847. static public Exception RowInsertOutOfRange(int index) {
  848. return _IndexOutOfRange(Res.GetString(Res.DataRow_RowInsertOutOfRange, (index).ToString(CultureInfo.InvariantCulture)));
  849. }
  850. static public Exception RowInsertTwice(int index, string tableName) {
  851. return _IndexOutOfRange(Res.GetString(Res.DataRow_RowInsertTwice, (index).ToString(CultureInfo.InvariantCulture), tableName));
  852. }
  853. static public Exception RowInsertMissing( string tableName) {
  854. return _IndexOutOfRange(Res.GetString(Res.DataRow_RowInsertMissing, tableName));
  855. }
  856. static public Exception RowAlreadyRemoved() {
  857. return _Data(Res.GetString(Res.DataRow_AlreadyRemoved));
  858. }
  859. static public Exception MultipleParents() {
  860. return _Data(Res.GetString(Res.DataRow_MultipleParents));
  861. }
  862. static public Exception InvalidRowState(DataRowState state) {
  863. return _InvalidEnumArgumentException<DataRowState>(state);
  864. }
  865. static public Exception InvalidRowBitPattern() {
  866. return _Argument(Res.GetString(Res.DataRow_InvalidRowBitPattern));
  867. }
  868. //
  869. // DataSet
  870. //
  871. static internal Exception SetDataSetNameToEmpty() {
  872. return _Argument(Res.GetString(Res.DataSet_SetNameToEmpty));
  873. }
  874. static internal Exception SetDataSetNameConflicting(string name) {
  875. return _Argument(Res.GetString(Res.DataSet_SetDataSetNameConflicting, name));
  876. }
  877. static public Exception DataSetUnsupportedSchema(string ns) {
  878. return _Argument(Res.GetString(Res.DataSet_UnsupportedSchema, ns));
  879. }
  880. static public Exception MergeMissingDefinition(string obj) {
  881. return _Argument(Res.GetString(Res.DataMerge_MissingDefinition, obj));
  882. }
  883. static public Exception TablesInDifferentSets() {
  884. return _Argument(Res.GetString(Res.DataRelation_TablesInDifferentSets));
  885. }
  886. static public Exception RelationAlreadyExists() {
  887. return _Argument(Res.GetString(Res.DataRelation_AlreadyExists));
  888. }
  889. static public Exception RowAlreadyInOtherCollection() {
  890. return _Argument(Res.GetString(Res.DataRow_AlreadyInOtherCollection));
  891. }
  892. static public Exception RowAlreadyInTheCollection() {
  893. return _Argument(Res.GetString(Res.DataRow_AlreadyInTheCollection));
  894. }
  895. static public Exception TableMissingPrimaryKey() {
  896. return _MissingPrimaryKey(Res.GetString(Res.DataTable_MissingPrimaryKey));
  897. }
  898. static public Exception RecordStateRange() {
  899. return _Argument(Res.GetString(Res.DataIndex_RecordStateRange));
  900. }
  901. static public Exception IndexKeyLength(int length, int keyLength) {
  902. if(length == 0) {
  903. return _Argument(Res.GetString(Res.DataIndex_FindWithoutSortOrder));
  904. }
  905. else {
  906. return _Argument(Res.GetString(Res.DataIndex_KeyLength, (length).ToString(CultureInfo.InvariantCulture), (keyLength).ToString(CultureInfo.InvariantCulture)));
  907. }
  908. }
  909. static public Exception RemovePrimaryKey(DataTable table) {
  910. if (table.TableName.Length == 0) {
  911. return _Argument(Res.GetString(Res.DataKey_RemovePrimaryKey));
  912. }
  913. else {
  914. return _Argument(Res.GetString(Res.DataKey_RemovePrimaryKey1, table.TableName));
  915. }
  916. }
  917. static public Exception RelationAlreadyInOtherDataSet() {
  918. return _Argument(Res.GetString(Res.DataRelation_AlreadyInOtherDataSet));
  919. }
  920. static public Exception RelationAlreadyInTheDataSet() {
  921. return _Argument(Res.GetString(Res.DataRelation_AlreadyInTheDataSet));
  922. }
  923. static public Exception RelationNotInTheDataSet(string relation) {
  924. return _Argument(Res.GetString(Res.DataRelation_NotInTheDataSet,relation));
  925. }
  926. static public Exception RelationOutOfRange(object index) {
  927. return _IndexOutOfRange(Res.GetString(Res.DataRelation_OutOfRange, Convert.ToString(index, null)));
  928. }
  929. static public Exception DuplicateRelation(string relation) {
  930. return _DuplicateName(Res.GetString(Res.DataRelation_DuplicateName, relation));
  931. }
  932. static public Exception RelationTableNull() {
  933. return _Argument(Res.GetString(Res.DataRelation_TableNull));
  934. }
  935. static public Exception RelationDataSetNull() {
  936. return _Argument(Res.GetString(Res.DataRelation_TableNull));
  937. }
  938. static public Exception RelationTableWasRemoved() {
  939. return _Argument(Res.GetString(Res.DataRelation_TableWasRemoved));
  940. }
  941. static public Exception ParentTableMismatch() {
  942. return _Argument(Res.GetString(Res.DataRelation_ParentTableMismatch));
  943. }
  944. static public Exception ChildTableMismatch() {
  945. return _Argument(Res.GetString(Res.DataRelation_ChildTableMismatch));
  946. }
  947. static public Exception EnforceConstraint() {
  948. return _Constraint(Res.GetString(Res.Data_EnforceConstraints));
  949. }
  950. static public Exception CaseLocaleMismatch() {
  951. return _Argument(Res.GetString(Res.DataRelation_CaseLocaleMismatch));
  952. }
  953. static public Exception CannotChangeCaseLocale() {
  954. return CannotChangeCaseLocale(null);
  955. }
  956. static public Exception CannotChangeCaseLocale(Exception innerException) {
  957. return _Argument(Res.GetString(Res.DataSet_CannotChangeCaseLocale), innerException);
  958. }
  959. static public Exception CannotChangeSchemaSerializationMode() {
  960. return _InvalidOperation(Res.GetString(Res.DataSet_CannotChangeSchemaSerializationMode));
  961. }
  962. static public Exception InvalidSchemaSerializationMode(Type enumType, string mode) {
  963. return _InvalidEnumArgumentException(Res.GetString(Res.ADP_InvalidEnumerationValue, enumType.Name, mode));
  964. }
  965. static public Exception InvalidRemotingFormat(SerializationFormat mode) {
  966. #if DEBUG
  967. switch(mode) {
  968. case SerializationFormat.Xml:
  969. case SerializationFormat.Binary:
  970. Debug.Assert(false, "valid SerializationFormat " + mode.ToString());
  971. break;
  972. }
  973. #endif
  974. return _InvalidEnumArgumentException<SerializationFormat>(mode);
  975. }
  976. //
  977. // DataTable and DataTableCollection
  978. //
  979. static public Exception TableForeignPrimaryKey() {
  980. return _Argument(Res.GetString(Res.DataTable_ForeignPrimaryKey));
  981. }
  982. static public Exception TableCannotAddToSimpleContent() {
  983. return _Argument(Res.GetString(Res.DataTable_CannotAddToSimpleContent));
  984. }
  985. static public Exception NoTableName() {
  986. return _Argument(Res.GetString(Res.DataTable_NoName));
  987. }
  988. static public Exception MultipleTextOnlyColumns() {
  989. return _Argument(Res.GetString(Res.DataTable_MultipleSimpleContentColumns));
  990. }
  991. static public Exception InvalidSortString(string sort) {
  992. return _Argument(Res.GetString(Res.DataTable_InvalidSortString, sort));
  993. }
  994. static public Exception DuplicateTableName(string table) {
  995. return _DuplicateName(Res.GetString(Res.DataTable_DuplicateName, table));
  996. }
  997. static public Exception DuplicateTableName2(string table, string ns) {
  998. return _DuplicateName(Res.GetString(Res.DataTable_DuplicateName2, table, ns));
  999. }
  1000. static public Exception SelfnestedDatasetConflictingName(string table) {
  1001. return _DuplicateName(Res.GetString(Res.DataTable_SelfnestedDatasetConflictingName, table));
  1002. }
  1003. static public Exception DatasetConflictingName(string table) {
  1004. return _DuplicateName(Res.GetString(Res.DataTable_DatasetConflictingName, table));
  1005. }
  1006. static public Exception TableAlreadyInOtherDataSet() {
  1007. return _Argument(Res.GetString(Res.DataTable_AlreadyInOtherDataSet));
  1008. }
  1009. static public Exception TableAlreadyInTheDataSet() {
  1010. return _Argument(Res.GetString(Res.DataTable_AlreadyInTheDataSet));
  1011. }
  1012. static public Exception TableOutOfRange(int index) {
  1013. return _IndexOutOfRange(Res.GetString(Res.DataTable_OutOfRange, (index).ToString(CultureInfo.InvariantCulture)));
  1014. }
  1015. static public Exception TableNotInTheDataSet(string table) {
  1016. return _Argument(Res.GetString(Res.DataTable_NotInTheDataSet, table));
  1017. }
  1018. static public Exception TableInRelation() {
  1019. return _Argument(Res.GetString(Res.DataTable_InRelation));
  1020. }
  1021. static public Exception TableInConstraint(DataTable table, Constraint constraint) {
  1022. return _Argument(Res.GetString(Res.DataTable_InConstraint, table.TableName, constraint.ConstraintName));
  1023. }
  1024. static public Exception CanNotSerializeDataTableHierarchy() {
  1025. return _InvalidOperation(Res.GetString(Res.DataTable_CanNotSerializeDataTableHierarchy));
  1026. }
  1027. static public Exception CanNotRemoteDataTable() {
  1028. return _InvalidOperation(Res.GetString(Res.DataTable_CanNotRemoteDataTable));
  1029. }
  1030. static public Exception CanNotSetRemotingFormat() {
  1031. return _Argument(Res.GetString(Res.DataTable_CanNotSetRemotingFormat));
  1032. }
  1033. static public Exception CanNotSerializeDataTableWithEmptyName() {
  1034. return _InvalidOperation(Res.GetString(Res.DataTable_CanNotSerializeDataTableWithEmptyName));
  1035. }
  1036. static public Exception TableNotFound (string tableName) {
  1037. return _Argument(Res.GetString(Res.DataTable_TableNotFound, tableName));
  1038. }
  1039. //
  1040. // Storage
  1041. //
  1042. static public Exception AggregateException(AggregateType aggregateType, Type type) {
  1043. return _Data(Res.GetString(Res.DataStorage_AggregateException, aggregateType.ToString(), type.Name));
  1044. }
  1045. static public Exception InvalidStorageType(TypeCode typecode) {
  1046. return _Data(Res.GetString(Res.DataStorage_InvalidStorageType, ((Enum) typecode).ToString()));
  1047. }
  1048. static public Exception RangeArgument(Int32 min, Int32 max) {
  1049. return _Argument(Res.GetString(Res.Range_Argument, (min).ToString(CultureInfo.InvariantCulture), (max).ToString(CultureInfo.InvariantCulture)));
  1050. }
  1051. static public Exception NullRange() {
  1052. return _Data(Res.GetString(Res.Range_NullRange));
  1053. }
  1054. static public Exception NegativeMinimumCapacity() {
  1055. return _Argument(Res.GetString(Res.RecordManager_MinimumCapacity));
  1056. }
  1057. static public Exception ProblematicChars(char charValue) {
  1058. string xchar = "0x" + ((UInt16)charValue).ToString("X", CultureInfo.InvariantCulture);
  1059. return _Argument(Res.GetString(Res.DataStorage_ProblematicChars, xchar));
  1060. }
  1061. static public Exception StorageSetFailed() {
  1062. return _Argument(Res.GetString(Res.DataStorage_SetInvalidDataType));
  1063. }
  1064. //
  1065. // XML schema
  1066. //
  1067. static public Exception SimpleTypeNotSupported() {
  1068. return _Data(Res.GetString(Res.Xml_SimpleTypeNotSupported));
  1069. }
  1070. static public Exception MissingAttribute(string attribute) {
  1071. return MissingAttribute(String.Empty, attribute);
  1072. }
  1073. static public Exception MissingAttribute(string element, string attribute) {
  1074. return _Data(Res.GetString(Res.Xml_MissingAttribute, element, attribute));
  1075. }
  1076. static public Exception InvalidAttributeValue(string name, string value) {
  1077. return _Data(Res.GetString(Res.Xml_ValueOutOfRange, name, value));
  1078. }
  1079. static public Exception AttributeValues(string name, string value1, string value2) {
  1080. return _Data(Res.GetString(Res.Xml_AttributeValues, name, value1, value2));
  1081. }
  1082. static public Exception ElementTypeNotFound(string name) {
  1083. return _Data(Res.GetString(Res.Xml_ElementTypeNotFound, name));
  1084. }
  1085. static public Exception RelationParentNameMissing(string rel) {
  1086. return _Data(Res.GetString(Res.Xml_RelationParentNameMissing, rel));
  1087. }
  1088. static public Exception RelationChildNameMissing(string rel) {
  1089. return _Data(Res.GetString(Res.Xml_RelationChildNameMissing, rel));
  1090. }
  1091. static public Exception RelationTableKeyMissing(string rel) {
  1092. return _Data(Res.GetString(Res.Xml_RelationTableKeyMissing, rel));
  1093. }
  1094. static public Exception RelationChildKeyMissing(string rel) {
  1095. return _Data(Res.GetString(Res.Xml_RelationChildKeyMissing, rel));
  1096. }
  1097. static public Exception UndefinedDatatype(string name) {
  1098. return _Data(Res.GetString(Res.Xml_UndefinedDatatype, name));
  1099. }
  1100. static public Exception DatatypeNotDefined() {
  1101. return _Data(Res.GetString(Res.Xml_DatatypeNotDefined));
  1102. }
  1103. static public Exception MismatchKeyLength() {
  1104. return _Data(Res.GetString(Res.Xml_MismatchKeyLength));
  1105. }
  1106. static public Exception InvalidField(string name) {
  1107. return _Data(Res.GetString(Res.Xml_InvalidField, name));
  1108. }
  1109. static public Exception InvalidSelector(string name) {
  1110. return _Data(Res.GetString(Res.Xml_InvalidSelector, name));
  1111. }
  1112. static public Exception CircularComplexType(string name) {
  1113. return _Data(Res.GetString(Res.Xml_CircularComplexType, name));
  1114. }
  1115. static public Exception CannotInstantiateAbstract(string name) {
  1116. return _Data(Res.GetString(Res.Xml_CannotInstantiateAbstract, name));
  1117. }
  1118. static public Exception InvalidKey(string name) {
  1119. return _Data(Res.GetString(Res.Xml_InvalidKey, name));
  1120. }
  1121. static public Exception DiffgramMissingTable(string name) {
  1122. return _Data(Res.GetString(Res.Xml_MissingTable, name));
  1123. }
  1124. static public Exception DiffgramMissingSQL() {
  1125. return _Data(Res.GetString(Res.Xml_MissingSQL));
  1126. }
  1127. static public Exception DuplicateConstraintRead(string str) {
  1128. return _Data(Res.GetString(Res.Xml_DuplicateConstraint, str));
  1129. }
  1130. static public Exception ColumnTypeConflict(string name) {
  1131. return _Data(Res.GetString(Res.Xml_ColumnConflict, name));
  1132. }
  1133. static public Exception CannotConvert(string name, string type) {
  1134. return _Data(Res.GetString(Res.Xml_CannotConvert, name, type));
  1135. }
  1136. static public Exception MissingRefer(string name) {
  1137. return _Data(Res.GetString(Res.Xml_MissingRefer, Keywords.REFER, Keywords.XSD_KEYREF, name));
  1138. }
  1139. static public Exception InvalidPrefix(string name) {
  1140. return _Data(Res.GetString(Res.Xml_InvalidPrefix, name));
  1141. }
  1142. static public Exception CanNotDeserializeObjectType() {
  1143. return _InvalidOperation(Res.GetString(Res.Xml_CanNotDeserializeObjectType));
  1144. }
  1145. static public Exception IsDataSetAttributeMissingInSchema() {
  1146. return _Data(Res.GetString(Res.Xml_IsDataSetAttributeMissingInSchema));
  1147. }
  1148. static public Exception TooManyIsDataSetAtributeInSchema() {
  1149. return _Data(Res.GetString(Res.Xml_TooManyIsDataSetAtributeInSchema));
  1150. }
  1151. // XML save
  1152. static public Exception NestedCircular(string name) {
  1153. return _Data(Res.GetString(Res.Xml_NestedCircular, name));
  1154. }
  1155. static public Exception MultipleParentRows(string tableQName) {
  1156. return _Data(Res.GetString(Res.Xml_MultipleParentRows, tableQName));
  1157. }
  1158. static public Exception PolymorphismNotSupported(string typeName) {
  1159. return _InvalidOperation(Res.GetString(Res.Xml_PolymorphismNotSupported, typeName));
  1160. }
  1161. static public Exception DataTableInferenceNotSupported() {
  1162. return _InvalidOperation(Res.GetString(Res.Xml_DataTableInferenceNotSupported));
  1163. }
  1164. /// <summary>throw DataException for multitarget failure</summary>
  1165. /// <param name="innerException">exception from multitarget converter</param>
  1166. /// <exception cref="DataException">always thrown</exception>
  1167. static internal void ThrowMultipleTargetConverter(Exception innerException)
  1168. {
  1169. string res = (null != innerException) ? Res.Xml_MultipleTargetConverterError : Res.Xml_MultipleTargetConverterEmpty;
  1170. ThrowDataException(Res.GetString(res), innerException);
  1171. }
  1172. //
  1173. // Merge
  1174. //
  1175. static public Exception DuplicateDeclaration(string name) {
  1176. return _Data(Res.GetString(Res.Xml_MergeDuplicateDeclaration, name));
  1177. }
  1178. //Read Xml data
  1179. static public Exception FoundEntity() {
  1180. return _Data(Res.GetString(Res.Xml_FoundEntity));
  1181. }
  1182. // ATTENTION: name has to be localized string here:
  1183. static public Exception MergeFailed(string name) {
  1184. return _Data(name);
  1185. }
  1186. // SqlConvert
  1187. static public DataException ConvertFailed(Type type1, Type type2) {
  1188. return _Data(Res.GetString(Res.SqlConvert_ConvertFailed, type1.FullName, type2.FullName));
  1189. }
  1190. // DataTableReader
  1191. static public Exception InvalidDataTableReader(string tableName) {
  1192. return _InvalidOperation(Res.GetString(Res.DataTableReader_InvalidDataTableReader, tableName));
  1193. }
  1194. static public Exception DataTableReaderSchemaIsInvalid(string tableName) {
  1195. return _InvalidOperation(Res.GetString(Res.DataTableReader_SchemaInvalidDataTableReader, tableName));
  1196. }
  1197. static public Exception CannotCreateDataReaderOnEmptyDataSet() {
  1198. return _Argument(Res.GetString(Res.DataTableReader_CannotCreateDataReaderOnEmptyDataSet));
  1199. }
  1200. static public Exception DataTableReaderArgumentIsEmpty() {
  1201. return _Argument(Res.GetString(Res.DataTableReader_DataTableReaderArgumentIsEmpty));
  1202. }
  1203. static public Exception ArgumentContainsNullValue() {
  1204. return _Argument(Res.GetString(Res.DataTableReader_ArgumentContainsNullValue));
  1205. }
  1206. static public Exception InvalidCurrentRowInDataTableReader() {
  1207. return _DeletedRowInaccessible(Res.GetString(Res.DataTableReader_InvalidRowInDataTableReader));
  1208. }
  1209. static public Exception EmptyDataTableReader(string tableName) {
  1210. return _DeletedRowInaccessible(Res.GetString(Res.DataTableReader_DataTableCleared, tableName));
  1211. }
  1212. //
  1213. static internal Exception InvalidDuplicateNamedSimpleTypeDelaration(string stName, string errorStr) {
  1214. return _Argument(Res.GetString(Res.NamedSimpleType_InvalidDuplicateNamedSimpleTypeDelaration, stName, errorStr));
  1215. }
  1216. // RbTree
  1217. static internal Exception InternalRBTreeError(RBTreeError internalError) {
  1218. return _InvalidOperation(Res.GetString(Res.RbTree_InvalidState, (int)internalError));
  1219. }
  1220. static public Exception EnumeratorModified() {
  1221. return _InvalidOperation(Res.GetString(Res.RbTree_EnumerationBroken));
  1222. }
  1223. }// ExceptionBuilder
  1224. }