Vibrant discussion about CSLA .NET and using the framework to build great business applications.
OK, so I'm trying to re-engineer things into VB and creating my DALs from scratch using some of the examples I have seen.
I created my first class library, DataAccess, with 3 classes;
DalFactory, DataNotFoundException & IDalManager.
I compiled the class library project and the DataAccess.dll exists as I would expect in Bin/Debug
I then created a DataAccess.Mock class library and added a reference to the above DLL.
Yet when I create the first class in the mock library;
Imports System.Collections.GenericImports System.LinqImports System.Text
Namespace DataAccess.Mock
Public Class DalManager
Implements DataAccess.IDalManager
Private Shared _typeMask As String = GetType(DalManager).FullName.Replace("DalManager", "{0}")
Public Function GetProvider(Of T As Class)() As T Dim typeName = String.Format(_typeMask, GetType(T).Name.Substring(1)) Dim type__1 = Type.[GetType](typeName) If type__1 IsNot Nothing Then Return TryCast(Activator.CreateInstance(type__1), T) Else Throw New NotImplementedException(typeName) End If End Function
Public Sub Dispose() End Sub
End Class
End Namespace
I get an error on the Implements "DataAccess.IDalManager" - type is not defined??
What am I missing?
Thanks,
Graham
Thanks Scott!
That looks almost certainly to be the issue. I have to play around now and see what the resolution is.
I'm tormented by the fact that I may have to shift my development to C# ..( errrghh )... and become a *real* developer ;)
I appreciate your input and will let you know how I make out.
Thanks again,
What you describe seems correct. I usually use project references instead of file references when working within one solution, otherwise you are describing what I do as a matter of course.
I suspect you have some basic issue with the assembly reference - that is sure what it sounds like anyway.
Rocky
I tried using the project reference - no difference.
What I did notice, and I'm not sure it's _the_ issue but when I translate the C# static class DalFactory to VB.Net, it becomes a "NonInheritable" class;
Imports System.Configuration
Namespace DataAccess
Public NotInheritable Class DalFactory
Private Sub New() End Sub
Private Shared _dalType As Type
Public Shared Function GetManager() As IDalManager
If _dalType Is Nothing Then
Dim dalTypeName = ConfigurationManager.AppSettings("DalManagerType")
If Not String.IsNullOrEmpty(dalTypeName) Then _dalType = Type.[GetType](dalTypeName) Else Throw New NullReferenceException("DalManagerType") End If
If _dalType Is Nothing Then Throw New ArgumentException(String.Format("Type {0} could not be found", dalTypeName)) End If
End If Return DirectCast(Activator.CreateInstance(_dalType), IDalManager)
End Function
Could that have anything to do with it?
This is very frustrating, it seems that no matter how I try to move down this CSLA4 path, I hit something that prevents me from moving forward....
The "NotInheritable" shouldn't matter.
Let's start with the basics: how is your IDalManager interface defined? Is it Public?
- Scott
Here's what I have in the DataAccess Library:
The DalFactory.cb class:
The IDalManager.vb class:
Public Interface IDalManager
Inherits IDisposable
Function GetProvider(Of T As Class)() As T
End Interface
And finally the DataNotFoundException.vb class:
Imports System.Collections.GenericImports System.LinqImports System.TextImports Csla.SerializationImports System.Security.Permissions
<Serializable()> _ Public Class DataNotFoundException
Inherits Exception
Public Sub New(message As String) MyBase.New(message) End Sub
Public Sub New(message As String, innerException As Exception) MyBase.New(message, innerException) End Sub
Protected Sub New(info As System.Runtime.Serialization.SerializationInfo, context As System.Runtime.Serialization.StreamingContext) MyBase.New(info, context) End Sub
<SecurityPermission(SecurityAction.LinkDemand, Flags:=SecurityPermissionFlag.SerializationFormatter)> _ <SecurityPermission(SecurityAction.Demand, Flags:=SecurityPermissionFlag.SerializationFormatter)> _ Public Overrides Sub GetObjectData(info As System.Runtime.Serialization.SerializationInfo, context As System.Runtime.Serialization.StreamingContext) MyBase.GetObjectData(info, context) End Sub
The DataAccess project references CSLA. It's assembly name and root namespace are both set to DataAccess.
It builds with no problems on its own and the DataAccess.dll builds to the Bin/Debug folder as I would expect.
My DataAccess.Mock Class library project has a project dependency to DataAccess. I set a reference to the DataAccess project also ( I had previously added the .Net reference to the DataAccess.dll). The project also references CSLA.
It's assembly name and root namespace are both set to DataAccess.Mock
I really don't see where the problem is.
Your help is much appreciated.
Hmmm, just got home and reloaded my Mock project and something else interesting happened. The reference to the DataAccess project said file not found. So I removed it, and added it back via the file.
When I did that the IDE's error correction suggested I change "Implements DataAccess.IDalManager:" to "Implements Global.DataAccess.IDalManager:"
What's THAT all about? When I did do that, it then further errored out by stating:
Class 'DalManager' must implement 'Function GetProvider(Of T As Class)() As T' for interface 'DataAccess.IDalManager'
Class 'DalManager' must implement 'Sub Dispose()' for interface 'System.IDisposable'
So, I removed the reference AGAIN. Re-added it as a Project reference, and NOW the Intellisense wants Global.DataAccess.DataAccess.IDalManager ...
This is unbelievable...
I'm not THAT dense. Things haven't changed that much from VS2005 to VS2010 ... it's a simple bloody reference....
Any ideas anyone?
And yest more info.
It looks like the DataAccess Assembly is sound.
I removed my "Mock" project from the solution, added in the DataAccess.Mock (C#) project that exists in the Encapsulated Invoke - changed the reference to my new VB.Net assembly and it's fine.
So, it looks like the little amount of code in my VB DataAccess.Mock is somehow not working. Did it translate incorrectly? Or is there some underlying issue with the way my Mock project has been created?
I'm losing hope here, that this is going to port to VB....
If someone can prove me wrong I'd appreciate it....
Thanks.
No takers eh?
Well, it appears CSLA4 using VB.Net is a no go, unless someone can prove otherwise.
There is either an assembly referencing issue with VB.Net projects that doesn't exist in the C# world, or the inheritance of the interface in the VB.Net DalManager is incorrect.
To verify, I created 2 completely new C# projects for DataAccess and DataAccess.Mock, and they reference correctly and compile.
The issue clearly lies in the VB arena.
Off to bed, frustrated - as yet another day passes with so many questions and few answers.
I think this post may help:
http://spiderinnet1.typepad.com/blog/2011/12/vbnet-root-namespace-vs-c-default-namespace.html
VB.NET deals with "Root Namespace" differently than C# deals with "Default Namespace". Essentially, VB.NET takes your "Root Namespace" value and prepends it to all your namespace declarations in your code files. Given that, and how you have your namespaces defined, I'm not surprised VS is getting confused.
It's been a REALLY long time since I did VB.NET development - I forgot all about this...
HTH
Well, it looks like we're all good.
I can't thank you enough Scott.
I removed the intrinsic Namespace = .... from my classes and that certainly fixed the referencing problem.
I was left with errors that I was not implementing the GetProvider and Dispose methods of the interface. I let the IDE create a couple for me to see what they looked like, and lo and behold - it looks like the translated code doesn't define the methods correctly:
This is what the vb.Net DalManager class SHOULD look like:
Imports SystemImports System.Collections.GenericImports System.LinqImports System.Text
Public Function GetProvider(Of T As Class)() As T Implements IDalManager.GetProvider
Dim typeName = String.Format(_typeMask, GetType(T).Name.Substring(1)) Dim type__1 = Type.[GetType](typeName) If type__1 IsNot Nothing Then Return TryCast(Activator.CreateInstance(type__1), T) Else Throw New NotImplementedException(typeName) End If
Public Sub Dispose() Implements IDisposable.Dispose End Sub
So, no need to become a *real* developer just yet.... I'll now push on.