MVVM Light RaisePropertyChanged Error - vb.net

I followed examples of RaisePropertyChanged for the MVVM Light libraries in a WPF application. This seems like it should be valid. Event the code hints seem to think so. But when I build, Visual Studio gives me an error and then highlights RaisePropertyChanged with light blue squiggleys. Anyone seen this issue? Is there something obvious I'm missing?
Private _selectedServerInstance As String
Property SelectedServerInstance As String
Get
Return _selectedServerInstance
End Get
Set(value As String)
_selectedServerInstance = value
RaisePropertyChanged(Function() Me.SelectedServerInstance) //Error on build
End Set
End Property
' Looks ok until I build. The Error for each line with RaisePropertyChanged using a lambda property selector is:
' error BC30518: Overload resolution failed because no accessible 'RaisePropertyChanged' can be called with these arguments:

for RaisePropertyChanged:
References required to assemblies 'System.Linq.Expressions', 'System.Runtime', 'System.ObjectModel'.
Check References in your project.

System.Runtime and System.ObjectModel are not in the list of references to choose. Is this because they are 'facade' references, and rarely get used except in the crazy case of mvvm-light?

Related

What is Office.Tools.Ribbon.RibbonControlImpl?

I am building a small helper to fetch and populate all the controls of a ribbon group inside a collection.
Option Strict On
Imports Microsoft.Office.Tools.Ribbon
Private Function GetChildControls(Group As RibbonGroup) As IEnumerable(Of RibbonControl)
Dim ChildControls As New List(Of RibbonControl)
Dim SubControls As IEnumerable(Of RibbonControl) = Group.Items
ChildControls.AddRange(SubControls)
' ...
' Some recursive call over SubControls to get the children of each child (not relevant here)
' ...
Return ChildControls
End Function
Code breaks at ChildControls.AddRange(SubControls), with the following exception:
System.InvalidCastException: 'Unable to cast object of type Microsoft.Office.Tools.Ribbon.RibbonControl[]' to type Microsoft.Office.Tools.Ribbon.RibbonControlImpl[]'.'
I cannot find any reference at all on RibbonControlImpl. The Microsoft documentation is silent, and - surprisingly - so are Google or StackOverflow.
Changing ChildControls.AddRange(SubControls) into SubControls.ToList.ForEach(Sub(p) ChildControls.Add(p)) does not work either, but a classic For Each does the trick:
For Each MySubControl As RibbonControl In SubControls
ChildControls.Add(MySubControl)
Next
I would like to understand what is happening here? Is Impl a suffix to interface types to signify something? Maybe 'Impl' stands for 'Implementation'? I could not find any information on this either.
Just some thoughts, no idea if I am right; what do you think?
Office.Ribbon.RibbonControl is an interop interface, hence cannot be used as a generic type across assemblies. A guess would be that Microsoft implemented a non-interop RibbonControlImp wrapper to which RibbonControl is implicitly cast every time it is referenced as a generic type.
No idea how this would be achieved, but that would explain why For Each ... Next does not throw the error, whilst relying on generic collections does.

How can I get the display name from my enum

I have researched and it seems that most is bouncing around the problem I have.
#Code
#Imports System.ComponentModel
Dim values = New SelectList([Enum].GetNames(GetType(myEnum)).GetAttribute<DisplayAttribute>()
End Code
The last pararenthesis has a blue line under it and when hover tells me an expression is expected. I want to capture the display name from my enum and have tried many things found on the google search without success. Why am I getting the expression expected error?
Attempted to incorporate and now getting at end parenthesis
Dim type = typeof(MyEnum) ls is expected.
You might want to have a look at this awesome NuGet package called UnconstrainedMelody from Jon Skeet.
https://www.nuget.org/packages/UnconstrainedMelody/
Helpful static methods (or extension methods) for enums and delegates, with constraints which can't be expressed in regular C#.
Have a look at the functions UnconstrainedMelody.Enums.GetNames() and UnconstrainedMelody.Enums.GetValues()

VB.net warning with VB6 code: how to fix it?

How can I use this code:
VB6.LoadResString(i)
without getting this warning:
Public Function LoadResString(ID As Integer) As String is obsolete:
'Microsoft.VisualBasic.Compatibility.* classes are obsolete and supported
within 32 bit processes only. http://go.microsoft.com/fwlink/?linkid=160862'.
The posted link in the error and other info in the MSDN site only say to me "ehy, this is obsolete in your framework, don't use it", but what if I need it (Loads a string from a resource (.res) file.)?
How can I write it without getting that warning message?
UPDATE: Thanks, but nothing worked...

.Net How to find SuppressMessageAttribute category for a given warning (BC42015)

I'm looking for a way how to find a SuppressMessageAttribute catagory for a given warning (BC42015).
After recieving the following warning I would like to suppress it.
'SomeLib.SomeInterface.DrawRuler' is already implemented by the base class 'SomeLib.SomeClass'. Re-implementation of function assumed. C:\Project\somefile.vb 5 115 ALibName
Using the SuppressMessage attribute should work but how can I find the relevant Catagory. The following won't work.
<CodeAnalysis.SuppressMessageAttribute("IDUNNO","BC42015")>
All MSDN examples are pretty useless.
In Source Suppression Overview
Rule Category - The category in which the rule is defined. For more information about code analysis rule categories, see some useless link.
The general way to discover the category for a Code Analysis warning, for use in the SuppressMessageAttribute attribute would be to consult the documentation for the warning.
For instance, for CA1039, we get:
TypeName ListsAreStronglyTyped
CheckId CA1039
Category Microsoft.Design
Breaking Change Breaking
Now, for BC42015 we don't find such information. Why? Because it's not a code analysis warning. It's a compiler warning (note that we're in a completely different part of the MSDN library).
So far as I'm aware, there's no local way to override compiler warnings in VB - all you can do is disable the warning at the project level (but I'll admit, this is hardly ever what you want to do).
You should find a list of warnings on : http://msdn.microsoft.com/en-us/library/dd380629(v=vs.100).aspx and http://msdn.microsoft.com/en-us/library/ms228296%28v=VS.90%29.aspx
P.S: to supress the specific warning, have you tried http://msdn.microsoft.com/en-us/library/vstudio/edzzzth4(v=vs.100).aspx ?
In VS2010, you can just right-click the message in the error list and
select "Suppress Message(s)" You have the option to suppress in source
or in the global project suppression file.
You can look at the generated suppression, see what it did.
As mentioned in Damien_The_Unbeliever's answer, the code analysis warnings are treated differently from compiler warnings. However, you may use a preprocessor directive (#Disable Warning in VB, #pragma warning in C#) to suppress this or other compiler warnings at a particular point in your code.
This example shows BC40003 being suppressed where class C2 implements sub1, which has already been implemented by base class C1:
Interface I1
Sub sub1(arg1 As Integer)
End Interface
Class C1
Implements I1
Public Sub sub1(arg1 As Integer) Implements I1.sub1
End Sub
End Class
Class C2
Inherits C1
Implements I1
#Disable Warning BC40003
Public Sub sub1(arg1 As Integer) Implements I1.sub1
#Enable Warning BC40003
End Sub
End Class

Why am I having to double cast here?

I have inheritance structure: Foo implements IGraphNode inherits IGraphItem.
Foo, IGraphItem/IGraphNode, and the implementation for IGraphItem/IGraphNode all reside in separate assemblies. I am using an inversion of control container, so the project I'm working in has a reference to the first two (Foo and IGraphItem/IGraphNode), but not the implementation of IGraphItem/IGraphNode. I also have Option Strict on as it is required for this project (turning if off didn't fix the problem). I'm using .NET 3.5.
I am passing a IGraphItem around and I have code that looks like this:
Public Sub ProcessItem(of IGraphItem)(item As IGraphItem)
If TypeOf item Is Foo Then
Dim f1 = CType(item, Foo) 'Compiler error
Dim f2 = DirectCast(item, Foo) 'Compiler error
'This is what I'm currently having to do. It works.
Dim f = CType(CType(item, IGraphNode), Foo)
'Do stuff
End If
End Sub
Any idea why I'm having to do this? I should add that TryCast works, but since we've just confirmed that item's type is Foo, I don't see why I can't DirectCast it. Shouldn't it just let me and throw an exception if I'm wrong? Is there a better way to accomplish what I'm trying to do?
Your original code compiles without a problem, even when target framework is 3.5.
The problem with your current code is that you've defined a generic method whereas IGraphItem is not the type of your interface but the generic type T which can be any type. But it cannot be another type than T and you're trying to cast it to type Foo.
If you would change your method signature to anything else it would work, for instance:
Public Sub ProcessItem(of IGraphItm)(item As IGraphItem)
I assume that you're somehow "shadowing" the type IGraphItem of your interface with the generic type IGraphItem in this method.
It would also work if you would explicitely tell the compiler that item As IGraphItem actually is a item As YourNamespace.IGraphItem.
I'm sure Jon or Eric could explain it better, but maybe it's helpful anyway ;)
This article might answer your question. If not, well, it's an excellent reading anyway.
http://blogs.msdn.com/b/ericlippert/archive/2009/03/19/representation-and-identity.aspx