[en] MEF, Events, Inheritated Interface and Zyan (solved)

Topics: Technical Support
Jun 11, 2013 at 11:35 AM
Edited Jun 13, 2013 at 11:51 AM
Hello,

I very frustrated in the last days. i not able to run the application again. Here are some VB.NET samples to show my Prolem

IBase
Public Interface IBase
    Event ServerCalled As ServerCalledEventHandler
End Inteface
IUserManagement
<InheritedExport(GetType(IBase))>
Public Interface IUserManagement

    Inherits IBase
    [....]
End Interface
ClassBase
Public Class ClassBase

    Implements IBase
    
    Public Event ServerCalled(args As DataExtensions.DataSource.ClientCallerArgs) Implements IBase.ServerCalled

   [...]
End Class
UserManagement (Serverside)
<ZyanComponent(GetType(IUserManagement)),
PartCreationPolicy(ComponentModel.Composition.CreationPolicy.Shared)>
Public Class UserManagement

    Inherits ClassBase
    Implements IUserManagement

    [...]
End Class
AdminUsersViewModel (Clientside)
Public Class AdminUsersViewModel

    Inherits ViewModel

    Private _ZyanProxy As IUserManagement
    Private _VDataManager As VirtualDataManager

    Public Sub New()
        _ZyanProxy = ConnectClient.Connection.CreateProxy(Of IUserManagement)()
        _VDataManager = New VirtualDataManager

       AddHandler _ZyanProxy.ServerCalled, AddressOf _VDataManager.ServerCalled
      [...]
End Class
If I try so set the AddHandler, then come up the following error:
"System.Collections.Generic.KeyNotFoundException" in Zyan.Communication.DLL ...
Where is the problem? Is it the MEF or Zyan? I have download the actual sourcecode and compile them for my application. I hope someone understand my problem

Thanks for the help and helpfull ideas!!!
Coordinator
Jun 13, 2013 at 11:16 AM
Hi,
System.Collections.Generic.KeyNotFoundException in Zyan.Communication.DLL ...
Unfortunately, the information you provided is not sufficient to say anything.
Please post the whole exception data, with inner exceptions and the stack trace data, including line numbers.
Coordinator
Jun 13, 2013 at 11:23 AM
Also, I can't quite understand your application structure...
Looks like MEF attributes are somewhat misplaced.
  • Why do you apply InheritedExport(GetType(IBase)) to the IUserManagement interface?
  • Why doesn't your UserManagement class implement IUserManagement interface?
    Exporting IUserManagement doesn't make sense unless your class implements the exported interface.
  • What is the purpose behind the ClassBase class?
Jun 13, 2013 at 11:47 AM
Edited Jun 13, 2013 at 1:21 PM
Here the Stack-Trace
Server stack trace: 
   bei System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   bei Zyan.Communication.Delegates.EventStub.AddHandler(String name, Delegate handler)
   bei Zyan.Communication.ZyanDispatcher.CreateClientServerWires(Type type, EventStub eventStub, List`1 delegateCorrelationSet, Dictionary`2 wiringList)
   bei Zyan.Communication.ZyanDispatcher.AddEventHandler(String interfaceName, DelegateCorrelationInfo correlation, String uniqueName)
   bei System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   bei System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]: 
   bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   bei Zyan.Communication.IZyanDispatcher.AddEventHandler(String interfaceName, DelegateCorrelationInfo correlation, String uniqueName)
   bei Zyan.Communication.ZyanProxy.AddRemoteEventHandler(DelegateCorrelationInfo correlationInfo)
   bei Zyan.Communication.ZyanProxy.HandleEventSubscription(IMethodCallMessage methodCallMessage, MethodInfo methodInfo)
   bei Zyan.Communication.ZyanProxy.InterceptAndInvoke(IMethodCallMessage methodCallMessage, Boolean allowInterception)
   bei Zyan.Communication.ZyanProxy.Invoke(IMessage message)
   bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   bei DataExtensions.DataSource.IBase.add_ServerCalled(ServerCalledEventHandler value)
   bei Client.Application.AdminUsersViewModel..ctor() in D:\_AppDev\Visual Studio 2010\Projekte\Client.Application\ViewModels\AdminUsersViewModel.vb:Zeile 41.
Line 41 is the 'AddHandler"-Line of Client-Side code
Jun 13, 2013 at 11:57 AM
Edited Jun 13, 2013 at 1:20 PM
yallie wrote:
Also, I can't quite understand your application structure...
Looks like MEF attributes are somewhat misplaced.
  • Why do you apply InheritedExport(GetType(IBase)) to the IUserManagement interface?
  • Why doesn't your UserManagement class implement IUserManagement interface?
    Exporting IUserManagement doesn't make sense unless your class implements the exported interface.
  • What is the purpose behind the ClassBase class?
OK - I will try to explain

But first: I have missspelled the UserManagemt-Snippet. Now ist correkt - it implements IUserManagement - Sorry

To your first question: I have understand, that InheritedExport shoulb be link to the "sub"-Interface. If I change it to "IUserManagement" then following error cames up:
Es wurde mehr als ein Export gefunden, der der Einschränkung "((exportDefinition.ContractName == "Common.Application.IUserManagement") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "Common.Application.IUserManagement".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))" entspricht.
the Stacktrace:
Server stack trace: 
   bei System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
   bei System.ComponentModel.Composition.Hosting.ExportProvider.GetExportsCore(Type type, Type metadataViewType, String contractName, ImportCardinality cardinality)
   bei System.ComponentModel.Composition.Hosting.ExportProvider.GetExportCore[T](String contractName)
   bei System.ComponentModel.Composition.Hosting.ExportProvider.GetExport[T](String contractName)
   bei Zyan.Communication.Composition.IComponentCatalogMefExtensions.<>c__DisplayClass8`1.<RegisterComponent>b__2()
   bei Zyan.Communication.ComponentCatalog.GetComponentInstance(ComponentRegistration registration)
   bei Zyan.Communication.ZyanComponentHost.GetComponentInstance(ComponentRegistration registration)
   bei Zyan.Communication.ZyanDispatcher.Invoke_ResolveComponentInstance(InvocationDetails details)
   bei Zyan.Communication.ZyanDispatcher.AddEventHandler(String interfaceName, DelegateCorrelationInfo correlation, String uniqueName)
   bei System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   bei System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]: 
   bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   bei Zyan.Communication.IZyanDispatcher.AddEventHandler(String interfaceName, DelegateCorrelationInfo correlation, String uniqueName)
   bei Zyan.Communication.ZyanProxy.AddRemoteEventHandler(DelegateCorrelationInfo correlationInfo)
   bei Zyan.Communication.ZyanProxy.HandleEventSubscription(IMethodCallMessage methodCallMessage, MethodInfo methodInfo)
   bei Zyan.Communication.ZyanProxy.InterceptAndInvoke(IMethodCallMessage methodCallMessage, Boolean allowInterception)
   bei Zyan.Communication.ZyanProxy.Invoke(IMessage message)
   bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   bei DataExtensions.DataSource.IBase.add_ServerCalled(ServerCalledEventHandler value)
   bei Client.Application.AdminUsersViewModel..ctor() in D:\_AppDev\Visual Studio 2010\Projekte\Client.Application\ViewModels\AdminUsersViewModel.vb:Zeile 41.
So, now what I want to do.

I want to have a generell Interface. In the IBase shoulb be a event that in ALL interfaces are the same.

All Modul-Interfaces (aka IUserManagement) should be inherited from IBase and have the modul specific functions

Is that possible?

BTW: ClassBase have some Properties and Funtions for displaying text and so on. Not complicates or so. Do you need more Information about that? I thing the ClassBase can delete from the snippet.

I hope it was helpfull
Coordinator
Jun 13, 2013 at 4:15 PM
Edited Jun 13, 2013 at 4:18 PM
This discussion has been copied to a work item: https://zyan.codeplex.com/workitem/2047
Coordinator
Jun 13, 2013 at 4:36 PM
Edited Jun 13, 2013 at 4:36 PM
Please download the latest source code for Zyan.
This fix will be included in the upcoming 2.5 release.
Let me know if it solves the problem.
 
To your first question: I have understand, that InheritedExport shoulb be link to the "sub"-Interface.
If I change it to "IUserManagement" then following error cames up:
Looks like InheritedExport attribute is not needed here because you mark your services with ZyanComponent attribute.
Try commenting it out, everything should work like before.
 
I want to have a generell Interface. In the IBase shoulb be a event that in ALL interfaces are the same.
All Modul-Interfaces (aka IUserManagement) should be inherited from IBase and have the modul specific functions
Is that possible?
Yes, certainly.
Coordinator
Jun 13, 2013 at 4:40 PM
One more thing.
Do you really need Shared creation policy?
I'd recommend to avoid it in most cases.
Jun 13, 2013 at 5:39 PM
Thank you very much for the fast support.

Now it works fine again - thank you for your fine project