CruiseControl .Net Plugin Vb.net Error - vb.net

I am trying to make my own Labeller plugin for Cruise Control .Net 1.4.3. I have made a class based on another plug in example but I keep getting an error
Class 'AssemblyVersionLabeller' must implement 'Function Generate(integrationResult As IIntegrationResult) As String' for interface 'ThoughtWorks.CruiseControl.Core.ILabeller'
Here is my code :
Imports Exortech.NetReflector
Imports ThoughtWorks.CruiseControl.Core
Imports ThoughtWorks.CruiseControl.Core.Util
Namespace NetAssembly.CCNet.Label
_
Public Class AssemblyVersionLabeller
Implements ILabeller
Public Sub Run(ByVal result As IIntegrationResult)
result.Label = Generate(result)
End Sub
Public Function Generate(ByVal integrationResult As IIntegrationResult) As String
Dim label As String = integrationResult.LastIntegration.Label
Return label
End Function
<ReflectorProperty("prefix", Required:=False)> _
Public Prefix As String = String.Empty
End Class
End Namespace
What am I doing wrong? What have I missed?
Background Info:
I am using VS2005. I cant use CrusieControl 1.4.4 RC2 (which has an Assembly Labeller) because my source control's plugin (SCM Anywhere) doesnt work with it.

I cannot judge just by looking at your code, but if you need a sample on how to write labellers (C# code though), you could take a look at BrekiLabeller code (written by me).

I believe you forgot the overrides decleration..
Public Overrides Function Generate

Related

Method 'set_Description' in type 'myAssembly.NetProduct' from assembly 'myAssembly' does not have an implementation

I have a DLL file created in VB6. It contains a class named Product and that contains the following simple code:
Option Explicit
Private sDescription As String
Public Property Get Description() As String
Description = sDescription
End Property
Public Property Let Description(Value As String)
sDescription = Value
End Property
I want to use this DLL in VB.NET, which is nothing more than registering the DLL on my system and including the DLL file in the references. Visual Studio automatically generates an interop DLL to consume the COM DLL. This interop DLL generates interfaces for all classes. In VB.NET I want to create a new class that implements the Product interface from the interop DLL. So I code:
Imports myAssembly
Public Class NetProduct
Implements myAssembly.Product
Public Property Description As String Implements _Product.Description
Get
Throw New NotImplementedException()
End Get
Set(value As String)
Throw New NotImplementedException()
End Set
End Property
End Class
The property is auto-generated because I implemented the Product interface. But here comes the problem because when I start using the NetProduct class I get an error telling me this:
Method 'set_Description' in type 'myProject.NetProduct' from
assembly 'myProject, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' does not have an implementation.
The problem is that there is no method set_Description in the interface. When I view the definition of the Product interface it shows me the following:
Imports System.Runtime.InteropServices
Namespace myAssembly
<CoClass(GetType(ProductClass))> <Guid("49CE2F98-931C-441B-B322-9F39B6D6F212")>
Public Interface Product
Implements _Product
End Interface
End Namespace
The definition of the _Product interface is:
Imports System.Runtime.InteropServices
Namespace myAssembly
<Guid("49CE2F98-931C-441B-B322-9F39B6D6F212")> <TypeLibTypeAttribute(4304)>
Public Interface _Product <DispId(1745027072)>
Property Description As String
End Interface
End Namespace
When I use the interface myAssembly.Product directly to create a new object then everything works as you would expect. The property does not pose a problem there. But when I implement the interface in a .NET class the problem arises.
How do I solve this?
[update 1] After creating a method Set_Description I see the following error appear:
property 'Description' implicitly defines 'set_Description', which
conflicts with a member of the same name in class 'NetProduct'.
This must have something to do with my problem, although I don't know what it is. I already tried completing the property to make sure the Throw New NotImplementedException() wouldn't be in the way but that didn't make the error go away. My code builds just fine by the way. The error I gave earlier is a runtime error. Not a build error.
Private myDescription As String
Public Property Description As String Implements Product.Description
Get
Return myDescription
End Get
Set(value As String)
myDescription = value
End Set
End Property
[update 2] I have used JetBrains DotPeek to disassemble the interop.dll that Visual Studio generates. Disassembly is coded in C#. It contains 2 interfaces and 1 class for the single Product class from VB6. Here are all details.
I'll start with the Product class itself.
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace myAssembly
{
[ClassInterface(0)]
[Guid("C54B96A8-1499-4B76-8508-0B732E551326")]
[TypeLibType(2)]
[ComImport]
public class ProductClass : _Product, Product
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public extern ProductClass();
[DispId(1745027072)]
public virtual extern string Description { [DispId(1745027072), MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] [return: MarshalAs(UnmanagedType.BStr)] get; [DispId(1745027072), MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] [param: MarshalAs(UnmanagedType.BStr), In, Out] set; }
}
}
The ProductClass uses 2 interfaces. I don't understand why because one of those is just an implementation of the other. This is the Product interface.
using System.Runtime.InteropServices;
namespace myAssembly
{
[CoClass(typeof (ProductClass))]
[Guid("49CE2F98-931C-441B-B322-9F39B6D6F212")]
[ComImport]
public interface Product : _Product
{
}
}
And then we have the _Product interface. They even share the same Guid. It might have something to do with backwards compatibility.
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace myAssembly
{
[Guid("49CE2F98-931C-441B-B322-9F39B6D6F212")]
[TypeLibType(4304)]
[ComImport]
public interface _Product
{
[DispId(1745027072)]
string Description { [DispId(1745027072), MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] [return: MarshalAs(UnmanagedType.BStr)] get; [DispId(1745027072), MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] [param: MarshalAs(UnmanagedType.BStr), In, Out] set; }
}
}
This is all I could find. Still no clue where the error for Set_Description comes from.
[Update 3] Example code
The code for the VB6 class is on top of this question. Nothing fancy there. The code for testing implementation in .NET is like this:
Imports myAssembly
Public Class NetProduct
Implements myAssembly.Product
Private myDescription As String
Public Property Description As String Implements Product.Description
Get
Return myDescription
End Get
Set(value As String)
myDescription = value
End Set
End Property
End Class
To test the NetProduct class I dropped a Button on a Form and create an instance of the class when the button is being clicked.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click '<- Error happens here, so on loading the datatype!
Dim Product As New NetProduct 'Error does NOT happen here.
End Sub
The whole project compiles without errors. The project even runs without errors UNTIL you click the button. Probably because the NetProduct type is first loaded on that point.
I used a console app to do my test. Other than that, my VB.NET code is basically identical to yours in update 3. The VB.NET properties were auto-generated by VS with the stub Throw New NotImplementedException() after using the Implements statement :
Imports OurCOMDll
Class TestClass
Implements OurCOMDll.ClassInCOMDll
Dim msStringProperty As String = String.Empty
Public Property StringProperty As String Implements _ClassInCOMDll.StringProperty
Get
StringProperty= msStringProperty
End Get
Set(value As String)
msStringProperty = value
End Set
End Property
End Class
Module Module1
Sub Main()
Dim o As New OurCOMDll.ClassInCOMDll
o.StringProperty = "Hello World!"
Console.WriteLine(o.StringProperty) ' Outputs 'Hello World!' as expected
Console.ReadLine()
End Sub
End Module
Same is true for the VB6 code. The string property is implemented like yours.
Distinguishing factors so far:
VS 2019 vs. VS 2017
(Consuming) GUI vs. Console application
Different property names

How do I make a property of a custom control open a file dialog?

I have a custom control with a property that holds the name (full path) to a file location that exists on the target computer.
The exact path will vary according to type of target pc and is typically set right after I add the custom control to my Form, while I am still in design mode of my project, so that when my application runs, it picks up the filename from the property.
It would be convenient if the property opened a file dialog to let me browse to the location (similar to how dialogs are opened when browsing for image and color properties), but this doesn't seem to be possible in visual basic.
After googling for days I have found a couple of articles that touch the subject for other programming languages (see example snippet below) but I haven't been able to work out how to make it work for visual basic.
Here is a snippet I found that mentions the use of an editor, which may be a clue to get started.
[Editor(typeof(FileSelectorTypeEditor), typeof(UITypeEditor))]
public string Filename
{
get { return _filename; }
set { _filename = value; }
}
Hope someone out there can lead me in the right way.
FileSelectorTypeEditor is probably a custom class derived from either FileNameEditor or FolderNameEditor.
You can implement both, using the standard class or extend the default with your own, as you have seen in those C# sources you have found.
Here I'm using a specialized FileNameEditor class, named (with some lack of imagination) SpecializedFileNameEditor and the standard FolderNameEditor assigning the UITypeEditor to two properties of a class.
► The ImagePath property editor is the SpecializedFileNameEditor object, which uses an OpenFileDialog, where a filter is pre-selected. It also overrides the EditValue method, to set the current value, if any, of an associated property (here, ImagePath) as the InitialDirectory of the OpenFileDialog.
► The ImageFolder property editor is a standard FolderNameEditor, which opens a FolderBrowserDialog.
I'm also attaching an ExpandableObjectConverter type converter, so you can present the two properties as an expandable property selector in a PropertyGrid.
You can see an example here:
How to bind child Controls of a User Control to a Public Property
Imports System.ComponentModel
Imports System.Drawing.Design
Imports System.IO
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
<TypeConverter(GetType(ExpandableObjectConverter))>
Public Class ImagePickerClass
Public Sub New()
' Initialize [...]
End Sub
<Editor(GetType(SpecializedFileNameEditor), GetType(UITypeEditor))>
Public Property ImagePath As String
<Editor(GetType(FolderNameEditor), GetType(UITypeEditor))>
Public Property ImageFolder As String
Public Class SpecializedFileNameEditor
Inherits FileNameEditor
Private currentValue As String = String.Empty
Public Overrides Function EditValue(context As ITypeDescriptorContext, provider As IServiceProvider, value As Object) As Object
If TypeOf value Is String Then
currentValue = DirectCast(value, String)
End If
Return MyBase.EditValue(context, provider, value)
End Function
Protected Overrides Sub InitializeDialog(ofd As OpenFileDialog)
MyBase.InitializeDialog(ofd)
If Not currentValue.Equals(String.Empty) Then
ofd.InitialDirectory = Path.GetDirectoryName(currentValue)
End If
ofd.Filter = "PNG Images (*.png)|*.png"
End Sub
End Class
End Class

VB.NET multithreading

I need to do a taks on a list of parameters: all those tasks are independant.
I don't see how to do it.. I tried to divide the parameters into one "shared class" and make a different instance of a class for each item in the list, and then launch the function on each instance asynchroneously :
Imports System.Runtime.InteropServices
Imports System.IO
Public Class DataContainer
Public Parameters as double 'obviously simplified code ;-)
End Class
Public Class JobDoer
Public CommonData As DataContainer
Public PrivData as double
Public Async Function YesWeCan() As Task(Of Boolean)
Return Task.Factory.StartNew(Of Boolean)(
DoIt(CommonData.Parameters , PrivData)
)
End Function
Public Function DoIt(a as double,b as double)
return 0
end function
End Class
==> Task is not defined...
.NET framework 3.0
VS 2015
Any ideas?
The Async and Await keywords are not available in .NET 3.0. They have been introduced in .NET 4.5, although you can already make use of them in 4.0 (with some modifications, like having to use TaskEx instead of Task for some of the static functions) if you import the Microsoft.Bcl.Async package via NuGet.
You can of course simply start new threads without having to use Async/Await.
Or you could use the ThreadPool. Here is some code I made back in the past, which was originally written in C#. I converted it now and removed the parts that would require at least .NET 4.0. Didn't test it, though.
Private Sub SubmitWorkToThreadPool()
For i as Integer = 0 To yourWorkItems.Count 'Adjust this loop so it adds all your tasks to the thread pool.
'customParameter is passed as parameter 'state' to the DoParallelWork function.
ThreadPool.QueueUserWorkItem(AddressOf DoParallelWork, customParameter)
Next
End Sub
Private Sub DoParallelWork(state As Object)
'TODO: Add code to be executed on the threadpool
End Sub
In the 4.0 version I had it written in a way that would allow me to wait for all work items to be completed after submitting it to the threadpool by using a CountdownEvent. But that class only exists since 4.0, so I removed it. You might have to find another way if you need to wait for everything to be done.

How to Inject a parameter to constructor using unity

Hi I am using unity in WebAPI 1.0 and registered it under Global.asax.vb file as below
Dim container As IUnityContainer = New UnityContainer()
container.RegisterType(Of Car)(New InjectionConstructor(GetType(Integer)))
Now how do i pass integer value which is passed by the client application into car type using
Public Sub New(ByVal intUserId As Int32)
objCar = DependencyResolver.Current.GetService(Of car)()
End Sub
Can't find anything to use (ParameterOverride("intUserId", intUserId) within DependencyResolver
It is very similar as registering unity container with ASP.NET MVC. Though web api has a different execution pipe line. Follow these steps.
NB: I have converted this code from C# to VB using a converter. So I hope it is syntactically correct. Though it is accurate in c#.
1) Implement IDependencyResolver (Make sure you are resolving correct namespace here. IDependencyResolver should come from System.Web.Http.Dependencies. Make note of Imported namespaces.
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports Microsoft.Practices.Unity
Imports System.Web.Http.Dependencies
Namespace YourNamespace.Framework
Public Class UnityApiDependencyResolver
Implements IDependencyResolver
Private _container As IUnityContainer = Nothing
Public Sub New(container As IUnityContainer)
Me._container = container
End Sub
Public Function GetService(serviceType As Type) As Object
Try
Return _container.Resolve(serviceType)
Catch generatedExceptionName As Exception
Return Nothing
End Try
End Function
Public Function GetServices(serviceType As Type) As IEnumerable(Of Object)
Try
Return _container.ResolveAll(serviceType)
Catch generatedExceptionName As Exception
Return Nothing
End Try
End Function
Public Function BeginScope() As IDependencyScope
Return Me
End Function
Public Sub Dispose()
'
End Sub
End Class
End Namespace
'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: #telerik
'Facebook: facebook.com/telerik
'=======================================================
2) Configure your container either thgough config or through code.
3) Register your container in Global.asax.vb file
Dim container = New UnityContainer()
Dim section As UnityConfigurationSection = TryCast(ConfigurationManager.GetSection("unity"), UnityConfigurationSection)
section.Configure(container, "UnitySection")
'api dependency resolver
GlobalConfiguration.Configuration.DependencyResolver = New UnityApiDependencyResolver(container)
'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: #telerik
'Facebook: facebook.com/telerik
'=======================================================
Thats it.
Now you can declare your dependency in any of your API controller and it will be injected by Unity
Public Sub New(repositoryFactory As IRepositoryFactory, serviceFactory As IServiceFactory)
Me.repositoryFactory = repositoryFactory
Me.serviceFactory = serviceFactory
End Sub
'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: #telerik
'Facebook: facebook.com/telerik
'=======================================================
Your type registration is wrong as well. you have to specify either an interface or an abstract class as dependency and its concrete implementation as its mapping.
e.g
container.RegisterType(Of IContext, Context)()
I don't understand what are trying to achieve by mapping an integer value to car. Do you want car object to be loaded based on integer value in your parameter?

DisplayName DataAnnotations not working in WinForms 3.5 DataGridView

Ok, I'm completely at a loss here. I've used DataAnnotations attribute DisplayName successfully using MVC model binding, and even with WPF/Silverlight model binding and of course it works just fine, but now I'm on a project that I'm forced to use VB.NET 3.5 WinForms.
I have a Linq2Sql model and I created a partial class for one of my classes and included a MetadataType attribute to point to a metadata class. I added a DisplayName attribute to a property in the metadata class. I then bind my datagridview with an IQueryable(Of mydatatype), but the column name in the grid is the Property's name and not the DisplayName.
Am I missing something? Is there something else I need to do to get the datagridview to use the DisplayName?
In my Model class:
Imports System.ComponentModel
Imports System.ComponentModel.DataAnnotations
<MetadataType(GetType(vwREVIEW_ECRMetadata))> _
Partial Class vwREVIEW_ECR
Public Sub TestMethod()
End Sub
End Class
Public Class vwREVIEW_ECRMetadata
Private _ECRNumber As String
<DisplayName("ECR #")> _
Public Property ECRNumber() As String
Get
Return _ECRNumber
End Get
Set(ByVal value As String)
_ECRNumber = value
End Set
End Property
End Class
In my Repository class:
Public Function GetAllECRsForLookup() As IQueryable(Of vwREVIEW_ECR)
Return db.vwREVIEW_ECRs
End Function
In my Presenter class:
Public Sub GetData()
view.FillData(model.GetFilteredECRsForLookup())
End Sub
In my View:
Public Sub FillData(ByVal data As System.Linq.IQueryable(Of vwREVIEW_ECR)) Implements ILookupECRView.FillData
Me.uxECRData.DataSource = data
End Sub
Any help would be greatly appreciated! Thanks
Ok, so I found a solution to my problem. Didn't even think about it this way, but in ASP.NET & WPF, you get this behavior becuase of model binding behavior built in. WinForms has databinding as well, but isn't just there for your. Though I could've "bound" my datagridview to my linq2sql generated object in the runtime, which would've accomplished what I needed, I needed to do this at design time, so instead, I modified my MVP to use ViewModels where needed, and bind the datagrid to that object at runtime to get my column names to look the way I want. The ViewModel is hooked up to the model and can pass the real values to it.
I based this approach on this blog, though I didn't fully implement what he did:
http://aviadezra.blogspot.com/2009/08/mvp-mvvm-winforms-data-binding.html