It's been awhile since I've done much VB.NET development.
Anyway I was putting together a solution that contains 2 projects with identical structures.
One in C# and the other in VB.Net to illustrate some of the diffs to our VB.NET devs.
I just cranked out a very simple class for each language.
All it does is Traverse a Directory and adds info about the files into a Dictionary<String, FileAttributes>
Everything complied fine, and the NUnit test for each respective project run fine. For giggles, I thought I would write a test that compared the execcution time of each implementation, just because I am curious.
When I try to access the VB.NET colection from C#, it throws me an error.
NUnit Errors wrote:
NetDemo.CDemo.Tests.CDemoTests.TimedCommandExecutionTest : System.InvalidCastException : Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,Microsoft.VisualBasic.FileAttribute]' to type 'System.Collections.Generic.Dictionary`2[System.String,System.IO.FileAttributes]'.
The Offending Line of Code in my C# Test is this.
vbfileCollection = (Dictionary<String, System.IO.FileAttributes>)myVBFileCmd.Results; If I try to change the Code to
vbfileCollection = (Dictionary<String, Microsoft.VisualBasic.FileAttribute>)myVBFileCmd.Results;
It tells me that there is no FileAttribute Member in Microsoft.VisualBasic.
Does anyone know exactly what I am doing 'wrong' here, and better yet why this doesn't work?
I thought all the .NET languages were pretty much interchangable?
The C# Test Code that Calls VB.Net Code
VBDemo.Commands.FileListCommand myVBFileCmd = new NetDemo.VBDemo.Commands.FileListCommand(directoryPath);
vbfileCollection = (Dictionary<String, System.IO.FileAttributes>)myVBFileCmd.Results;
VB Runtime Code
NamespaceNetDemo.VBDemo.Commands Public Class FileListCommand
Inherits BaseCommand Private _fileCollection As Dictionary(Of String, FileAttribute) = New Dictionary(Of String, FileAttribute) Private _dInfo As DirectoryInfo
Public Sub New(ByVal filePath As String)
_dInfo = New DirectoryInfo(filePath)
End Sub Public Overrides Sub Execute()
Dim fInfo() As FileInfo Try
fInfo = _dInfo.GetFiles()
For Each f As FileInfo In fInfo
MyBase._results = Me._fileCollection
End Try End Sub End Class