C# - Nullable(of Guid) With Generic Delegate Causes Weird (hidden) Error?

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


ADVERTISEMENT

Reflection - .NET: Checking If Variable Is Of Guid (nullable) Type?

Jan 16, 2012

I'm trying to check if a variable has been defined as a nullable Guid. eg.

Dim myGuid As Nullable(Of Guid) or Dim myGuid As Guid?

It seems doing a myGuid.GetType returns the underlying type, that is type Guid, not Guid?. So testing myGuid.GetType Is GetType(Guid?) always returns False.How do I find out if myGuid is a nullable type?

Ed: I can do the following, which correctly returns True for "Guid?" and False for "Guid":

Not Nullable.GetUnderlyingType(GetType(Guid?)) Is Nothing

The problem is that I don't know how to retrieve the nullable type from the variable itself, in order to test it. I've only been able to get the underlying (non-nullable) system type.

I've written a db helper function. I pass it an object comprised of public members, representing the row data of a table. The members are the table columns.Using reflection, I loop through these public members to create an INSERT statement for a command object and populate its parameters with the values in those members. So far so good.But now there's a table which has a uniqueidentifier column which I must not populate from the row object, as it defaults to "NEWID()" (using SQL Server 2008). Instead of skipping all Guid columns, which would be easy, I only want to skip ones defined in the row data class as "Guid" (non-nullable).Basically, I'm using the Guid? (Nullable) type to indicate it's ok to populate that uniqueidentifier column with data. If it's non-nullable, that tells me to skip it because the column has a NEWID() default value.

View 3 Replies

Error - Soap Serializer Does Not Support Serializing Generic Types : System.Nullable`1[System.DateTime]

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

Get A Error" Method 'Private Shared Sub Ping Does Not Have A Signature Compatible With Delegate 'Delegate Sub ?

Jun 1, 2010

Code:
Public Class SendPings
Shared Sub New()
AddHandler Post.Saved, AddressOf Post_Saved[code].....

I get a error" Method 'Private Shared Sub Ping(item As BlogEngine.Core.IPublishable, itemUrl As System.Uri)' does not have a signature compatible with delegate 'Delegate Sub WaitCallback(state As Object)'.

View 4 Replies

.net - Determine If A Generic Parameter Is A Nullable Type?

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

Determine If A Generic Param Is A Nullable Type?

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

.net - Creating A Generic Method For Converting String To Nullable Numbers

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

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

.net - Performance Implications Of Implementing A Generic Type And A Delegate In A Function?

Aug 4, 2010

I wrote a serializer (to Byte Array) for dictionaries that have a string key, but an object of some sort as its value.I've never implemented a generic type in a function or used a delegate before, so I'm a bit concerned about this being significantly slower than writing a serialization function for a specific type of Dictionary (Dictionary(Of String, MyClass) for example)Should this code be significantly slower due to the use of the generic type or the delegate?

[code]...

It works, and I could loop it and compare it to a more static Dictionary serializer, but I'm more concerned about when I start using this for a lot of different String/Object dictionary combinations, and it'll take me a long time to write a bunch of static dictionary serializers (that's what I'm hoping to avoid in the first place)edit: simplified intro text

View 1 Replies

Search A Generic List - Keep Getting:Delegate To An Instance Method Cannot Have Null 'this'?

Feb 16, 2009

I'm trying to search a generic list of 'User' business objects which has a property called 'Username': If (From u In colUsers Select u.Username Where Username.Equals(strUsername)).Count > 0 ThenI keep getting:Delegate to an instance method cannot have null 'this'.

View 16 Replies

IDE :: IDE Giving Weird Build Error

Oct 26, 2006

I just finished putting the first 6 datagrid controls on my form and i went to go test it and got this build error: Error 4 Value of type 'String' cannot be converted to 'System. Windows.Forms.DataGridViewTextBoxColumn'.C:SoftwareForm1.vb 1425 19..When the line generating the error is this Me.Name = "Form1".where it has the "Form1" portion underlined in blue.This is a weird error because that line was made by the IDE to say the name of the form and has nothing to do with 'System.Windows.Forms.DataGridViewTextBoxColumn'.I tried saving my progress and restarting the IDE with no luck..Now I cannot even access the form in designer mode,One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.The designer cannot process the code at line 1424: Me.Name = "Form1" The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified.

View 5 Replies

VS 2008 Weird Error With A ToolStripMenuItem?

Jul 5, 2011

I had a lengthy subroutine with handler routines, like this, before:

Private Sub CompMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
ToolStripMenuItem3.Click, ToolStripMenuItem4.Click, ToolStripMenuItem5.Click,

[code].....

View 3 Replies

GUID In Registry - Get The Program To Preform This Task On Another Computer As Their GUID Will Be Different?

Feb 26, 2012

im workin on a task that will get the current computers Default Gatway, So i chose the easiest option, using the Registry, in most cases i find this with no problem at all, here's the code im using right now,

Public sHost As String = My.Computer.Registry.GetValue _
("HKEY_LOCAL_MACHINESYSTEMControlSet001servicesTcpipParametersInterfaces THE GUID NEEDED HERE ", "DhcpServer", Nothing)

Which works fine, if i put My GUID in where i've stated in above code, I get the right value ect..., no what i was woundering is how would i get the program to preform this task on another Computer as their GUID will be diffrent, if their away i can do this with simplicity?

View 3 Replies

VS 2010 Weird Error Even Teacher Can't Figure Out?

Apr 23, 2012

i made a program in which you put in a number like 10, and there are 10 cards. If you put in a number like 23, here is a possible output -

Card #1 - 3
Card #2 - 20
the rest 0

etc, where all the cards values adds up to the number you submit (the values displayed will be random)

The thing is, when i do a number below 10,000, it will come up as one card equaling that number and the rest equaling zero. If i do it a number 10,000 or larger, it will split it like it is supposed to.

[Code]...

interestingly, if you put in a break point, it works like it is supposed to!

What is going on? And why does it matter the size of the number for it to matter?

When i get home i'll edit this with screenshots.

View 13 Replies

Weird Error Shockwave Flash And AxMedia Player

Sep 19, 2009

When i was making my program, i went to import Shockwave Flash Object and AxMedia Player, But they were not there. I know a way of restoring them, Dll's but, however i cannot find the DLL in the folder. Can someone either give me the location in an example "/vbexpress/*****" Or can someone give me a download link to the DLL so i can do that, aswell? I think the download link would be the best.

View 8 Replies

Checking For Duplicate In Listbox Item Turns Out Weird Error

Apr 21, 2011

I'm trying to add a string to a listbox if there is none exact string existed inside, but it turns out a very weird error. Look at this.
On form_load, I have this:
AddHandler Server1.OnUserLoggedIn, AddressOf HandleUser

And then,
Public Sub HandleUser(ByVal username As String)
'Here, you handle adding the text to a text box.
Me.Invoke(New PrintMessageDelegate(AddressOf AddUser), username)
End Sub
[Code] .....

The output is when I connect the first client, it works fine. But, when I try to connect the second client, it prints out three times both the listbox1 item and the txtDisplay. It's like get caught in loop, but I have tried other kind of loops like for each and other string comparison too, still work that way.

View 4 Replies

Weird Error Every Time Open My Project In Visual Studio

Feb 25, 2011

I have a VB application that uses databases and writes information onto an Excel-file. I have the Excel-file in my Project folder(Visual Studio 2008ProjectsProjectXProjectXExcel objektitListy.xls)Every time I open up my project I get the following error:[code]The thing is, I don't know why the error starts up in the first place. Why is the VS 'unable to open the module file' even though it exists in that folder and can be opened normally?Also, why does the error disappear when the file is opened manually from the containing folder?

View 5 Replies

Cast Value Type To Nullable Enumeration Type In Generic Object If All Types Are Unknown At Write-time?

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

Invoke An Instance Function Delegate On An Instance Of A Generic Type?

Aug 4, 2010

D is a dictionary whose entry values are of Type T..What I'm attempting to do is have a delegate like "Serializer" below that I can invoke on an instance of T, such as "Entry.Value" below.Please see the "return Entry..." line below for my wishful thinking.[code]

View 2 Replies

To Extract The GUID With ObjectFromLresult Error Occurred

Aug 30, 2011

API Declarations

<DllImport("oleacc.dll")> _
Shared Function ObjectFromLresult (ByVal lResult As IntPtr, <MarshalAs(UnmanagedType.LPStruct)> ByVal refiid As Guid, ByVal wParam As IntPtr) As <MarshalAs(UnmanagedType.Interface)> Object
End Function

[CODE]...............

When I go to extract the GUID with ObjectFromLresultAccessviolationException not occurred at the Management 'attempt to read or write protected memory. This usually means that other memory is corrupt. What does the way in here to deal with ObjectFromLresult the API to be successful extraction GUID.

View 4 Replies

Unexpected Syntax Error When Creating New Guid Array

Oct 22, 2009

The following syntax is just fine ReadOnly

[Code]...

View 3 Replies

VS 2010 To Extract The GUID With ObjectFromLresult Error Occurred?

Aug 30, 2011

API Declarations

<DllImport("oleacc.dll")> _
Shared Function ObjectFromLresult (ByVal lResult As IntPtr, <MarshalAs(UnmanagedType.LPStruct)> ByVal refiid As Guid, ByVal wParam As IntPtr) As

[code].....

View 4 Replies

Multicast Delegate: Represents A Multicast Delegate; That Is, A Delegate That Can Have More Than One Element In Its Invocation List?

Jan 30, 2010

from the documentation we have this: Multicast Delegate: Represents a multicast delegate; that is, a delegate that can have more than one element in its invocation list.

so am i right to say that Multicast delegate is no different from a normal delegate other than the fact that it has arguments. so System.Action is a 'normal' delegate whereas System.Action(T)(Byval obj as T) is a multicast delegate?

View 5 Replies

Build Error - Property Keycode Is Non Nullable

Jul 4, 2005

I tried to build my project but it has 1 build error
:Property 'Keycode' is non-nullable.
I double click it but it points nowhere. I'm really desperate. My project consists of Crystal Report. It had just been upgraded from version 8.5 to version 11. Is it possible that this is the source of error?

View 5 Replies

Error In Assigning Object Of Nullable Type?

Jul 9, 2010

I have a structure that contains another structure. The inner structure is nullable. Now wht I do is something like the following. I create a new instance of the inner structure, set the member variables and assign the whole structure to the inner structure of the parent. But it is giving an error. The assignment is not successful. If I try to peek into the structure in the watch window, it says "property evaluation failed" for the HasValue and Value properties.

Dim testData As List(Of TestData) = Nothing
Dim testData_List1 As New TestData
With testData_List1.commonTestParam

[Code].....

View 1 Replies

Error Querying When Nullable Types In Where Clause

Mar 1, 2012

I have the following NHibernate Linq query:
From eachLine In myNhSession(Of SamplePoco)()
Where eachLine.SampleIntField = 1234
The property SamplePoco.SampleIntField is type Nullable(Of Int32)

When I run the query, I get the following exception:
System.InvalidCastException: Unable to cast object of type 'NHibernate.Hql.Ast.HqlCoalesce' to type 'NHibernate.Hql.Ast.HqlBooleanExpression'
If I change the property type to Int32, it works. It seems that Nullable types are automatically converted into a coalesce expression by the Linq compiler.

Debugging the NHibernate, I just found out that this Where clause was converted into: {where ((eachLine.SampleIntField == 1234) ?? False)}. As I can understand, the whole condition comparison was translated to be coalesced instead of just the Nullable property.
If I put this way eachLine.SampleIntField.Equals(1234) it doesn't work as well ('Equals not implemented' exception)

If I change the query to the following code, it works:
From eachLine In myNhSession(Of SamplePoco)()
Where {1234}.Contains(eachLine.SampleIntField)

Another code that works as well (coalescing the field properly as I was expecting by the first query):
From eachLine In myNhSession(Of SamplePoco)()
Where If(eachLine.SampleIntField,0) = 1234

View 1 Replies

Extension On Nullable(Of T) Object, Gives Type Error?

Oct 29, 2010

The code I want to work:

<Extension()>
Public Function NValue(Of T)(ByVal value As Nullable(Of T), ByVal DefaultValue As T) As T
Return If(value.HasValue, value.Value, DefaultValue)

[code].....

View 2 Replies

Delegate - BeginInvoke - EndInvoke - Clean Up Multiple Async Threat Calls To The Same Delegate?

Feb 9, 2010

I've created a Delegate that I intend to call Async.

[Code]...

View 2 Replies

VS 2005 Unknown Error In Delegate?

Sep 23, 2010

I have a program which use an API. One of the functions of this API has threading.Once I start this function. It will continue reading data and once the data is found, it will pass me the data to a function let's say functionnd I call a delegate functionB from this functionA.And at some point this functionB throw me an error of "Collection was modified; enumeration operation might not execute.".Does anyone know what this mean?I google it and found that this error was caused by "For Each or For" loop.But in my program I don't have any for loop.

VB.Net
Public Sub ReadTag(ByVal sender As Object, ByVal e As TagReadDataEventArgs)
Try

[code].....

View 2 Replies

VS 2008 Webservice Compilation Error Re:System.Nullable(Of Decimal)

Jun 1, 2009

Quote:Value of type System.Nullable(Of Decimal) cannot be converted to System I have the code below which seems to work fine on my development server but causes a compilation error when I put it on my live webserver (uncommented).The error message I get from the event viewer in IIS is as above.

' <WebMethod(Description:="Insert into Referral Payments Table.")> _
'Public Function InsertReferralPayment(ByVal ReffererCustID As Integer, ByVal InstalledCustID As Integer, ByVal AmountReferrer As Nullable(Of Decimal), ByVal AmountInstalled As Nullable(Of Decimal), ByVal ReferrerChequeSentDate As Nullable(Of Date), ByVal InstalledChequeSentDate As Nullable(Of Date), ByVal ReferrerChequeNo As Integer, ByVal InstalledChequeNo As Integer, ByVal InputBy As String) As Integer

[code]....

From what I can tell IIS is configured the same and both referenced DataTables seem identical.

View 7 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved