.net - Implemented Interface Needs Casting?

Jan 12, 2011

I have an Entity class which Implements IWeightable:

Public Interface IWeightable
Property WeightState As WeightState
End Interface

I have a WeightCalculator class:

Public Class WeightsCalculator
Public Sub New(...)
..
End Sub

Why can I not do wc.Calculate(entities)? I receive:

Unable to cast object of type
'System.Collections.Generic.List1[mynameSpace.Entity]'
to type
'System.Collections.Generic.IList1[myNamespace.IWeightable]'.

If Entity implements IWeightable why is this not possible?

View 2 Replies


ADVERTISEMENT

Why Would Compiler Think An Interface Isn't Implemented When It Is

Apr 9, 2010

I've boxed in red. The class displayed here does implement INotifyPropertyChanged, but the VB compiler seems to think that the PropertyChanged event as declared does not match the signature of INotifyPropertyChanged.PropertyChanged.Here I've selected the offending line of code. Between this and the next screenshot I literally just cut and paste the exact same line back into the file (i.e., I hit Ctrl + X followed by Ctrl + V).I have this happen sometimes, particularly with the INotifyPropertyChanged interface in my experience but I have no idea if the problem is limited to that single interface (which would seem bizarre) or not.Let's say I have some code set up like this. There's an interface with a single event. A class implements that interface. It includes the event. [code] Every now and then, when I build my project, the compiler will suddenly start acting like the above code is broken. It will report that the Person class does not implement INotifyPropertyChanged because it doesn't have a PropertyChanged event; or it will say the PropertyChanged event can't implement INotifyPropertyChanged.PropertyChanged because their signatures don't match.This is weird enough as it is, but here's the weirdest part: if I just cut out the line starting with Event PropertyChanged and then paste it back in, the error goes away. The project builds.

View 2 Replies

Interface Be Implemented Across An Aggregate/composite Class In .net?

Mar 30, 2010

VB.NET .NET 3.5 I have an aggregate class called Package as part of a shipping system. Package contains another class, BoxType . BoxType contains information about the box used to ship the package, such as length, width, etc. of the Box.

Package has a method called GetShippingRates. This method calls a separate helper class, ShipRater, and passes the Package itself as an argument. ShipRater examines the Package as well as the BoxType, and returns a list of possible shipping rates/methods.

What I would like to do is construct an Interface, IRateable, that would be supplied to the helper class ShipRater. So instead of:

[Code]...

However, ShipRater requires information from both the Package and its aggregate, BoxType. If I write an interface IRateable, then how can I use the BoxType properties to implement part of the Interface?

View 2 Replies

Casting An Object Through An Interface (.NET 3.5)?

May 14, 2010

I have an object that inherits from an interface. I can create and return the following:

Dim o As IRequest
o = New Request
Return o

This works fine. Now I want to return a List(Of Requests), so I try the following:

Dim o As List(Of IRequest)
o = New List(Of Request)
Return o

The error below is being given on o = New List(Of Request)

System.Collections.Generic.List(Of MyObjects.Request)' cannot be converted to System.Collections.Generic.List(Of MyInterfaces.IRequest)'.Consider using 'System.Collections.Generic.IEnumerable(Of MyInterfaces.IRequest)'

View 2 Replies

INotifyPropertyChanged.PropertyChanged Implemented And Not Implemented; Visual Studio Build Error

Jan 2, 2012

I'm seeing a strange build bug a lot. Sometimes after typing some code we receive the following build error.

Class 'clsX' must implement 'Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs)' for interface System.ComponentModel.INotifyPropertyChanged'.

And

'PropertyChanged' cannot implement 'PropertyChanged' because there is no matching event on interface 'System.ComponentModel.INotifyPropertyChanged'.

Those error should never go together! Usually we can just ignore the exception and build the solution but often enough this bug stops our build. (this happens a lot using Edit and Continue which is annoying)Removing the PropertyChanged event and retyping the same code! sometimes fixes this.We're using a code generator that causes this error to surface but just editing some files manually triggers this exception too. This error occur's on multiple machines using various setups.

View 4 Replies

C# - How Is Hash Implemented In .NET

Aug 3, 2010

[Code]...

The garbage collector in .NET moves objects, so the object's address is not stable. How is Object's GetHashCode() method implemented?

View 1 Replies

How Can The UrlNormalizer Be Implemented

Nov 27, 2009

I found the line in a program that references UrlNormalizerUtil.UrlNormalizer to validate a url. It calls it from a GeneralPurposeUtilities file which is added to the project properties in references as a .dll file.

My question is: where does this file come from? Is is self coded or from some library? how else can the UrlNormalizer be implemented?

View 9 Replies

Have Implemented IEquatable Correctly?

Mar 18, 2012

I saw the question posed here: Have I implemented Equals()/GetHashCode() correctly? but my c# is not as strong, and I am unfimiliar with IEquatable enough that I would like to see this in VB.NET if possible please.My example code (The class will eventually use INotifyPropertyChanged when I get there):[code]

View 2 Replies

XML Embedded Expressions Implemented?

Sep 4, 2009

Can someone explain the nuts and bolts of what's really going on under the covers?

View 1 Replies

.show Method Or Operation Is Not Implemented?

Jul 18, 2012

I am programming an ordering site in VB.Net and ASP.Net.I start with the main ordering form and the idea is that the user will select a subject from the drop down list and then click a button to retrieve all modules associated with that subject in a second form (smaller than the main order form).I have created the second form (frm2) and added content to it.In the main form inside the method which represents the button being clicked, I have coded the following:

Dim frm As New frm2()
frm.show()

I then get an error that show has not been declared and so I create a method stub for it.I run the program and when I click on the button I get the following error:'method or operation is not implemented.'This points to the following line in the 2nd form:

Sub show()
Throw New NotImplementedException
End Sub

what I need to put inside this method to make my second form load when the button is clicked?

View 10 Replies

Private Set In Auto-Implemented Properties

Jun 11, 2009

I'm going to resolve this bug as "Postponed" as we won't have time to do it for VS2010, but I'm definitely interested in your feedback going forward.

View 6 Replies

VB10, Auto-Implemented Properties And COM?

Nov 30, 2010

I recently finished a class that we're using to tie Access to some WCF Services. Of course this means that the .Net classes (and all of their properties) need to be visible to COM. Given that I'm using VB10 and the Contact class has about 20 properties I went ahead and used auto-implementing properties.Much to my surprise, the properties were not accessible from within VBA in Access. I tried marking the properties as ComVisible (which I didn't have to do in the past with standard properties) and it still didn't work. After changing the auto properties to standard properties everything worked.

Became
Public Property FirstName As String
Get

[code].....

View 1 Replies

ReadOnly Property ListView In ListViewItem - How Is Implemented

Nov 30, 2009

how ListView pointer is stored/removed at ReadOnly Property ListView in ListViewItem? How is it implemented? I know ListViewItems are stored in ListViewItemCollection which has constructor New(owner as ListView) but I dont know how pointer to ListView is add/remove in ReadOnly Property in ListViewItem...

View 1 Replies

VS 2008 IPodServiceLib - Method Or Operation Is Not Implemented?

Jun 23, 2009

im messing around with this trying to get into my ipod touch the code i found here and there on the net doesnt quite work..Imports IpodServiceLib

Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

[Code]...

View 18 Replies

VS 2010 Comments On Strategy Pattern Implemented

May 18, 2012

a debate has been sparked here about the use of the strategy pattern in my classes.
Basically, I have a 'Shape' object that is an interface 'IShape'. We have 'Circle', 'Rectangle' and 'Elongated' that are the concrete classes that must implement the IShape interface.

[Code]...

View 3 Replies

VS 2010 Dll That Is Implemented By A Class With A Default Constructor

Dec 27, 2010

I have a base class which must be overriden. This base class sits in one dll shared by all. The derived classes will each be in their own dll such that the addition of a new derived class can be done by distributing a new dll. The set of dlls, and therefore the set of derived classes, will be discovered by the main program on startup. That's all pretty straightforward. The problem is that the main program needs to be able to query a database to figure out which type of derived class it needs, then create a class of that type. Naturally, it can't know which types will be available ahead of time because even I don't know that. The program has to be dynamically extensible.The obvious way to do this is to have an interface in the dll that is implemented by a class with a default constructor. The sole purpose of that class would be to return an object of the type (one of the derived types) defined in that dll. The derived types can't really be this class, because they can't have a default constructor since the base class doesn't have a default constructor, and the derived class can't make up the arguments that the base class constructor needs.

So basically, each dll that houses a derived class would also house a simple class that implemented an interface for the sole purpose of creating that particular derived class. The main program would examine the dll to find a class that implemented the interface, and once it found one, it could ask it what type of class it created, or it could ask it to create an instance of that class. It seems like there ought to be an easier way to dynamically add new classes to the project. It seems like the derived class ought to be able to tell the main project what type it was. This could be done, except that the derived class would have to exist before any of its methods could be called unless the methods were shared. Since you can't have a shared method in an interface, the interface itself would make no sense at that point, in which case I would need to discover whether the class in the dll derived from the base class in the second dll, just to figure out whether or not I wanted to create it. That's getting convoluted by now, so I guess I'll leave it there. The basic point is that the base class is known to the main program from a common dll. The number and types of derived classes can't be known at this time, so the program has to be able to discover them dynamically. Each derived class will sit in its own dll (or there could be more than one in a dll), and has to be discovered, and instances created, as needed, by the main program.

View 2 Replies

Why Is The VBCodeProvider.Parse Method In VS2005 Not Implemented

Mar 17, 2011

Why is the VBCodeProvider.Parse method in VS2005 not implemented? Is there an equivalent function?

View 2 Replies

.NET Auto-Implemented Properties - Compatibility Between VS2010 And VS2008?

Apr 29, 2011

I am working on an ASP.NET project where I use VB.NET within Visual Studio 2010. Some of the other developers on the project are using Visual Studio 2008. We all check our code into single SVN repository. I would like to start using Auto-Implemented Properties within VB.NET ...

Property FirstName as String
instead of ...
Private FirstName as String

[code].....

My concern is that this could mess up things for those using VS2008. What would happen if someone using VS2008 needed to modify my class that made use of Auto-Implemented Properties? I am assuming that since everything compiles down to IL code then there would be no issue in binary compatibility. Though a problem would arise when editing source.

View 1 Replies

Event Based Async Pattern - Correctly Implemented?

Oct 9, 2009

I've implemented the Event Based Async Pattern for the first time in a relatively complex class. I'm having some doubts about if I've done it as it should be done, and if there are no better approaches. One of the things that make me frown the most is how I'm currently handling all the cross thread events. This class contains a decent amount of events, about 20. What I've done is created a dictionary in which I have a list of callbacks, one for each event. The keys are a value of an enum containing all keys I created. In the underneath line, eventDelegates is the dictionary, and delegates is the enum.

[Code]....

View 1 Replies

IDE :: VS2010: Enable Or Disable Auto-Implemented Properties?

Nov 10, 2011

I have somehow managed to disable auto-implemented properties in my VS2010 IDE how to turn it back on. Almost every article on the internet loves to explain auto-implemented properties but doesnt give you the crucial option of how to turn it on or off.

View 2 Replies

Tabsize In A TextBox Or RichTextBox : Why Microsoft Have Not Implemented It As A PROPERTY

Jun 3, 2010

Tabsize in a TextBox or RichTextBox. Anyone know why Microsoft have not implemented it as a PROPERTY?

View 1 Replies

DoubleClick Event Not Firing When DragDrop Code Implemented (ListView)?

Aug 29, 2008

As the subject describes, once I implemented support for DragDrop - The DoubleClick event of the ListView control no longer fires.An overview of the code is as follows:

Private Sub ListView_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView.MouseMove

[code]......

View 4 Replies

.net - Why Can't Access The Backing Field On An Auto Implemented Property From Within An Inherited Class

Dec 20, 2011

I have a class that exposes an auto implemented property Enabled

[Code]...

But If I had not use an auto implemented property and declared my own backing-field as follows this is accessible from the subclass: Private _Enabled as Boolean ---- EDIT ----
The abve line is incorrect - this is not possible, it was in fact Protected in the original code which allowed access from the sub class See @JonSkeet answer ---- EDIT Of course I can just access Enabled from the sub class to work around this but can someone explain why this is the behaviour?

View 2 Replies

.net - Casting Interfaces And MEF?

Mar 13, 2009

I have the following problem with MEF: Interface definition to be used by host:

Public Interface IExecuteDoSomething
Inherits IAddinSettings
Event DataReceived As EventHandler(Of DataReceivedEventArgs)
Function DoSomething() As Boolean
End Interface

[Code]...

Everything seems to work fine until the Button2_Click routine is executed, then an InvalidCastException is thrown with the info:Unable to cast object of type 'System.Collections.Generic.List1[SharedLibrary.IExecuteDoSomething]' to type 'System.Collections.Generic.List1[SharedLibrary.IAddinSettings]'.

How can i solve this problem, because the imported object implements both of the interfaces?

View 1 Replies

.net - Difference Between Casting In C# And It

Dec 9, 2009

The next code works fine in C#:

[Code]...

But this code crash with a OverflowException in VB.Net.

[Code]...

Both codes seems the same to me. What is the difference and how can I get the C# code converted to VB.Net?

View 6 Replies

C Style Casting In VB?

Aug 19, 2011

I have a object type variable (control .Tag) that I need to cast to a structured type, and change a member in. This is a contrived but representative example

[code]...

View 2 Replies

Casting Error?

Oct 16, 2009

get around this. I have a data base field that is a decimal data type and I want to display it in a text box with the following txtWeekdayRate = CType(RoomsDataRow!WeekdayRate, TextBox)I get the following error when I run my program.Unable to cast object of type 'System.Decimal' to type 'System.Windows.Forms.TextBox'.

View 20 Replies

Casting Value Must Be Less Than Infinity?

Mar 1, 2009

I am getting the followin error from my code. System.InvalidCastException was unhandled Message="Unable to cast object of type 'QADBASE.DMRDataLists' to type 'QADBASE.DMRData'." Source="QADBASE" I am getting the error in the code below on the createDMRIssue

[code]...

View 1 Replies

Interface And Graphics :: Create A User Interface In A Game Such As The Application XFire Using VB?

Jan 12, 2010

how to create a user interface in a game such as the application XFire using Visual Basic?

View 3 Replies

Interface And Graphics :: Use A Graphical User Interface That Contains A Drag And Drop Form?

Oct 19, 2008

I'm working on a design project where I have to use a Graphical User Interface that contains a drag and drop form. It consists of having a window dropped on a wall. Both of them are images to scale. I would like to know what kind of code I would have to use to show the x and y coordinates of one of the points of my window when dragged so when I drop it, I'm dropping in it on the desired coordinate of the wall.

View 2 Replies







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