OrderBy Nullable Properties In A Generic List Throwing InvalidCastException?
Jun 13, 2012
I need to return an a generic list in the correct order for my project, and I'm getting InvalidCastException errors. Here is the code:
Dim lDt As List(Of Comment) = RemapCommentsForE1(so.CommentList). _
OrderBy(Function(x) x.CreateDate.Value). _
ThenBy(Function(x) x.Sequence). _
[code].....
View 2 Replies
ADVERTISEMENT
Jun 7, 2012
I have a grid view with a lot of columns, all need to be sorted on. I have seen a few snippets out there, but I cannot get any of them to work with my example. Here is what I have so far.
Protected Sub gvSearch_OnSorting(ByVal sender As Object, _
ByVal e As GridViewSortEventArgs)
If Not Session("sort") Is Nothing Then
[code].....
View 1 Replies
Dec 7, 2011
We have a web solution with mixed C# and VB.NET (3.5) projects (note: several vb.net files do have Option Strict Off). Our code runs as modules inside DotNetNuke 4.8. Under certain conditions, our application will crash at the method:[code]If I look at the Formatters.Binary part of MSDN I'd guess the ObjectWriter is internal for Binary (as suggested in the comments, red)?How can .NET even at all fail at casting a Int64 to String? Rephrased: what value for a Int64 could potentially not be converted to a String? However, as pointed out in comments: Int64 can easily be converted to Strings, but Casting them is a different issue.The Serialize method doesn't announce this ArgumentException or InvalidCastException may occur (in the Exceptions section).I tried investigating XYZ and types for properties in that class in ildasm to see any irregularities but couldn't find any.
View 2 Replies
Mar 3, 2011
I have the following VB.NET function, for example:
Public Function MyFunction (Of TData) (ByVal InParam As Integer) As TData
End Sub
How do I, in a function, determine if TData is a NULLable Type?
View 3 Replies
Dec 14, 2006
I have the following VB.NET function, for example:Public Function MyFunction (Of TData) (ByVal InParam As Integer) As TDataEnd Sub
View 5 Replies
Jun 19, 2009
I have 3 similar functions, that only change based on numeric type:
<Extension()> _
Public Function ToNullableShort(ByVal str As String) As Short?
Dim intReturn As Short
[Code].....
I was trying to make a generic function out of this, but couldn't do it. How can I make a generic function that will take a specific T and make it a Nullable(of T)?
View 2 Replies
Jun 6, 2011
Scroll to the bottom, EDIT 19 onwards. See @Chris's comments also for good examples
[code]...
It's all gone quiet since Edit 19ish and @Chris reinforcing the issue with a good example (thank you Chris). I'll make the question a little easier (and attempt to tidy up all of the above), can anyone prove this is not an MS bug or similar? It seems to be something under the hood is not correctly wired up for VB.Net with regards to Nullable Structures and Events? However, all other cases using the Nullable Structures does appear to work?
View 3 Replies
Jan 17, 2010
It seems like overkill to set the value of a nullable type and implement iNotifyPropertyChanged. Is there a better way of doing this?
[Code]...
View 2 Replies
Jun 30, 2011
I am trying to create a list of a generic type in vb.net 2.0 framework.
This is the generic type definition:
Public Class GenericParamMap(Of T)
Public Sub New(ByVal pParamName As String, ByVal pPropValue As T)
mParamName = pParamName
[Code]....
The compiler does not allow a "T" in the method's parameter because it's not defined, but I'm not sure how or where to define it. I thought it was okay to have a generic method definition.
View 2 Replies
Dec 14, 2011
I have a generic Class I'm using to hold information loaded from a database.I have a method which takes a DataRow as an argument, uses the object's known column name and extracts the data from the DataRow, such that:Dim loadData As T = CType(myDataRow("myColumnName"), T))works as my default assignment in most cases.Unfortunately, due to some horrifying design constraints, some of my columns may be null, and may also be taken from enumerations.This means that when <T> is Nullable(Of SomeEnumeration) the above code does not work because I can't cast 0 directly to SomeEnumeration.Zero.Is there some way to check whether <T> is Nullable(Of [Enum])? Or some way to write a method which allows Integers to be cast to Nullable(Of [Enum])?I feel like I'm forgetting something that would allow me to write one of the other of these, but my weak google-fu is turning up nothing.
EDIT: Okay, thanks to dasblinkenlight's answer below, I can detect when this circumstance is occurring, but what I need to do now is to take a type <T> which I know is Nullable(Of SomeClass), get a type reference to SomeClass and then create a new object of type Nullable(Of SomeClass) and assign that to LoadData.My problem was that I had a lot of difficulty in finding any function which would accept baseType as an actual Type.Parse accepted baseType as a parameter, I knew baseType was an [Enum] type because of dasblinkenlight's code, so I was, in this instance, able to code a solution. It's a solution which is very specific to my problem (i.e., T is Nullable(of SomeEnumeration)), but it's a solution nonetheless.
View 2 Replies
Oct 2, 2009
Im working on my first n-tier application. I am trying to serialize a structure and Im getting an error"Soap Serializer does not support serializing Generic Types : System.Nullable`1[System.DateTime]."Here is the structure that is being serialized
Namespace Structures
<Serializable()> _
Public Structure structAllergy
Public AllergyID As String
Public ProfileID As String
[code]....
The bold line is the line that is throwing the error.
View 1 Replies
Jan 29, 2010
In a program I am writing (in VB.NET, 2008), I have 2 classes, "Receipt" and "Group", each with similar properties, both implementing a custom interface entitled "IIDUser". In my program, I have a number of lists of "Receipt" and "Group", declared like:Friend receipts as List(Of Receipt)
I have written a few functions that apply equally to managing both lists of receipts and groups, declared like this one:Friend Function getNextAvailableUserLabel(ByRef theList As IList(Of IIDUser), ByVal startLabel As Short) As Short
Then called like this:getNextAvailableUserLabel(receipts, s)
I did all this in an attempt for interface-based polymorphism, as I thought writing 2 identical functions (except for that one would be for lists of receipts while the other for lists of groups) would be bad practice (and waste time). However, I get an "InvalidCastException" during runtime. It is explained, "Unable to cast object of type 'System.Collections.Generic.List`1[Receipt_Sorter_v2.Receipt]' to
[Code]...
View 4 Replies
Jan 17, 2012
In the below sample code, I have tried to use Nullable(of T) for DateTime and I want to use it same of the Dimensions property which is List(of Dimension).
CODE:
View 1 Replies
Apr 8, 2009
I have a class which extends HashSet(Of T).I am trying to evaluate some custom properties of this HashSet during execution and make decisions based on those values.
During debugging, I am pausing execution and adding a Watch on my instance of this HashSet.
The Watch only provides me with a view of the Count of the HashSet and the objects contained by the HashSet.How can I get the Watch to show me the other properties of the HashSet?
View 1 Replies
Oct 1, 2009
I'm looping all the properties in an object via reflection:
For Each p As PropertyInfo In values.[GetType]().GetProperties()
If p.CanRead Then
'Do stuff
End If
Next
how to determine whether the property in question is a generic List(Of T)? If it is I need to loop the list itself.
I've experimented with GetType and TypeOf but have not managed to get anything working.
To clarify, I want to keep this generic. I do not want to specify the type of T, I need to loop the list items and call the ToString method on each item. T could be one of a number of different types (application specific reference types). Is it possible to do this without specifying types?
(VB.NET 2005 with .Net 2.0)
View 3 Replies
Mar 23, 2011
Public Class notifierMain
Public Class Contacts
Inherits List(Of row)
Public Sub New()
[code]....
When I debug this winforms application I get curType = "notifier.notifierMain+Contacts+row" I want to the Validate function to know it is in MyContacts. How do I do this?
View 3 Replies
May 3, 2012
i have issue returning a list in a web method. here is the code
<WebMethod()> _
Public Function getTags(para_parents As String) As List(Of getTypeDetailsByParentName_Result)()
Dim context As New PPEntities
[code]....
the error is
Value of type 'System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)' cannot be converted to '1-dimensional array of System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)'
View 1 Replies
Apr 7, 2011
it seems always at this time I cant figure out how to do something maybe it has something to do with lunchtime.
Im having trouble using a method that is defined by an outside company
This is a link to their integration guide:
[URL]
This is their documentation for the class Im trying to use
OrderQueryWebService Class
This class is for SID in particular and is made for use with the notification methods. This is for the Order Query Web Service specifically, allowing clients to return the status of transactions for their merchant, whenever they want to.
Methods
/ <summary>
/ Pass through the variables required and receive a list of Transaction
objects showing transaction status
[Code].....
The MerchantCode, the MerchantUsername, the MerchantPassword are all good the List is a custom type called SetComHash.Transaction
Everytime I try adding a string to the list such as the transactionNumber and some other values it gives me a type error:
"Value of type string cannot be converted to 'SetcomHash.Transaction'
View 13 Replies
Jul 29, 2011
Currently my code has the following properties:
[Code]...
View 3 Replies
Sep 14, 2011
I'm wondering if it's possible in VB.NET to make similar properties call one generic one?A sentence doesn't explain it well so here's a code example.I have a bit field defined like this:
<Flags()> _
Enum E_Operation As Integer
Upload = 1
[code]....
View 1 Replies
May 23, 2010
Number of downloads: 81This program is supposed to calculate the ever popular mortgage payment and amortize the loan in a list box. I keep throwing this error "Missing Member Exception" and can not find out how to fix it anywhere. Because of the error I can't even see if I can even get a calculation in the text box, let alone if the amortization will run. The purple text is where the exception is.
Public Class HarlessSmithIA3
Dim LoanAmt, Int, Result, Term As Double
Dim txtIntRate As New Object
Dim txtLoanAmount As New Object
Dim txtLoanTerm As New Object
Dim txtMonthlyPayment As New Object
[CODE]...
View 10 Replies
Oct 29, 2010
What would be the fastest way to sort a list that contains a list of objects, based upon another list? An example follows:Say I have multiple lists of employees. Each individual list has a common property value, say "Department". So I have a list of employees, in one list they all have the department string value of "Sales". In another list all the objects have a department value of "Finance". These lists of employees are then contained in a list which holds them all.
I have a second list, which should drives the sort order of the employee lists. The second list simply contains a list of strings like, "Finance", "Sales", "IT" and so on. I'd like my lists of customers to be sorted in the order of "Finance", "Sales", etc.I'm using VB.NET in .NET 2.0
View 1 Replies
Jan 5, 2011
Dim x = GetType(List(Of )) 'valid statement
Dim list As New List(Of String)
Now I want to see if list is a List(Of T) variable: Dim isList = TypeOf list Is List(Of ) On the last line I get a compile error: "Type Expected". Is there any cheap-performance TypeOf operator alternative for generics?
View 2 Replies
Mar 12, 2009
I have converted c# .cs to vb:= I have 6 errors on:
Red "List" says Too few type arguments to system.Collections.Generic.List(Of T)'
Orange "Calendar" says Value of type 'System.Windows.Forms.Control.ControlCollection' cannot be converted to 'Form1.Kobush.Windows.Forms.Appointment'.
[code]....
View 6 Replies
Nov 25, 2009
What I've done is create a User Control Library (Project) and I've added a single User Control to that project. The control contains a single FlowLayoutPanel, and I created a Property on the control itself to pass the FlowDirection from the Control to its FlowLayoutPanel child.
Build, reference, component appears in the Toolbox and everything works fine, but the property on the control does not appear in the Properties window when I go to edit it at design time.
View 6 Replies
Oct 13, 2011
i m getting a collection of data in list's object. And from this list i want to get the maximum id.`
Dim objinfo As List(Of AlbumInfo) = objPhotos.GetPhotos_Alb_ID(Me.ModuleId, hdd_AlbID.Value)
Dim Photo_Image As String = ""
Dim str As String = Photo_Image & fu_Photo.PostedFile.FileName.Substrng(fu_Photo.PostedFile.FileName.LastIndexOf("."))
[code]....
this returns the "0"th positions id from Convert.ToString(objinfo.Item("0").Photo_Id + 1)but i want to get the last item's id.
View 17 Replies
Jan 5, 2011
i have list of string like this :
Dim totalPrice As New List(Of Integer)
how can i get sum of column(0) (C# or VB) ?
View 4 Replies
Jan 17, 2011
<div class=PhorumReadBodyText>Hi, I have a problem with adding of items to generic list, problem is when I insert 1. item to the list, everithing is ok, but if I insert second item, first and second has same values.
code looks like that (asp.net 4.0): </div> <div class=PhorumReadBodyText> </div> <div class=PhorumReadBodyText>Partial Class _Default
Inherits System.Web.UI.Page
[Code]...
View 1 Replies
Jan 17, 2011
I have a problem with adding items to generic list, problem is when I add 1. item to the list, everything is ok, but when I add second, first and second has the same values...
This is code (asp.net 4.0):
Partial Class _Default
Inherits System.Web.UI.Page
<Serializable()>
Public Class Product
Shared Property Material As String
[URL]
View 7 Replies
Aug 26, 2009
In my VB.net application I am populating my customer object and looping through it as shown below.As there are thousands of customers, I want to do it 500 customers at a time.Is there anyway I can have one more For loop to process 500 customers at one shot in vB.netI am not using LinQ as the database is Oracle.[code]
View 2 Replies