how to create a VTK.Net View?

Topics: CAB & Smart Client Software Factory
Apr 7, 2013 at 10:53 PM
Hello,

First of all, I would like to state that I am a newbie using CAB and Smart Client Software Factory.

I am trying to embeded VTK.Net into a view. But I dont know why. I get an ModuleLoadException.

I dont know what I am doing wrong.

Could anyone help me?

thanks in advance.

The Error Exception that I get

Microsoft.Practices.CompositeUI.Services.ModuleLoadException was unhandled
  Message="Failed to load module from assembly 7f405271-9377-4d9c-9ed7-141f6b216a13. Error was:\r\nFailed to load module from assembly Module2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. Error was:\r\nException has been thrown by the target of an invocation."
  Source="Infrastructure.Library"
  StackTrace:
       at SCFSTest.Infrastructure.Library.Services.DependentModuleLoaderService.ModuleMetadata.ThrowModuleLoadException(Exception innerException) in D:\Projects\Visual Studio 2008\SCFSTest\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:line 434
       at SCFSTest.Infrastructure.Library.Services.DependentModuleLoaderService.ModuleMetadata.InitializeModuleClasses(WorkItem workItem) in D:\Projects\Visual Studio 2008\SCFSTest\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:line 396
       at SCFSTest.Infrastructure.Library.Services.DependentModuleLoaderService.InnerLoad(WorkItem workItem, IModuleInfo[] modules) in D:\Projects\Visual Studio 2008\SCFSTest\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:line 124
       at SCFSTest.Infrastructure.Library.Services.DependentModuleLoaderService.Load(WorkItem workItem, IModuleInfo[] modules) in D:\Projects\Visual Studio 2008\SCFSTest\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:line 79
       at Microsoft.Practices.CompositeUI.CabApplication`1.LoadModules()
       at Microsoft.Practices.CompositeUI.CabApplication`1.Run()
       at SCFSTest.Infrastructure.Shell.ShellApplication.RunInDebugMode() in D:\Projects\Visual Studio 2008\SCFSTest\Source\Infrastructure\Shell\ShellApplication.cs:line 56
       at SCFSTest.Infrastructure.Shell.ShellApplication.Main() in D:\Projects\Visual Studio 2008\SCFSTest\Source\Infrastructure\Shell\ShellApplication.cs:line 47
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Reflection.TargetInvocationException
       Message="Exception has been thrown by the target of an invocation."
       Source="mscorlib"
       StackTrace:
            at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
            at System.Reflection.RuntimeConstructorInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
            at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
            at Microsoft.Practices.ObjectBuilder.CreationStrategy.InitializeObject(IBuilderContext context, Object existing, String id, ICreationPolicy policy)
            at Microsoft.Practices.ObjectBuilder.CreationStrategy.BuildUpNewObject(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.CreationStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.ReflectionStrategy`1.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
            at Microsoft.Practices.ObjectBuilder.TypeMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
            at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
            at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
            at Microsoft.Practices.CompositeUI.Collections.ManagedObjectCollection`1.BuildFirstTimeItem(Type typeToBuild, String idToBuild, Object item)
            at Microsoft.Practices.CompositeUI.Collections.ManagedObjectCollection`1.Build(Type typeToBuild, String idToBuild, Object item)
            at Microsoft.Practices.CompositeUI.Collections.ManagedObjectCollection`1.AddNew(Type typeToBuild, String id)
            at Microsoft.Practices.CompositeUI.Collections.ManagedObjectCollection`1.AddNew[TTypeToBuild]()
            at SCFSTest.Module2.ModuleController.AddViews() in D:\Projects\Visual Studio 2008\SCFSTest\Module2\Module2\ModuleController.cs:line 65
            at SCFSTest.Module2.ModuleController.Run() in D:\Projects\Visual Studio 2008\SCFSTest\Module2\Module2\ModuleController.cs:line 31
            at SCFSTest.Module2.Module.Load() in D:\Projects\Visual Studio 2008\SCFSTest\Module2\Module2\Module.cs:line 36
            at SCFSTest.Infrastructure.Library.Services.DependentModuleLoaderService.ModuleMetadata.InitializeModuleClasses(WorkItem workItem) in D:\Projects\Visual Studio 2008\SCFSTest\Source\Infrastructure\Infrastructure.Library\Services\DependentModuleLoaderService.cs:line 389
       InnerException: System.BadImageFormatException
            Message="Could not load file or assembly 'Kitware.VTK, Version=5.8.0.607, Culture=neutral, PublicKeyToken=995c7fb9db2c1b44' or one of its dependencies. An attempt was made to load a program with an incorrect format."
            Source="Module2"
            FileName="Kitware.VTK, Version=5.8.0.607, Culture=neutral, PublicKeyToken=995c7fb9db2c1b44"
            FusionLog="=== Pre-bind state information ===\r\nLOG: User = aisha\\ting\r\nLOG: DisplayName = Kitware.VTK, Version=5.8.0.607, Culture=neutral, PublicKeyToken=995c7fb9db2c1b44\n (Fully-specified)\r\nLOG: Appbase = file:///D:/Projects/Visual Studio 2008/SCFSTest/bin/Debug/\r\nLOG: Initial PrivatePath = NULL\r\nCalling assembly : Module2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.\r\n===\r\nLOG: This bind starts in default load context.\r\nLOG: Using application configuration file: D:\\Projects\\Visual Studio 2008\\SCFSTest\\bin\\Debug\\Shell.vshost.exe.Config\r\nLOG: Using machine configuration file from C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\config\\machine.config.\r\nLOG: Post-policy reference: Kitware.VTK, Version=5.8.0.607, Culture=neutral, PublicKeyToken=995c7fb9db2c1b44\r\nLOG: Attempting download of new URL file:///D:/Projects/Visual Studio 2008/SCFSTest/bin/Debug/Kitware.VTK.DLL.\r\nERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.\r\n"
            StackTrace:
                 at SCFSTest.Module2.View1.InitializeComponent()
                 at SCFSTest.Module2.View1..ctor() in D:\Projects\Visual Studio 2008\SCFSTest\Module2\Module2\Views\View1.cs:line 30
            InnerException: 
Apr 8, 2013 at 7:42 PM
Hi,

Looking at the exception, it seems that the key behind the problem is the following one:
 InnerException: System.BadImageFormatException
        Message="Could not load file or assembly 'Kitware.VTK, Version=5.8.0.607, Culture=neutral, PublicKeyToken=995c7fb9db2c1b44' or one of its dependencies.  
        An attempt was made to load a program with an incorrect format ."
        Source="Module2"
        FileName="Kitware.VTK, Version=5.8.0.607, Culture=neutral, PublicKeyToken=995c7fb9db2c1b44"
Based on my understanding, the " An attempt was made to load a program with an incorrect format " message appears when trying to load a corrupted dll or an unmanaged non-COM 32-bits dll inside a .NET application built for 64-bits architectures. As a starting point, please check that your build configurations a targeted to x86.

Also, I am not familiar with the Visualization Tooltik (VTK) but I believe the following library could be useful to develop .NET applications with it (in case you are not using it already):
Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini
Apr 17, 2013 at 12:34 AM
Hi Damian,

It was as you said. I set my project to target a x84 platform and It works perfect.

Thank you very much