137 references to InvalidCastException
Aspire.Confluent.Kafka (1)
src\Vendoring\OpenTelemetry.Instrumentation.ConfluentKafka\Shared\Guard.cs (1)
179throw new InvalidCastException($"Cannot cast '{paramName}' from '{value?.GetType().ToString() ?? "null"}' to '{typeof(T)}'");
Aspire.Dashboard.Tests (2)
Telemetry\DashboardTelemetrySenderTests.cs (1)
99throw new InvalidCastException($"Unexpected path: {request.RequestUri}");
Telemetry\DashboardTelemetryServiceTests.cs (1)
140throw new InvalidCastException($"Unexpected path: {request.RequestUri}");
Aspire.Hosting.Kubernetes (1)
Resources\Int32OrStringV1.cs (1)
70value.Number ?? throw new InvalidCastException("The specified value is not an Int32.");
Aspire.Hosting.RemoteHost (5)
Ats\AtsMarshaller.cs (5)
760throw new InvalidCastException($"Value cannot be converted to {targetType.Name}."); 764throw new InvalidCastException($"Value cannot be converted to {targetType.Name}."); 793throw new InvalidCastException($"Value cannot be converted to {targetType.Name}."); 799throw new InvalidCastException($"Value cannot be converted to {targetType.Name}."); 806throw new InvalidCastException($"Value cannot be converted to {targetType.Name}.");
Aspire.Hosting.RemoteHost.Tests (1)
CapabilityDispatcherTests.cs (1)
144throw new InvalidCastException("Cannot cast to expected type");
Aspire.StackExchange.Redis (1)
src\Vendoring\OpenTelemetry.Instrumentation.StackExchangeRedis\Shared\Guard.cs (1)
209? throw new InvalidCastException($"Cannot cast '{paramName}' from '{value?.GetType().ToString() ?? "null"}' to '{typeof(T)}'")
dotnet-svcutil-lib (19)
FrameworkFork\Microsoft.Xml\Xml\BinaryXml\XmlBinaryReader.cs (7)
1120throw new InvalidCastException(string.Format(ResXml.XmlBinary_CastNotSupported, _token, "Boolean")); 1210throw new InvalidCastException(string.Format(ResXml.XmlBinary_CastNotSupported, _token, "DateTime")); 1305throw new InvalidCastException(string.Format(ResXml.XmlBinary_CastNotSupported, _token, "Double")); 1400throw new InvalidCastException(string.Format(ResXml.XmlBinary_CastNotSupported, _token, "Float")); 1495throw new InvalidCastException(string.Format(ResXml.XmlBinary_CastNotSupported, _token, "Decimal")); 1590throw new InvalidCastException(string.Format(ResXml.XmlBinary_CastNotSupported, _token, "Int32")); 1685throw new InvalidCastException(string.Format(ResXml.XmlBinary_CastNotSupported, _token, "Int64"));
FrameworkFork\Microsoft.Xml\Xml\schema\XmlValueConverter.cs (9)
564return new InvalidCastException(string.Format(ResXml.XmlConvert_TypeBadMapping, XmlTypeName, sourceType.Name)); 566return new InvalidCastException(string.Format(ResXml.XmlConvert_TypeBadMapping2, XmlTypeName, sourceType.Name, destinationType.Name)); 724throw new InvalidCastException(string.Format(ResXml.XmlConvert_TypeNoNamespace, value, prefix)); 729throw new InvalidCastException(string.Format(ResXml.XmlConvert_TypeNoNamespace, value, prefix)); 855throw new InvalidCastException(string.Format(ResXml.XmlConvert_TypeNoPrefix, qname.ToString(), qname.Namespace)); 2913throw new InvalidCastException(string.Format(ResXml.XmlConvert_TypeToString, XmlTypeName, sourceType.Name)); 2916throw new InvalidCastException(string.Format(ResXml.XmlConvert_TypeFromString, XmlTypeName, destinationType.Name)); 3660return new InvalidCastException(string.Format(ResXml.XmlConvert_TypeListBadMapping, XmlTypeName, sourceType.Name)); 3662return new InvalidCastException(string.Format(ResXml.XmlConvert_TypeListBadMapping2, XmlTypeName, sourceType.Name, destinationType.Name));
FrameworkFork\Microsoft.Xml\Xml\Serialization\XmlSerializationReader.cs (3)
1414return new InvalidCastException(string.Format(ResXml.XmlInvalidNullCast, type.FullName)); 1416return new InvalidCastException(string.Format(ResXml.XmlInvalidCast, value.GetType().FullName, type.FullName)); 1418return new InvalidCastException(string.Format(ResXml.XmlInvalidCastWithId, value.GetType().FullName, type.FullName, id));
Microsoft.AspNetCore.Components.Forms (1)
FieldIdentifier.cs (1)
290throw new InvalidCastException($"Unable to cast object of type '{value.GetType()}' to type '{expression.Type}'.");
Microsoft.AspNetCore.DataProtection (1)
TypeExtensions.cs (1)
26throw new InvalidCastException(Resources.FormatTypeExtensions_BadCast(
Microsoft.Data.Analysis (1)
DataFrame.cs (1)
390throw new InvalidCastException(String.Format(Strings.BadColumnCastDuringGrouping, columnName, column.DataType, typeof(TKey)));
Microsoft.Extensions.VectorData.Abstractions (2)
ProviderServices\Filter\FilterTranslatorBase.cs (1)
225throw new InvalidCastException($"Property '{propertyModel.ModelName}' is being cast to type '{convert.Type.Name}', but its configured type is '{propertyModel.Type.Name}'.");
ProviderServices\PropertyModel.cs (1)
131throw new InvalidCastException($"Property '{ModelName}' has a value of type '{value.GetType().Name}', but its configured type is '{propertyType.Name}'.");
Microsoft.Maui.Controls (1)
DependencyResolver.cs (1)
35 throw new InvalidCastException("Resolved instance is not of the correct type.");
Microsoft.Private.Windows.Core (1)
System\Value.cs (1)
80throw new InvalidCastException($"{from?.Name ?? "<null>"} cannot be cast to {to.Name}");
Microsoft.TemplateEngine.Orchestrator.RunnableProjects (3)
Macros\BaseGeneratedSymbolMacro.cs (2)
21throw new InvalidCastException($"Couldn't cast the {nameof(rawConfig)} as {nameof(IGeneratedSymbolConfig)}."); 58throw new InvalidCastException($"Couldn't cast the {nameof(config)} as {typeof(T)}.");
Macros\BaseMacro.cs (1)
22throw new InvalidCastException($"Couldn't cast the {nameof(config)} as {typeof(T).Name}.");
Microsoft.VisualBasic.Core (5)
Microsoft\VisualBasic\CompilerServices\ExceptionUtils.vb (1)
245Return New InvalidCastException(Description)
Microsoft\VisualBasic\CompilerServices\NewLateBinding.vb (2)
1394Throw New InvalidCastException(errorMessage) 1470Throw New InvalidCastException(errorMessage)
Microsoft\VisualBasic\CompilerServices\Operators.Resolution.vb (1)
217Throw New InvalidCastException(errorMessage)
Microsoft\VisualBasic\CompilerServices\OverloadResolution.vb (1)
2575Return New InvalidCastException(message)
PresentationFramework (2)
MS\Internal\Controls\ConnectionPointCookie.cs (2)
49ex = new InvalidCastException(SR.Format(SR.AxNoSinkImplementation, eventInterface.Name)); 65ex = new InvalidCastException(SR.AxNoConnectionPointContainer);
System.ComponentModel.Annotations (3)
System\ComponentModel\DataAnnotations\LengthAttribute.cs (1)
67throw new InvalidCastException(SR.Format(SR.LengthAttribute_InvalidValueType, value.GetType()));
System\ComponentModel\DataAnnotations\MaxLengthAttribute.cs (1)
84throw new InvalidCastException(SR.Format(SR.LengthAttribute_InvalidValueType, value.GetType()));
System\ComponentModel\DataAnnotations\MinLengthAttribute.cs (1)
67throw new InvalidCastException(SR.Format(SR.LengthAttribute_InvalidValueType, value.GetType()));
System.Data.Common (1)
System\Data\DataSetUtil.cs (1)
35return new InvalidCastException(message);
System.Drawing.Common (1)
System\Drawing\Printing\TriState.cs (1)
41value.IsDefault ? throw new InvalidCastException(SR.TriStateCompareError) : value == True;
System.Linq.Expressions (2)
System\Linq\Expressions\Error.cs (2)
96return new InvalidCastException(Strings.DynamicObjectResultNotAssignable(p0, p1, p2, p3)); 103return new InvalidCastException(Strings.DynamicBinderResultNotAssignable(p0, p1, p2));
System.Private.CoreLib (50)
src\runtime\src\libraries\System.Private.CoreLib\src\System\Array.cs (1)
563throw new InvalidCastException(SR.InvalidCast_DownCastArrayElement);
src\runtime\src\libraries\System.Private.CoreLib\src\System\Boolean.cs (2)
333throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Boolean", "Char")); 393throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Boolean", "DateTime"));
src\runtime\src\libraries\System.Private.CoreLib\src\System\Byte.cs (1)
243throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Byte", "DateTime"));
src\runtime\src\libraries\System.Private.CoreLib\src\System\Char.cs (5)
586throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "Boolean")); 636throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "Single")); 641throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "Double")); 646throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "Decimal")); 651throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "DateTime"));
src\runtime\src\libraries\System.Private.CoreLib\src\System\Convert.cs (8)
137throw new InvalidCastException(SR.InvalidCast_IConvertible); 161TypeCode.DBNull => throw new InvalidCastException(SR.InvalidCast_DBNull), 162TypeCode.Empty => throw new InvalidCastException(SR.InvalidCast_Empty), 214throw new InvalidCastException(SR.InvalidCast_DBNull); 216throw new InvalidCastException(SR.InvalidCast_Empty); 218throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, value.GetType().FullName, targetType.FullName)); 236throw new InvalidCastException(SR.InvalidCast_CannotCastNullToValueType); 247throw new InvalidCastException(SR.InvalidCast_IConvertible);
src\runtime\src\libraries\System.Private.CoreLib\src\System\DateTime.cs (1)
1964private static InvalidCastException InvalidCast(string to) => new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, nameof(DateTime), to));
src\runtime\src\libraries\System.Private.CoreLib\src\System\DBNull.cs (14)
44throw new InvalidCastException(SR.InvalidCast_FromDBNull); 49throw new InvalidCastException(SR.InvalidCast_FromDBNull); 54throw new InvalidCastException(SR.InvalidCast_FromDBNull); 59throw new InvalidCastException(SR.InvalidCast_FromDBNull); 64throw new InvalidCastException(SR.InvalidCast_FromDBNull); 69throw new InvalidCastException(SR.InvalidCast_FromDBNull); 74throw new InvalidCastException(SR.InvalidCast_FromDBNull); 79throw new InvalidCastException(SR.InvalidCast_FromDBNull); 84throw new InvalidCastException(SR.InvalidCast_FromDBNull); 89throw new InvalidCastException(SR.InvalidCast_FromDBNull); 94throw new InvalidCastException(SR.InvalidCast_FromDBNull); 99throw new InvalidCastException(SR.InvalidCast_FromDBNull); 104throw new InvalidCastException(SR.InvalidCast_FromDBNull); 109throw new InvalidCastException(SR.InvalidCast_FromDBNull);
src\runtime\src\libraries\System.Private.CoreLib\src\System\Decimal.cs (2)
1036throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Decimal", "Char")); 1096throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Decimal", "DateTime"));
src\runtime\src\libraries\System.Private.CoreLib\src\System\Double.cs (2)
457throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Double", "Char")); 517throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Double", "DateTime"));
src\runtime\src\libraries\System.Private.CoreLib\src\System\Enum.cs (1)
2191DateTime IConvertible.ToDateTime(IFormatProvider? provider) => throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Enum", "DateTime"));
src\runtime\src\libraries\System.Private.CoreLib\src\System\Int16.cs (1)
246throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int16", "DateTime"));
src\runtime\src\libraries\System.Private.CoreLib\src\System\Int32.cs (1)
261throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int32", "DateTime"));
src\runtime\src\libraries\System.Private.CoreLib\src\System\Int64.cs (1)
258throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int64", "DateTime"));
src\runtime\src\libraries\System.Private.CoreLib\src\System\SByte.cs (1)
249throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "SByte", "DateTime"));
src\runtime\src\libraries\System.Private.CoreLib\src\System\Single.cs (2)
450throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Single", "Char")); 510throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Single", "DateTime"));
src\runtime\src\libraries\System.Private.CoreLib\src\System\UInt16.cs (1)
240throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt16", "DateTime"));
src\runtime\src\libraries\System.Private.CoreLib\src\System\UInt32.cs (1)
256throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt32", "DateTime"));
src\runtime\src\libraries\System.Private.CoreLib\src\System\UInt64.cs (1)
255throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt64", "DateTime"));
System\Array.NativeAot.cs (2)
411throw new InvalidCastException(SR.Format(SR.Arg_ObjObjEx, value.GetType(), Type.GetTypeFromHandle(new RuntimeTypeHandle(pElementEEType)))); 430throw new InvalidCastException(SR.InvalidCast_StoreArrayElement);
System\InvokeUtils.cs (1)
439return new InvalidCastException(SR.InvalidCast_StoreArrayElement);
System\Runtime\InteropServices\IDynamicInterfaceCastable.cs (1)
62throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, instance.GetType(), Type.GetTypeFromMethodTable(interfaceType)));
System.Private.Windows.Core (1)
System\Value.cs (1)
80throw new InvalidCastException($"{from?.Name ?? "<null>"} cannot be cast to {to.Name}");
System.Private.Xml (19)
System\Xml\BinaryXml\XmlBinaryReader.cs (7)
1109throw new InvalidCastException(SR.Format(SR.XmlBinary_CastNotSupported, _token, "Boolean")); 1199throw new InvalidCastException(SR.Format(SR.XmlBinary_CastNotSupported, _token, "DateTime")); 1294throw new InvalidCastException(SR.Format(SR.XmlBinary_CastNotSupported, _token, "Double")); 1389throw new InvalidCastException(SR.Format(SR.XmlBinary_CastNotSupported, _token, "Float")); 1484throw new InvalidCastException(SR.Format(SR.XmlBinary_CastNotSupported, _token, "Decimal")); 1579throw new InvalidCastException(SR.Format(SR.XmlBinary_CastNotSupported, _token, "Int32")); 1674throw new InvalidCastException(SR.Format(SR.XmlBinary_CastNotSupported, _token, "Int64"));
System\Xml\Schema\XmlValueConverter.cs (9)
478return new InvalidCastException(SR.Format(SR.XmlConvert_TypeBadMapping, XmlTypeName, sourceType.Name)); 480return new InvalidCastException(SR.Format(SR.XmlConvert_TypeBadMapping2, XmlTypeName, sourceType.Name, destinationType.Name)); 639throw new InvalidCastException(SR.Format(SR.XmlConvert_TypeNoNamespace, value, prefix)); 644throw new InvalidCastException(SR.Format(SR.XmlConvert_TypeNoNamespace, value, prefix)); 770throw new InvalidCastException(SR.Format(SR.XmlConvert_TypeNoPrefix, qname, qname.Namespace)); 2493throw new InvalidCastException(SR.Format(SR.XmlConvert_TypeToString, XmlTypeName, sourceType.Name)); 2496throw new InvalidCastException(SR.Format(SR.XmlConvert_TypeFromString, XmlTypeName, destinationType.Name)); 3128return new InvalidCastException(SR.Format(SR.XmlConvert_TypeListBadMapping, XmlTypeName, sourceType.Name)); 3130return new InvalidCastException(SR.Format(SR.XmlConvert_TypeListBadMapping2, XmlTypeName, sourceType.Name, destinationType.Name));
System\Xml\Serialization\XmlSerializationReader.cs (3)
1361return new InvalidCastException(SR.Format(SR.XmlInvalidNullCast, type.FullName)); 1363return new InvalidCastException(SR.Format(SR.XmlInvalidCast, value.GetType().FullName, type.FullName)); 1365return new InvalidCastException(SR.Format(SR.XmlInvalidCastWithId, value.GetType().FullName, type.FullName, id));
System.Runtime.InteropServices (1)
System\Runtime\InteropServices\Marshalling\ComInterfaceMarshaller.cs (1)
82throw new InvalidCastException($"Unable to cast the provided managed object to a COM interface with ID '{TargetInterfaceIID.GetValueOrDefault():B}'");
System.Text.Json (1)
System\Text\Json\ThrowHelper.Serialization.cs (1)
58throw new InvalidCastException(SR.Format(SR.DeserializeUnableToAssignValue, typeOfValue, declaredType));
System.Text.RegularExpressions (1)
System\Text\RegularExpressions\Regex.Timeout.cs (1)
118throw new InvalidCastException(SR.Format(SR.IllegalDefaultRegexMatchTimeoutInAppDomain, DefaultMatchTimeout_ConfigKeyName, defaultTimeout));
System.Windows.Forms (10)
System\Windows\Forms\ActiveX\AxHost.ConnectionPointCookie.cs (2)
29throw new InvalidCastException(SR.AXNoConnectionPointContainer); 39throw new InvalidCastException(string.Format(SR.AXNoSinkImplementation, eventInterface.Name));
System\Windows\Forms\Controls\DataGridView\DataGridView.Methods.cs (1)
2653throw new InvalidCastException(SR.DataGridView_InvalidEditingControl);
System\Windows\Forms\Controls\DataGridView\DataGridViewButtonColumn.cs (1)
37throw new InvalidCastException(string.Format(SR.DataGridViewTypeColumn_WrongCellTemplateType, "System.Windows.Forms.DataGridViewButtonCell"));
System\Windows\Forms\Controls\DataGridView\DataGridViewCheckBoxColumn.cs (1)
38throw new InvalidCastException(string.Format(SR.DataGridViewTypeColumn_WrongCellTemplateType, "System.Windows.Forms.DataGridViewCheckBoxCell"));
System\Windows\Forms\Controls\DataGridView\DataGridViewComboBoxColumn.cs (1)
75throw new InvalidCastException(string.Format(SR.DataGridViewTypeColumn_WrongCellTemplateType, "System.Windows.Forms.DataGridViewComboBoxCell"));
System\Windows\Forms\Controls\DataGridView\DataGridViewImageColumn.cs (1)
45throw new InvalidCastException(string.Format(SR.DataGridViewTypeColumn_WrongCellTemplateType, "System.Windows.Forms.DataGridViewImageCell"));
System\Windows\Forms\Controls\DataGridView\DataGridViewLinkColumn.cs (1)
85throw new InvalidCastException(string.Format(SR.DataGridViewTypeColumn_WrongCellTemplateType, "System.Windows.Forms.DataGridViewLinkCell"));
System\Windows\Forms\Controls\DataGridView\DataGridViewTextBoxColumn.cs (1)
28throw new InvalidCastException(string.Format(SR.DataGridViewTypeColumn_WrongCellTemplateType, "System.Windows.Forms.DataGridViewTextBoxCell"));
System\Windows\Forms\Controls\PropertyGrid\PropertyGridInternal\PropertyGridView.DropDownHolder.cs (1)
350throw new InvalidCastException(string.Format(SR.PropertyGridViewEditorCreatedInvalidObject, createType));