private static string GetResourceString(ExceptionResource resource) { switch (resource) { case ExceptionResource.ArgumentOutOfRange_Index: return(SR.ArgumentOutOfRange_Index); case ExceptionResource.ArgumentOutOfRange_IndexCount: return(SR.ArgumentOutOfRange_IndexCount); case ExceptionResource.ArgumentOutOfRange_IndexCountBuffer: return(SR.ArgumentOutOfRange_IndexCountBuffer); case ExceptionResource.ArgumentOutOfRange_Count: return(SR.ArgumentOutOfRange_Count); case ExceptionResource.ArgumentOutOfRange_Year: return(SR.ArgumentOutOfRange_Year); case ExceptionResource.Arg_ArrayPlusOffTooSmall: return(SR.Arg_ArrayPlusOffTooSmall); case ExceptionResource.NotSupported_ReadOnlyCollection: return(SR.NotSupported_ReadOnlyCollection); case ExceptionResource.Arg_RankMultiDimNotSupported: return(SR.Arg_RankMultiDimNotSupported); case ExceptionResource.Arg_NonZeroLowerBound: return(SR.Arg_NonZeroLowerBound); case ExceptionResource.ArgumentOutOfRange_GetCharCountOverflow: return(SR.ArgumentOutOfRange_GetCharCountOverflow); case ExceptionResource.ArgumentOutOfRange_ListInsert: return(SR.ArgumentOutOfRange_ListInsert); case ExceptionResource.ArgumentOutOfRange_NeedNonNegNum: return(SR.ArgumentOutOfRange_NeedNonNegNum); case ExceptionResource.ArgumentOutOfRange_SmallCapacity: return(SR.ArgumentOutOfRange_SmallCapacity); case ExceptionResource.Argument_InvalidOffLen: return(SR.Argument_InvalidOffLen); case ExceptionResource.Argument_CannotExtractScalar: return(SR.Argument_CannotExtractScalar); case ExceptionResource.ArgumentOutOfRange_BiggerThanCollection: return(SR.ArgumentOutOfRange_BiggerThanCollection); case ExceptionResource.Serialization_MissingKeys: return(SR.Serialization_MissingKeys); case ExceptionResource.Serialization_NullKey: return(SR.Serialization_NullKey); case ExceptionResource.NotSupported_KeyCollectionSet: return(SR.NotSupported_KeyCollectionSet); case ExceptionResource.NotSupported_ValueCollectionSet: return(SR.NotSupported_ValueCollectionSet); case ExceptionResource.InvalidOperation_NullArray: return(SR.InvalidOperation_NullArray); case ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted: return(SR.TaskT_TransitionToFinal_AlreadyCompleted); case ExceptionResource.TaskCompletionSourceT_TrySetException_NullException: return(SR.TaskCompletionSourceT_TrySetException_NullException); case ExceptionResource.TaskCompletionSourceT_TrySetException_NoExceptions: return(SR.TaskCompletionSourceT_TrySetException_NoExceptions); case ExceptionResource.NotSupported_StringComparison: return(SR.NotSupported_StringComparison); case ExceptionResource.ConcurrentCollection_SyncRoot_NotSupported: return(SR.ConcurrentCollection_SyncRoot_NotSupported); case ExceptionResource.Task_MultiTaskContinuation_NullTask: return(SR.Task_MultiTaskContinuation_NullTask); case ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple: return(SR.InvalidOperation_WrongAsyncResultOrEndCalledMultiple); case ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList: return(SR.Task_MultiTaskContinuation_EmptyTaskList); case ExceptionResource.Task_Start_TaskCompleted: return(SR.Task_Start_TaskCompleted); case ExceptionResource.Task_Start_Promise: return(SR.Task_Start_Promise); case ExceptionResource.Task_Start_ContinuationTask: return(SR.Task_Start_ContinuationTask); case ExceptionResource.Task_Start_AlreadyStarted: return(SR.Task_Start_AlreadyStarted); case ExceptionResource.Task_RunSynchronously_Continuation: return(SR.Task_RunSynchronously_Continuation); case ExceptionResource.Task_RunSynchronously_Promise: return(SR.Task_RunSynchronously_Promise); case ExceptionResource.Task_RunSynchronously_TaskCompleted: return(SR.Task_RunSynchronously_TaskCompleted); case ExceptionResource.Task_RunSynchronously_AlreadyStarted: return(SR.Task_RunSynchronously_AlreadyStarted); case ExceptionResource.AsyncMethodBuilder_InstanceNotInitialized: return(SR.AsyncMethodBuilder_InstanceNotInitialized); case ExceptionResource.Task_ContinueWith_ESandLR: return(SR.Task_ContinueWith_ESandLR); case ExceptionResource.Task_ContinueWith_NotOnAnything: return(SR.Task_ContinueWith_NotOnAnything); case ExceptionResource.Task_InvalidTimerTimeSpan: return(SR.Task_InvalidTimerTimeSpan); case ExceptionResource.Task_Delay_InvalidMillisecondsDelay: return(SR.Task_Delay_InvalidMillisecondsDelay); case ExceptionResource.Task_Dispose_NotCompleted: return(SR.Task_Dispose_NotCompleted); case ExceptionResource.Task_ThrowIfDisposed: return(SR.Task_ThrowIfDisposed); case ExceptionResource.Task_WaitMulti_NullTask: return(SR.Task_WaitMulti_NullTask); case ExceptionResource.ArgumentException_OtherNotArrayOfCorrectLength: return(SR.ArgumentException_OtherNotArrayOfCorrectLength); case ExceptionResource.ArgumentNull_Array: return(SR.ArgumentNull_Array); case ExceptionResource.ArgumentNull_SafeHandle: return(SR.ArgumentNull_SafeHandle); case ExceptionResource.ArgumentOutOfRange_EndIndexStartIndex: return(SR.ArgumentOutOfRange_EndIndexStartIndex); case ExceptionResource.ArgumentOutOfRange_Enum: return(SR.ArgumentOutOfRange_Enum); case ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported: return(SR.ArgumentOutOfRange_HugeArrayNotSupported); case ExceptionResource.Argument_AddingDuplicate: return(SR.Argument_AddingDuplicate); case ExceptionResource.Argument_InvalidArgumentForComparison: return(SR.Argument_InvalidArgumentForComparison); case ExceptionResource.Arg_LowerBoundsMustMatch: return(SR.Arg_LowerBoundsMustMatch); case ExceptionResource.Arg_MustBeType: return(SR.Arg_MustBeType); case ExceptionResource.Arg_Need1DArray: return(SR.Arg_Need1DArray); case ExceptionResource.Arg_Need2DArray: return(SR.Arg_Need2DArray); case ExceptionResource.Arg_Need3DArray: return(SR.Arg_Need3DArray); case ExceptionResource.Arg_NeedAtLeast1Rank: return(SR.Arg_NeedAtLeast1Rank); case ExceptionResource.Arg_RankIndices: return(SR.Arg_RankIndices); case ExceptionResource.Arg_RanksAndBounds: return(SR.Arg_RanksAndBounds); case ExceptionResource.InvalidOperation_IComparerFailed: return(SR.InvalidOperation_IComparerFailed); case ExceptionResource.NotSupported_FixedSizeCollection: return(SR.NotSupported_FixedSizeCollection); case ExceptionResource.Rank_MultiDimNotSupported: return(SR.Rank_MultiDimNotSupported); case ExceptionResource.Arg_TypeNotSupported: return(SR.Arg_TypeNotSupported); case ExceptionResource.Argument_SpansMustHaveSameLength: return(SR.Argument_SpansMustHaveSameLength); case ExceptionResource.Argument_InvalidFlag: return(SR.Argument_InvalidFlag); default: Debug.Fail("The enum value is not defined, please check the ExceptionResource Enum."); return(""); } }
private static string?InternalGetResourceString(string?key) { if (key == null || key.Length == 0) { Debug.Fail("SR::GetResourceString with null or empty key. Bug in caller, or weird recursive loading problem?"); return(key !); } // We have a somewhat common potential for infinite // loops with mscorlib's ResourceManager. If "potentially dangerous" // code throws an exception, we will get into an infinite loop // inside the ResourceManager and this "potentially dangerous" code. // Potentially dangerous code includes the IO package, CultureInfo, // parts of the loader, some parts of Reflection, Security (including // custom user-written permissions that may parse an XML file at // class load time), assembly load event handlers, etc. Essentially, // this is not a bounded set of code, and we need to fix the problem. // Fortunately, this is limited to mscorlib's error lookups and is NOT // a general problem for all user code using the ResourceManager. // The solution is to make sure only one thread at a time can call // GetResourceString. Also, since resource lookups can be // reentrant, if the same thread comes into GetResourceString // twice looking for the exact same resource name before // returning, we're going into an infinite loop and we should // return a bogus string. bool lockTaken = false; try { Monitor.Enter(_lock, ref lockTaken); // Are we recursively looking up the same resource? Note - our backout code will set // the ResourceHelper's currentlyLoading stack to null if an exception occurs. if (_currentlyLoading != null && _currentlyLoading.Count > 0 && _currentlyLoading.LastIndexOf(key) != -1) { // We can start infinitely recursing for one resource lookup, // then during our failure reporting, start infinitely recursing again. // avoid that. if (_infinitelyRecursingCount > 0) { return(key); } _infinitelyRecursingCount++; // Note: our infrastructure for reporting this exception will again cause resource lookup. // This is the most direct way of dealing with that problem. string message = $"Infinite recursion during resource lookup within {System.CoreLib.Name}. This may be a bug in {System.CoreLib.Name}, or potentially in certain extensibility points such as assembly resolve events or CultureInfo names. Resource name: {key}"; Environment.FailFast(message); } _currentlyLoading ??= new List <string>(); // Call class constructors preemptively, so that we cannot get into an infinite // loop constructing a TypeInitializationException. If this were omitted, // we could get the Infinite recursion assert above by failing type initialization // between the Push and Pop calls below. if (!_resourceManagerInited) { RuntimeHelpers.RunClassConstructor(typeof(ResourceManager).TypeHandle); RuntimeHelpers.RunClassConstructor(typeof(ResourceReader).TypeHandle); RuntimeHelpers.RunClassConstructor(typeof(RuntimeResourceSet).TypeHandle); RuntimeHelpers.RunClassConstructor(typeof(BinaryReader).TypeHandle); _resourceManagerInited = true; } _currentlyLoading.Add(key); // Push string?s = ResourceManager.GetString(key, null); _currentlyLoading.RemoveAt(_currentlyLoading.Count - 1); // Pop Debug.Assert(s != null, "Managed resource string lookup failed. Was your resource name misspelled? Did you rebuild mscorlib after adding a resource to resources.txt? Debug this w/ cordbg and bug whoever owns the code that called SR.GetResourceString. Resource name was: \"" + key + "\""); return(s ?? key); } catch { if (lockTaken) { // Backout code - throw away potentially corrupt state s_resourceManager = null; _currentlyLoading = null; } throw; } finally { if (lockTaken) { Monitor.Exit(_lock); } } }
private static string GetArgumentName(ExceptionArgument argument) { switch (argument) { case ExceptionArgument.obj: return("obj"); case ExceptionArgument.dictionary: return("dictionary"); case ExceptionArgument.array: return("array"); case ExceptionArgument.info: return("info"); case ExceptionArgument.key: return("key"); case ExceptionArgument.text: return("text"); case ExceptionArgument.values: return("values"); case ExceptionArgument.value: return("value"); case ExceptionArgument.startIndex: return("startIndex"); case ExceptionArgument.task: return("task"); case ExceptionArgument.bytes: return("bytes"); case ExceptionArgument.byteIndex: return("byteIndex"); case ExceptionArgument.byteCount: return("byteCount"); case ExceptionArgument.ch: return("ch"); case ExceptionArgument.chars: return("chars"); case ExceptionArgument.charIndex: return("charIndex"); case ExceptionArgument.charCount: return("charCount"); case ExceptionArgument.s: return("s"); case ExceptionArgument.input: return("input"); case ExceptionArgument.ownedMemory: return("ownedMemory"); case ExceptionArgument.list: return("list"); case ExceptionArgument.index: return("index"); case ExceptionArgument.capacity: return("capacity"); case ExceptionArgument.collection: return("collection"); case ExceptionArgument.item: return("item"); case ExceptionArgument.converter: return("converter"); case ExceptionArgument.match: return("match"); case ExceptionArgument.count: return("count"); case ExceptionArgument.action: return("action"); case ExceptionArgument.comparison: return("comparison"); case ExceptionArgument.exceptions: return("exceptions"); case ExceptionArgument.exception: return("exception"); case ExceptionArgument.pointer: return("pointer"); case ExceptionArgument.start: return("start"); case ExceptionArgument.format: return("format"); case ExceptionArgument.culture: return("culture"); case ExceptionArgument.comparer: return("comparer"); case ExceptionArgument.comparable: return("comparable"); case ExceptionArgument.source: return("source"); case ExceptionArgument.state: return("state"); case ExceptionArgument.length: return("length"); case ExceptionArgument.comparisonType: return("comparisonType"); case ExceptionArgument.manager: return("manager"); case ExceptionArgument.sourceBytesToCopy: return("sourceBytesToCopy"); case ExceptionArgument.callBack: return("callBack"); case ExceptionArgument.creationOptions: return("creationOptions"); case ExceptionArgument.function: return("function"); case ExceptionArgument.scheduler: return("scheduler"); case ExceptionArgument.continuationAction: return("continuationAction"); case ExceptionArgument.continuationFunction: return("continuationFunction"); case ExceptionArgument.tasks: return("tasks"); case ExceptionArgument.asyncResult: return("asyncResult"); case ExceptionArgument.beginMethod: return("beginMethod"); case ExceptionArgument.endMethod: return("endMethod"); case ExceptionArgument.endFunction: return("endFunction"); case ExceptionArgument.cancellationToken: return("cancellationToken"); case ExceptionArgument.continuationOptions: return("continuationOptions"); case ExceptionArgument.delay: return("delay"); case ExceptionArgument.millisecondsDelay: return("millisecondsDelay"); case ExceptionArgument.millisecondsTimeout: return("millisecondsTimeout"); case ExceptionArgument.stateMachine: return("stateMachine"); case ExceptionArgument.timeout: return("timeout"); case ExceptionArgument.type: return("type"); case ExceptionArgument.sourceIndex: return("sourceIndex"); case ExceptionArgument.sourceArray: return("sourceArray"); case ExceptionArgument.destinationIndex: return("destinationIndex"); case ExceptionArgument.destinationArray: return("destinationArray"); case ExceptionArgument.pHandle: return("pHandle"); case ExceptionArgument.other: return("other"); case ExceptionArgument.newSize: return("newSize"); case ExceptionArgument.lowerBounds: return("lowerBounds"); case ExceptionArgument.lengths: return("lengths"); case ExceptionArgument.len: return("len"); case ExceptionArgument.keys: return("keys"); case ExceptionArgument.indices: return("indices"); case ExceptionArgument.index1: return("index1"); case ExceptionArgument.index2: return("index2"); case ExceptionArgument.index3: return("index3"); case ExceptionArgument.length1: return("length1"); case ExceptionArgument.length2: return("length2"); case ExceptionArgument.length3: return("length3"); case ExceptionArgument.endIndex: return("endIndex"); case ExceptionArgument.elementType: return("elementType"); case ExceptionArgument.arrayIndex: return("arrayIndex"); case ExceptionArgument.year: return("year"); case ExceptionArgument.codePoint: return("codePoint"); case ExceptionArgument.str: return("str"); case ExceptionArgument.options: return("options"); case ExceptionArgument.prefix: return("prefix"); case ExceptionArgument.suffix: return("suffix"); case ExceptionArgument.buffer: return("buffer"); case ExceptionArgument.offset: return("offset"); default: Debug.Fail("The enum value is not defined, please check the ExceptionArgument Enum."); return(""); } }
// Migrating InheritanceDemands requires this default ctor, so we can mark it SafeCritical protected WeakReference() { Debug.Fail("WeakReference's protected default ctor should never be used!"); throw new NotImplementedException(); }
// Special coersion rules for primitives, enums and pointer. private static Exception ConvertOrWidenPrimitivesEnumsAndPointersIfPossible(object srcObject, EETypePtr srcEEType, EETypePtr dstEEType, CheckArgumentSemantics semantics, out object?dstObject) { if (semantics == CheckArgumentSemantics.SetFieldDirect && (srcEEType.IsEnum || dstEEType.IsEnum)) { dstObject = null; return(CreateChangeTypeException(srcEEType, dstEEType, semantics)); } if (dstEEType.IsPointer) { Exception exception = ConvertPointerIfPossible(srcObject, srcEEType, dstEEType, semantics, out IntPtr dstIntPtr); if (exception != null) { dstObject = null; return(exception); } dstObject = dstIntPtr; return(null); } if (!(srcEEType.IsPrimitive && dstEEType.IsPrimitive)) { dstObject = null; return(CreateChangeTypeException(srcEEType, dstEEType, semantics)); } CorElementType dstCorElementType = dstEEType.CorElementType; if (!srcEEType.CorElementTypeInfo.CanWidenTo(dstCorElementType)) { dstObject = null; return(CreateChangeTypeArgumentException(srcEEType, dstEEType)); } switch (dstCorElementType) { case CorElementType.ELEMENT_TYPE_BOOLEAN: bool boolValue = Convert.ToBoolean(srcObject); dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, boolValue ? 1 : 0) : boolValue; break; case CorElementType.ELEMENT_TYPE_CHAR: char charValue = Convert.ToChar(srcObject); dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, charValue) : charValue; break; case CorElementType.ELEMENT_TYPE_I1: sbyte sbyteValue = Convert.ToSByte(srcObject); dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, sbyteValue) : sbyteValue; break; case CorElementType.ELEMENT_TYPE_I2: short shortValue = Convert.ToInt16(srcObject); dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, shortValue) : shortValue; break; case CorElementType.ELEMENT_TYPE_I4: int intValue = Convert.ToInt32(srcObject); dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, intValue) : intValue; break; case CorElementType.ELEMENT_TYPE_I8: long longValue = Convert.ToInt64(srcObject); dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, longValue) : longValue; break; case CorElementType.ELEMENT_TYPE_U1: byte byteValue = Convert.ToByte(srcObject); dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, byteValue) : byteValue; break; case CorElementType.ELEMENT_TYPE_U2: ushort ushortValue = Convert.ToUInt16(srcObject); dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, ushortValue) : ushortValue; break; case CorElementType.ELEMENT_TYPE_U4: uint uintValue = Convert.ToUInt32(srcObject); dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, uintValue) : uintValue; break; case CorElementType.ELEMENT_TYPE_U8: ulong ulongValue = Convert.ToUInt64(srcObject); dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, (long)ulongValue) : ulongValue; break; case CorElementType.ELEMENT_TYPE_R4: if (srcEEType.CorElementType == CorElementType.ELEMENT_TYPE_CHAR) { dstObject = (float)(char)srcObject; } else { dstObject = Convert.ToSingle(srcObject); } break; case CorElementType.ELEMENT_TYPE_R8: if (srcEEType.CorElementType == CorElementType.ELEMENT_TYPE_CHAR) { dstObject = (double)(char)srcObject; } else { dstObject = Convert.ToDouble(srcObject); } break; default: Debug.Fail("Unexpected CorElementType: " + dstCorElementType + ": Not a valid widening target."); dstObject = null; return(CreateChangeTypeException(srcEEType, dstEEType, semantics)); } Debug.Assert(dstObject.GetEETypePtr() == dstEEType); return(null); }
public static void DoEvilThings() { Debug.Fail("Evil thing happened!"); }
// Returns the biggest power of ten that is less than or equal to the given number. static void BiggestPowerTenLessThanOrEqualTo(uint number, int bits, out uint power, out int exponent) { switch (bits) { case 32: case 31: case 30: { if (Ten9 <= number) { power = Ten9; exponent = 9; break; } goto case 29; } case 29: case 28: case 27: { if (Ten8 <= number) { power = Ten8; exponent = 8; break; } goto case 26; } case 26: case 25: case 24: { if (Ten7 <= number) { power = Ten7; exponent = 7; break; } goto case 23; } case 23: case 22: case 21: case 20: { if (Ten6 <= number) { power = Ten6; exponent = 6; break; } goto case 19; } case 19: case 18: case 17: { if (Ten5 <= number) { power = Ten5; exponent = 5; break; } goto case 16; } case 16: case 15: case 14: { if (Ten4 <= number) { power = Ten4; exponent = 4; break; } goto case 13; } case 13: case 12: case 11: case 10: { if (1000 <= number) { power = 1000; exponent = 3; break; } goto case 9; } case 9: case 8: case 7: { if (100 <= number) { power = 100; exponent = 2; break; } goto case 6; } case 6: case 5: case 4: { if (10 <= number) { power = 10; exponent = 1; break; } goto case 3; } case 3: case 2: case 1: { if (1 <= number) { power = 1; exponent = 0; break; } goto case 0; } case 0: { power = 0; exponent = -1; break; } default: { power = 0; exponent = 0; Debug.Fail("unreachable"); break; } } }
public override double Sample() { Debug.Fail("Not used or called for this implementation."); throw new NotSupportedException(); }