VB.NET / VS 2022 QUESTION . . .
2024-07-13-105315
All --
I would like to use VB.NET in VISUAL STUDIO 2022 to control IMAGE-PRO 11.
I have started a new VP PROJECT from scratch and I think I have a good start but . . .
The ERROR show below happens whether IP11 is running or not.
The IMAGE FILE is definitely in the the FILE named so I believe that there is an issue with VS2022 connecting with IP11.
Thanks.
-- Matt
0
Answers
You have 2 options to interface with Image-Pro using .NET languages:
- The most common and easiest way is to create an Add-in for Image-Pro, see https://forums.mediacy.com/discussion/comment/2684#Comment_2684 for details. In this case you are extending Image-Pro's capabilities with a dll which can contain additional logic as well as some new panels, ribbon controls, or dialogs for the UI.
- The other option is to use the Automation Server for which you will find documentation in C:\Program Files\Media Cybernetics\Image-Pro 11\Help\Automation Server Help.chm. In that case your application would be using Image-Pro as an image analysis server.
In reference to your posting, it looks like you are missing the add-in plumbing that will give you a valid reference to the application object. You will find some example of that in the discussion mentioned above.It means that the reference DLL cannot be found. The sample project, which Pierre pointed you to, has all reference dlls in X:\ location.
so, please make sure that your X-drive is mapped correctly, as mentioned in the instructions.
I've attached the addin sample project that is created for VS 2022.
Regards,
Yuri
You can also debug your addin directly from Visual Studio setting Startup program as X:\Image-Pro.exe
Yuri
USERPROFILE=C:\Users\mbatc
For Image-Pro 11.1 the line is:
Regards,
Yuri
We need to know precisely which executable to run, hence the specific version. You can get to that using this code:
The sample project is setup to build in the Image-Pro folder, if you want to keep it separate you just need to create an Automation folder in your project output folder and copy the assembly MediaCy.Automation.Server.dll in that folder.
The automation server allows you to remotely run commands in Image-Pro, however it does not give you access to the McApplication object (see the sample project C:\Program Files\Media Cybernetics\Image-Pro 11\Automation\Samples\VB.NET\MediaCy.Automation.Samples.VBClient for details).
If this is what you are looking for then you need to build an add-in as we had originally suggested.
Debug.Print("-- BackgroundWorker1_DoWork -- START --")
'_session = New Session("Image-Pro 10.0 64-bit", 60)
'_session = New Session("Image-Pro 11.1 64-bit", 60)
Try
_session = New Session("Image-Pro 11.1 64-bit", 60)
Catch ex As Exception
Debug.Print("---- Exception Message: " & ex.Message)
Debug.Print("---- Exception Message: " & ex.Message)
Debug.Print("---- Stack Trace: " & ex.StackTrace)
Debug.Print("---- Source: " & ex.Source)
End Try
Debug.Print("-- BackgroundWorker1_DoWork -- END --")
End Sub
'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\Compile Output\MediaCy.Automation.Server.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\assembly\GAC\Extensibility\7.0.3300.0__b03f5f7f11d50a3a\Extensibility.dll'. Module was built without symbols.
'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\SMDiagnostics\v4.0_4.0.0.0__b77a5c561934e089\SMDiagnostics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Internals\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Internals.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
---- Exception Message: Exception has been thrown by the target of an invocation.
---- Exception Message: Exception has been thrown by the target of an invocation.
---- Stack Trace: at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.ServiceModel.Description.TypeLoader.GetKnownTypes(Object[] knownTypeAttributes, ICustomAttributeProvider provider)
at System.ServiceModel.Description.TypeLoader.UpdateOperationsWithInterfaceAttributes(ContractDescription contractDesc, ContractReflectionInfo reflectionInfo)
at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation)
at System.ServiceModel.ChannelFactory`1.CreateDescription()
at System.ServiceModel.ChannelFactory.InitializeEndpoint(Binding binding, EndpointAddress address)
at System.ServiceModel.ChannelFactory`1..ctor(Binding binding, EndpointAddress remoteAddress)
at System.ServiceModel.ChannelFactory`1.CreateChannel(Binding binding, EndpointAddress endpointAddress)
at MediaCy.Automation.Server.Connect(String uri, String exepath, Int32 timeout)
at MediaCy.Automation.Proxy.Session..ctor(String product, Int32 timeout)
at MediaCy.Automation.Samples.VBClient.Form1.BackgroundWorker1_DoWork(Object sender, DoWorkEventArgs e) in C:\Users\mbatc\Desktop\MediaCy.Automation.Samples.VBClient\Form1.vb:line 101
---- Source: mscorlib
-- BackgroundWorker1_DoWork -- END --
-- I resolved this by modifying the HINTPATH for the MEDIACY REFERENCES to
"C:\Program Files\Media Cybernetics\Image-Pro 11\"
See below.
-- I changed the PROJECT COMPILE BUILD OUTPUT PATH from X:\ to
"Compile Output\"
See below.
This was needed by the
"_session = New Session("Image-Pro 11.1 64-bit", 60)"
statement in "BackgroundWorker1_DoWork"
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\Media Cybernetics\Image-Pro 11\MediaCy.Addins.Measurements.dll</HintPath>
</Reference>
<Reference Include="MediaCy.Automation.Proxy">
<HintPath>C:\Program Files\Media Cybernetics\Image-Pro 11\\MediaCy.Automation.Proxy.dll</HintPath>
</Reference>
<Reference Include="MediaCy.Automation.Server">
<HintPath>C:\Program Files\Media Cybernetics\Image-Pro 11\\MediaCy.Automation.Server.dll</HintPath>
</Reference>
<Reference Include="MediaCy.Commands.Features, Version=3.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\Media Cybernetics\Image-Pro 11\MediaCy.Commands.Features.dll</HintPath>
</Reference>
<Reference Include="MediaCy.Commands.Overlays, Version=3.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\Media Cybernetics\Image-Pro 11\MediaCy.Commands.Overlays.dll</HintPath>
</Reference>
<Reference Include="MediaCy.IQL.Application, Version=3.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\Media Cybernetics\Image-Pro 11\MediaCy.IQL.Application.dll</HintPath>
</Reference>
Debug.Print("-- BackgroundWorker1_DoWork -- START --")
'_session = New Session("Image-Pro 10.0 64-bit", 60)
'_session = New Session("Image-Pro 11.1 64-bit", 60)
Try
_session = New Session("Image-Pro 11.1 64-bit", 60)
Catch ex As Exception
Debug.Print("---- Exception Message: " & ex.Message)
Debug.Print("---- Exception Message: " & ex.Message)
Debug.Print("---- Stack Trace: " & ex.StackTrace)
Debug.Print("---- Source: " & ex.Source)
End Try
Debug.Print("-- BackgroundWorker1_DoWork -- END --")
End Sub