133 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.Microsoft.Data.SqlClient (1)
src\Vendoring\OpenTelemetry.Instrumentation.SqlClient\Shared\Guard.cs (1)
177throw new InvalidCastException($"Cannot cast '{paramName}' from '{value?.GetType().ToString() ?? "null"}' to '{typeof(T)}'");
Aspire.Microsoft.EntityFrameworkCore.SqlServer (1)
src\Vendoring\OpenTelemetry.Instrumentation.SqlClient\Shared\Guard.cs (1)
177throw new InvalidCastException($"Cannot cast '{paramName}' from '{value?.GetType().ToString() ?? "null"}' to '{typeof(T)}'");
Aspire.StackExchange.Redis (1)
src\Vendoring\OpenTelemetry.Instrumentation.StackExchangeRedis\Shared\Guard.cs (1)
185throw 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.DataProtection (1)
TypeExtensions.cs (1)
26throw new InvalidCastException(Resources.FormatTypeExtensions_BadCast(
Microsoft.AspNetCore.Mvc.ViewFeatures.Test (2)
Rendering\HtmlHelperValidationSummaryTest.cs (2)
673modelState.AddModelError("Property3", new InvalidCastException("Exception will be ignored."), metadata); 692modelState.AddModelError("Property3", new InvalidCastException("An ignored Exception."), metadata);
Microsoft.CodeAnalysis.EditorFeatures.Wpf (2)
Lightup\ISmartRenameSessionFactoryWrapper.cs (1)
43throw new InvalidCastException($"Cannot cast '{instance.GetType().FullName}' to '{WrappedTypeName}'");
Lightup\ISmartRenameSessionWrapper.cs (1)
115throw new InvalidCastException($"Cannot cast '{instance.GetType().FullName}' to '{WrappedTypeName}'");
Microsoft.Data.Analysis (1)
DataFrame.cs (1)
390throw new InvalidCastException(String.Format(Strings.BadColumnCastDuringGrouping, columnName, column.DataType, typeof(TKey)));
Microsoft.DotNet.Git.IssueManager (3)
Helpers\RepositoryHelper.cs (3)
39throw new InvalidCastException($"'{parsedUri}' is not a valid URI"); 73throw new InvalidCastException($"'{parsedUri}' is not a valid URI"); 101throw new InvalidCastException($"'{parsedUri}' is not a valid URI");
Microsoft.Maui.Controls (2)
Compatibility\Handlers\TabbedPage\iOS\TabbedRenderer.cs (1)
461 throw new InvalidCastException($"{nameof(renderer)} must be a {nameof(Page)} renderer.");
DependencyResolver.cs (1)
35 throw new InvalidCastException("Resolved instance is not of the correct type.");
Microsoft.Maui.Controls.Compatibility (1)
iOS\Renderers\TabbedRenderer.cs (1)
470 throw new InvalidCastException($"{nameof(renderer)} must be a {nameof(Page)} renderer.");
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)
Microsoft.VisualStudio.LanguageServices.DevKit (2)
Logging\VSCodeTelemetryLogger.cs (2)
97throw new InvalidCastException($"Unexpected value for scope: {scope}"); 195_ => throw new InvalidCastException($"Unexpected value for scope: {scope}")
PresentationFramework (2)
MS\Internal\Controls\ConnectionPointCookie.cs (2)
50ex = new InvalidCastException(SR.Format(SR.AxNoSinkImplementation, eventInterface.Name)); 66ex = 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.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\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\libraries\System.Private.CoreLib\src\System\Byte.cs (1)
249throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Byte", "DateTime"));
src\libraries\System.Private.CoreLib\src\System\Char.cs (5)
519throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "Boolean")); 569throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "Single")); 574throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "Double")); 579throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "Decimal")); 584throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "DateTime"));
src\libraries\System.Private.CoreLib\src\System\Convert.cs (8)
138throw new InvalidCastException(SR.InvalidCast_IConvertible); 162TypeCode.DBNull => throw new InvalidCastException(SR.InvalidCast_DBNull), 163TypeCode.Empty => throw new InvalidCastException(SR.InvalidCast_Empty), 215throw new InvalidCastException(SR.InvalidCast_DBNull); 217throw new InvalidCastException(SR.InvalidCast_Empty); 219throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, value.GetType().FullName, targetType.FullName)); 237throw new InvalidCastException(SR.InvalidCast_CannotCastNullToValueType); 248throw new InvalidCastException(SR.InvalidCast_IConvertible);
src\libraries\System.Private.CoreLib\src\System\DateTime.cs (1)
1973private static InvalidCastException InvalidCast(string to) => new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, nameof(DateTime), to));
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\libraries\System.Private.CoreLib\src\System\Decimal.cs (2)
1041throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Decimal", "Char")); 1101throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Decimal", "DateTime"));
src\libraries\System.Private.CoreLib\src\System\Double.cs (2)
459throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Double", "Char")); 519throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Double", "DateTime"));
src\libraries\System.Private.CoreLib\src\System\Enum.cs (1)
2190DateTime IConvertible.ToDateTime(IFormatProvider? provider) => throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Enum", "DateTime"));
src\libraries\System.Private.CoreLib\src\System\Int16.cs (1)
252throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int16", "DateTime"));
src\libraries\System.Private.CoreLib\src\System\Int32.cs (1)
267throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int32", "DateTime"));
src\libraries\System.Private.CoreLib\src\System\Int64.cs (1)
264throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int64", "DateTime"));
src\libraries\System.Private.CoreLib\src\System\SByte.cs (1)
255throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "SByte", "DateTime"));
src\libraries\System.Private.CoreLib\src\System\Single.cs (2)
454throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Single", "Char")); 514throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Single", "DateTime"));
src\libraries\System.Private.CoreLib\src\System\UInt16.cs (1)
246throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt16", "DateTime"));
src\libraries\System.Private.CoreLib\src\System\UInt32.cs (1)
262throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt32", "DateTime"));
src\libraries\System.Private.CoreLib\src\System\UInt64.cs (1)
261throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt64", "DateTime"));
src\System\Array.CoreCLR.cs (3)
274throw new InvalidCastException(SR.InvalidCast_DownCastArrayElement); 555throw new InvalidCastException(SR.InvalidCast_StoreArrayElement); 591throw new InvalidCastException(SR.InvalidCast_StoreArrayElement);
src\System\Runtime\InteropServices\DynamicInterfaceCastableHelpers.cs (2)
20throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, castable.GetType(), interfaceType)); 30throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, castable.GetType(), interfaceType));
System.Private.Windows.Core (1)
System\Value.cs (1)
81throw 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)
1326return new InvalidCastException(SR.Format(SR.XmlInvalidNullCast, type.FullName)); 1328return new InvalidCastException(SR.Format(SR.XmlInvalidCast, value.GetType().FullName, type.FullName)); 1330return 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)
81throw 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));