w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
If strings are nullable by default, why do i get Unable to cast object of type 'System.DBNull' to type 'System.String'.?
Because null != DBNull.Value. But you can check if it the value in the DataReader is null with the IsDbNull method: DestributionGroup = dr.IsDbNull("Destribution Group") ? "" : dr.GetString("Destribution Group");

Categories : C#

Unable to cast object of type 'System.Int16' to type 'System.String'
This t.Field<string>("db_code").ToString() perhaps should be this: t.Field<short>("db_code").ToString() or equivalent t.Field<Int16>("db_code").ToString()

Categories : C#

Unable to cast object of type 'System.String[]' to type 'System.IConvertible'
Try this, weight is an array. Assuming you want to convert first element of array. string[] weight = txtProductOptn1.Text.Split(','); var Weight1 = Convert.ToInt32(weight[0]);

Categories : C#

Unable to cast object of type 'System.Linq.OrderedEnumerable`2[***]' to type 'System.Collections.Generic.IEnumerable`1[***]'
You're trying to convert a collection of DirectoryToken to a collection of Token. This is called a covariant conversion, and it's only supported in .Net 4.0 or later. If you can't upgrade, you can call .Cast<Token>() to create a new IEnumerable<T> instance (actually an iterator) that casts each object to the desired type. Under no circumstances do you need an explicit cast operation.

Categories : C#

Unable to cast object of type 'System.Data.SqlClient.SqlDataReader' to type 'System.IConvertible'
It's exactly what the error says. You can't convert an SqlDataReader to a DateTime. If you want to query for just a single value, you should use: cmd2.ExecuteScalar(); If you are looking to retrieve a single value, I would suggest using TOP 1 in your query as well: SELECT TOP 1 DISTINCT loanUpdateDate Also note that ExecuteScalar() can return DbNull.Value if no value is found, so be sure to do a null check before trying to convert the value to anything.

Categories : C#

Unable to cast object of type 'System.Int32' to type 'System.Data.DataRowView'
Try to Direct Cast the value : (DirectCast(LbmCat.SelectedItem, DataRowView)("ID").ToString()) See it here. It may help

Categories : Vb.Net

Unable to cast object of type to type 'System.Data.Objects.ObjectContext
Try the link for MSDN Article below solved my problem when I was going through the same tutorial. MSDN Article! Just change SchoolContext to SchoolEntities in the method SchoolContextEntityDataSource_ContextCreating() Best regards, Adit Malik

Categories : Entity Framework

Unable to cast object of type VB$AnonymousDelegate to type System.Func
"Function() to a Func" is not an implicit conversion precisely, but the normal assignation which Func expects (that is, a Function). You are not including the As Func(Of T, Boolean) bit in BoolFunc, what makes this function "anonymous" (you are not saying explicitly the returned type). Include this bit and it should work without any problem. That is, replace your BoolFunc with this one: Public Function BoolFunc(Of T)(ByVal bfunc As Func(Of Boolean, Boolean, Boolean), ByVal f1 As Func(Of T, Boolean), ByVal f2 As Func(Of T, Boolean)) As Func(Of T, Boolean) If f1 Is Nothing Then Return f2 If f2 Is Nothing Then Return f1 Return Function(param As T) bfunc(f1(param), f2(param)) End Function

Categories : Vb.Net

Unable to cast object of type 'System.Web.Security.SqlRoleProvider' to type 'WebMatrix.WebData.SimpleRoleProvider'
That's because SqlRoleProvider does not inherit SimpleRoleProvider. However, you can try using SimpleRoleProvider Constructor (RoleProvider): var roles = new SimpleRoleProvider(Roles.Provider);

Categories : Sql Server

Using weka in C#: Unable to cast object of type 'java.util.ArrayList' to type 'System.Collections.Generic.List`
I am answering my own question. I used this link to solve the problem I was facing. Thanks @SecretSquirrel(see the comments) and @Jon Iles (see the answer I've linked).

Categories : C#

C#.NET Error: Unable to cast object of type 'System.Data.DataTable' to type 'System.Data.DataSet'
It's because you're setting the DataSource to a DataTable: gvPartNumber.DataSource = dsgvPartNumber.Tables["partNumbers"]; not a DataSet. So, instead of this: DataSet dsgvPartNumberDelete = (DataSet)gvPartNumber.DataSource; do this: DataTable dsgvPartNumberDelete = (DataTable)gvPartNumber.DataSource; and then in the following lines you won't need accessors like .Tables[0]. It will already be a DataTable and thus more direct to access anyway. This modification would of course have to be replicated to all of your methods where you're trying to cast the DataSource as a DataSet.

Categories : C#

System.InvalidCastException: Unable to cast object of type
_Bots.Values is a collection of virtualBot and your code should be foreach (virtualBot roomBot in _Bots.Values) { if (roomBot.goalX == -1) continue;

Categories : C#

How to cast a string value to some specific type when we have only Class object of the type?
According to what you describe, if you have: String var = "variable"; Class<?> type = Class.forName("your_class");// Your type Object o = type.cast(var); Now 3 things can happen: o should be of your_class type If var is null, o will be null or ClassCastException will be thrown

Categories : Java

Unable to cast object of type WhereSelectListIterator 2 System.Collections.Generic.List
As the error is trying to tell you, LINQ methods return special iterator types the implement IEnumerable<T>; they do not return List<T>. This enables deferred execution. Since the object isn't actually a List<T>, you can't cast it to a type that it isn't. If you need a List<T>, you can either call ToList(), or skip LINQ entirely and use List<T>.ConvertAll(), which is like Select(), but does return List<T>.

Categories : Linq

What is causing the "Unable to cast object of type 'System.Data.Entity.DynamicProxies" error
I'm not entirely clear what's going on in this section of code, are you meant to be retrieving the Resource from the second context you mentioned in your comment? var entry = ex.Entries.Single(); var databaseValues = (Rack)entry.GetDatabaseValues().ToObject(); var clientValues = (Rack)entry.Entity; var entry2 = ex.Entries.Single(); var databaseValues2 = (Resource)entry2.GetDatabaseValues().ToObject(); var clientValues2 = (Resource)entry2.Entity; If you called Single() on a sequence that contained more than one element, you would generate an exception; since Single isn't generating an exception, you only have one entry present which you're using in both cases. In the first you want to treat it as a Rack, which doesn't seem to generate a complaint. In the second, you're treating

Categories : Asp Net

asp.net json web service sending array error Cannot convert object of type 'System.String' to type 'System.Collections.Generic.List`1[System.String]'
You need to make your data parameter of the $.ajax call like this: JSON.stringify({'a': variables}) The JSON variable is not available in < IE8 so you'll want to include a JSON implementation like the one mentioned in the answer here Also, you had an extra } in the success function. So, in the future, if you want to add extra parameters to your data object passed to the web service, you'd construct it like so: var someArr = ['el1', 'el2']; JSON.stringify({ 'param1': 1, 'param2': 'two' 'param3': someArr // etc }); JavaScript: var variables = Array(); var i = 0; $('#Div_AdSubmition').find('.selectBox').each(function () { variables[i] = $(this).find('.selected').find(".text").html(); i++; }); $.ajax({ type: 'post', data: JSON.stringify({'a': variables}),

Categories : C#

Cannot convert object of type 'System.String' to type 'PropertySearch'
It looks like you are trying to deserialize with invalid json. A good place to check your json format is JsonLint.com. You will want your json object to look more like this: { "UserId": 1, "SessionId": 1, "PriceMin": 1, "PriceMax": 1, "BedsMin": 1 } The issue you are having is you are passing a comma delimited string. The deserializer does not know which values to map to which fields.

Categories : Dotnet

Unable to cast object of type 'WhereSelectListIterator` in LINQ
bw will be a sequence of BackgroundWorker items - so you can't cast from that sequence to a single item. There are a number of methods which will give you a single item, e.g. First FirstOrDefault Single SingleOrDefault Last LastOrDefault You should work out whether you should use one of those, or actually iterate over all the results of the query.

Categories : Dotnet

"Object of type 'System.object[]' cannot be converted to type 'system.string'"
Using your code, I wrote an example. This is error free and I hope it helps you! static void Main(string[] args) { Dictionary<string, Object> dic = new Dictionary<string, Object>(); dic.Add("tester1", new object()); dic.Add("tester2", new object()); dic.Add("tester3", new object()); dic.Add("tester4", new object()); dic.Add("tester5", new object()); dic.Add("tester6", new object()); Console.WriteLine("Starting loop..."); foreach (KeyValuePair<string, Object> kvp in dic) { var x = kvp.Key; var y = kvp.Value; Console.WriteLine(String.Format("Key: {1}, Value: {2}{0}", Environment.NewLine, x, y)); } Console.WriteLine("Finished Loop

Categories : C#

Unable to cast object of type error during IIS Deploy -> Import Application
Had the same problem (used Web Deploy 2.0) I changed to Web Deploy 3.5 and it's working now (I uninstalled Web Deploy 2.0 via Control Panel before and used the Web Platform Installer in IIS to install the newer version on server 2012 -simply search for web deploy there)

Categories : Iis

Nhibernate throws Object of type 'System.Linq.EnumerableQuery`1[Entity]' cannot be converted to type 'System.Linq.IQueryable`1[System.Object[]]'
.AsQueryable() will wrap the given IQueryable from NH needlessly into a new Queryable but since NH will by default use object arrays as results and transform it later it will fail casting. Also Selecting the user into another User will prevent changetracking and is needless copying. repo.GetAll().Where(f => f.Id == id).FirstOrDefault(); should be enough or even better because of the sessioncache usage var user = session.Get<User>(id); if (user == null) // user with given Id does not exist

Categories : C#

Linq to Entities - "Unable to create a constant value of type 'System.Object'..."
I think it is the following line that causes the problems: Line = (p.ProdLine.Factory.Factory_No + '/' + p.ProdLine.ProdLine_No.ToString()) This is since it combines a query-result with a .NET method result. Maybe this will work. It delays the creation the of Line-variable-contents until after the query has been run. var query = (from p in Productions join t in MaterialTransactions on p.Prodn_ID equals t.Prodn_ID where p.WO_ID == 2345 orderby p.Date descending select new { Id = p.Prodn_ID, Date = p.Date, Line1 = p.ProdLine.Factory.Factory_No, Line2 = p.ProdLine.ProdLine_No, Qty = p.Qty, Wgt = (double)p.ActWgt, Speed = (double)p.ActSpeed, MaterialUsed = t.Material.Name }) .AsEnumerable() // This is where the db-stuff stops, and the in-memory stuff b

Categories : C#

How to cast to an object to a type when type is known during runtime?
Unfortunately, it's not just that its the "same class in a different namespace"... basically, you have 2 classes. They are completely different classes, because of the auto generated code. As far as the .Net Runtime is concerned, they might as well be as different as "int" and "string". They probably even hail from different assemblies. I've had a similar issue as well - and at this point, probably the easiest thing you can do is make your own generic converter method that will read the public properties from the one type, and populate them on the another type. This can be done because you PROMISE that the two classes look identical :)

Categories : C#

Object of type 'System.Reflection.MdFieldInfo' cannot be converted to type 'MyEnum'
I think you need a Field.GetValue here type.GetProperty("St").SetValue(student, type3.GetField("Good").GetValue(instance), null); Type.GetField returns FieldInfo but what you actually need to pass as a parameter is enum value. Note: I assume Good is a field on type3 which is of type Enum StudentType

Categories : C#

No mapping exists from object type System.Net.Sockets.SocketException to a known managed provider native type
I got the answer to this problem. It was actually occurring due to improper datatype conversion at the SQL Server end. By mistake i was passing ex.innerException into a field of datatype nvarchar. This is why the exception was occurring. Hence the final point here is: if you try to pass some parameter from any language to SQL server, you must make sure that the datatypes are matching or interoprable with each other.

Categories : C#

Could not determine JSON object type for type System.Char
If you are getting multiple randoms in sequence may need to change your code to generate better randoms but this will work for creating a JArray var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var random = new Random ( ); var result = JArray.FromObject ( Enumerable.Repeat ( chars , 1 ) .Select ( s => s [ random.Next ( s.Length ) ] ) .ToArray ( ) );

Categories : C#

The ViewData item that has the key 'category' is of type 'System.String' but must be of type 'IEnumerable'
In post, if ModelState is invalid, you return view. But you fill categories select list only in get request, you should do that in post too [HttpPost] public ActionResult Create(Contact contact) { try { if (ModelState.IsValid) { db.Contacts.Add(contact); db.SaveChanges(); return RedirectToAction("Index"); } } catch (DataException) { //Log the error (add a variable name after DataException) ModelState.AddModelError("", "Unable to save changes, Try again."); } IEnumerable<SelectListItem> items = db.Catagorys .Select(c => new SelectListItem { Text = c.CatagoryName }); return View(contact); } And of course, it will be great if you create CreateContac

Categories : Asp Net Mvc

typeof() when Cannot implicitly convert type 'System.Type' to 'string'
According to the documentation, the DataType property is used to specify an XSD data type, not a .NET type: An XML Schema data type, as defined by the World Wide Web Consortium (www.w3.org) document named "XML Schema Part 2: Datatypes". Try this instead: public class EPubBody { [XmlElement(ElementName = "Image")] public EPubImage[] BodyItems; }

Categories : C#

Unable to resolve type:System.Data.Spatial.DbGeography with sql server geography data type returned in odata
For Geo types we use GeoJSON. You can do the following: Let's suppose you have an EntitySet with the following structure: point: id: int, point: $data.GeographyPoint when you retrieve your points use map (projection): context.points.map(function(p) { return { id: id, point: { lat: Latitude, lng: Longitude } }, {}, "default") please let us know if it works for you or not

Categories : Misc

Java Pass instance type of Object to generic class type parameter
No.. generic type should be known at compile time. Generics are there to catch possible runtime exceptions at compile time itself. List<Integer> list = new ArrayList<Integer>(); //..some code String s = list.get(0); // this generates compilation error because compiler knows that list is meant to store only Integer objects and assigning the value got from list to String is definitely an error. If the generic type was determined at run-time this would have been difficult.

Categories : Java

How to declare an inter-type method with return type of every object's class?
Try this: aspect MyAspect { public S MyInterface<S>.getMyself() { return (S) this; } } interface MyInterface<T extends MyInterface<T>> { } class MyClassOne implements MyInterface<MyClassOne> {} class MyClassTwo implements MyInterface<MyClassTwo> {} class Main { public static void main(String[] args) { MyClassOne aClassOne = new MyClassOne().getMyself(); MyClassTwo aClassTwo = new MyClassTwo().getMyself(); MyClassOne errorClassOne = new MyClassTwo().getMyself(); // compile error MyClassTwo errorClassTwo = new MyClassOne().getMyself(); // compile error } } Fun with generics! Answer is straight forward, I think, but let me know if this is confusing for you.

Categories : Java

JSON Schema: represent constraint to encode object type in string type
I agree, either you choose the object or string type. I have looked into the JSON Schema documentation and I could not find anything to express the constraint as clear as needed. Hence, a short discussions of the two approaches there are to my mind. Type String JSON Schema defines seven primitive types, including object. A string is simply defined as a JSON string. The RFC 4627 defines a JSON string as follows A string is a sequence of zero or more Unicode characters This would apply to your case, even though the content of the string has to be restricted. The question is how to communicate the restriction. I would use a description to reference to another subschema. You can even define a pattern for the string an encode the subschema as regular expression. This, however,

Categories : Javascript

Deserializ XML string into c# object for my Class type EmailAccount
It might be easier to load your XML file into a XMLDocument in C# and then convert it into a list of XML nodes by using SelectNodes method. That way you can access every node individually and take the data you need. You can load your file with this code: Document = new XmlDocument(); try { openFileDialog1.ShowDialog(); Document.Load(openFileDialog1.FileName); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } ListOfNodes = Document.SelectNodes("ReceiveAccountSettings"); Where ListOfNodes is XmlNodeList type variable After you load your document, you can access any node like any other member of list, and access it's attributes, child nodes etc.

Categories : C#

Get Type of object and then cast it?
taken from msdn: Pointer types do not inherit from object and no conversions exist between pointer types and object. Also, boxing and unboxing do not support pointers. However, you can convert between different pointer types and between pointer types and integral types. link:http://msdn.microsoft.com/en-us/library/y31yhkeb(v=vs.100).aspx int number = 200; unsafe { // Convert to byte: byte* p = (byte*)&number; }

Categories : C#

cast dynamic object in other type .net
When the compiler generates code for expression organization.Name it detects the type of the variable organization as being dynamic. Then it decides to postpone the 'binding' process for execution time, because it does not know it the object behind the variable organization will have a Name or ModifiedOn properties. The methods TryGetMember and TrySetMember will be called during execution time whenever the dynamic object won't have the corresponding member. In this example TryGetMember and TrySetMember wont be called for property Name, because it is statically declared on eObject, but they will be called for the rest of member access you defined. When you cast the variable to eObject in newOrg, the compiler is back to static analisis, so it can see that newOrg references an object with

Categories : Dotnet

Cast an object into a generic type
Well my crystal ball is in for service. So my guess of what you are trying to is either : Dynamically access a a property. Dynamically call a generic method Dynamically call instantiate an object 1) dynamic dObj = bla; dObj.Prop 2) Dynamic generic method // example looks close to yout issue, (checking removed for brevity) // call method GetRespository<poco> dynamically on any object that implements ILuw // the result passed back is also dynamic. For obvious reasons. public static dynamic GetDynamicRepository(ILuw iLuw, string pocoFullName) { //null checks removed for demo.... var pocoType = Type.GetType(pocoFullName); MethodInfo method = typeof(ILuw).GetMethod("GetRepository"); MethodInfo generic = method.MakeGenericMethod(poco

Categories : C#

Cast generic type T into Class
You could do this: public class Parent<T> { private final Class<T> clazz; public Parent(Class<T> clazz) { this.clazz = clazz; } public Class<T> getType() { return clazz; } } public class Foo<T> extends Parent { public Foo(Class<T> clazz) { super(clazz); } }

Categories : Java

How can an object (as in var of type object) be cast using Reflection? (OFX specific)
It would be a lot simpler if you used the relevant interface. In this case, you can use the IEnumerable interface. IEnumerable keys = parameter.GetType().GetProperty("Keyframes") .GetValue(parameter, null) as IEnumerable; You have to then deal with the type of the enumerated objects, but the enumerable itself is easier to deal with. IEnumerable is in the System.Collections namespace, not System.Collections.Generic.

Categories : C#

Cast an object to a derived type in Python
The usual way to do this is to write a class method for B that takes an A object and creates a new B object using the information from it. class B(A): @classmethod def from_A(cls, A_obj): value = A.value other_value = A.other_value return B(value, other_value) a_thing = B.from_A(a_thing)

Categories : Python

Cannot implicitly convert type 'double' to 'System.Windows.HorizontalAlignment'. An explicit conversion exists (are you missing a cast?)
The HorizontalAlignment property expects an HorizontalAlignment enum. myBarCode.HorizontalAlignment = HorizontalAlignment.Left;

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.