D
Danish Ahmed
Hi all
I developed a Visio AddIn in C# through Visual Studio.NET.
This .NET component access my other .NET assemblies for example logger assembly.
I also made a ClassLoader class ( that is in another assembly ClassLoader.dll ) that loads a class from given assembly.
The class loader assembly is statically binded to Visio AddIn assembly.
Due to assembly unloading problem first i load that assembly in another AppDomain and search for the given class name.
I do this through another class RemoteClassChecker that is also in ClassLoader.dll.
RemoteClassChecker is derived from MarshalByRefObject.
ClassLoader first creates RemoteClassChecker instance in another AppDomain through AppDomain.CreateInstanceAndUnwrap method and cast it to RemoteClassChecker and then validates the class presence in the given assembly through RemoteClassChecker's other functions.
If class is present or not it unloads the AppDomain in which RemoteClassChecker made. So the result is if class is present then assembly is loaded in current AppDomain otherwise not.
It all does work well in whole .NET environment but in Visio-AddIn scenario if my other assemblies are not present in VISIO.EXE folder CLR throws InvalidCastException( Specified cast is not allowed ) but if the assemblies are in VISIO.EXE folder again all things work well.
Buttttttttttttt!!! it creates problem for deployment of my assemblies. I want to deploy these in my own private folder for AddIn. Also i do not want to make assemblies strongly typed.
Also i know that when a .NET component is accessed from COM side CLR creates an AppDomain "DefaultDomain" and sets its base directory that of VISIO.EXE.
I also configured the CodeBase value in registry. Is there any other setting in registry that tolds CLR for DefaultDomain settings like BaseDirectory???? I ask this also as my guess about this problem is that my other assemblies are not in BaseDirectory's folder or in its relative folders so CLR would not find meta data of RemoteClassChecker's meta data when unwraping marshaled RemoteClassLChecker object.
Also note that if i do not cast object reference from AppDomain.CreateInstanceAndUnwrap method then no error occurrred. So i try reflection to invoke methods of RemoteClassChecker but this is also not working
Is it a COMInterop problem? or is it related to cross AppDomain accessing?? or some thing else???
If anyone have a solution for this then please reply. Also if there are some ins and outs of this topic then please give links of those resources.
Thanks in advance.
Regards
Danish Ahmed
I developed a Visio AddIn in C# through Visual Studio.NET.
This .NET component access my other .NET assemblies for example logger assembly.
I also made a ClassLoader class ( that is in another assembly ClassLoader.dll ) that loads a class from given assembly.
The class loader assembly is statically binded to Visio AddIn assembly.
Due to assembly unloading problem first i load that assembly in another AppDomain and search for the given class name.
I do this through another class RemoteClassChecker that is also in ClassLoader.dll.
RemoteClassChecker is derived from MarshalByRefObject.
ClassLoader first creates RemoteClassChecker instance in another AppDomain through AppDomain.CreateInstanceAndUnwrap method and cast it to RemoteClassChecker and then validates the class presence in the given assembly through RemoteClassChecker's other functions.
If class is present or not it unloads the AppDomain in which RemoteClassChecker made. So the result is if class is present then assembly is loaded in current AppDomain otherwise not.
It all does work well in whole .NET environment but in Visio-AddIn scenario if my other assemblies are not present in VISIO.EXE folder CLR throws InvalidCastException( Specified cast is not allowed ) but if the assemblies are in VISIO.EXE folder again all things work well.
Buttttttttttttt!!! it creates problem for deployment of my assemblies. I want to deploy these in my own private folder for AddIn. Also i do not want to make assemblies strongly typed.
Also i know that when a .NET component is accessed from COM side CLR creates an AppDomain "DefaultDomain" and sets its base directory that of VISIO.EXE.
I also configured the CodeBase value in registry. Is there any other setting in registry that tolds CLR for DefaultDomain settings like BaseDirectory???? I ask this also as my guess about this problem is that my other assemblies are not in BaseDirectory's folder or in its relative folders so CLR would not find meta data of RemoteClassChecker's meta data when unwraping marshaled RemoteClassLChecker object.
Also note that if i do not cast object reference from AppDomain.CreateInstanceAndUnwrap method then no error occurrred. So i try reflection to invoke methods of RemoteClassChecker but this is also not working
Is it a COMInterop problem? or is it related to cross AppDomain accessing?? or some thing else???
If anyone have a solution for this then please reply. Also if there are some ins and outs of this topic then please give links of those resources.
Thanks in advance.
Regards
Danish Ahmed