Plugin Development

Nov 16, 2015 at 2:23 PM
Hi PM,
Pardon my wrong posting.

I have been able to advance on my Plugin development. I now have the following issues:
Failed to load plugin: MW5.TopoGISPlugin XXXXXXXXX
ComponentActivator: couldnot instantiate MW5,TopoGISPlugin.MenuListener.

My Build Process generate these errors:
1>------ Rebuild All started: Project: MW5.TopoGISPlugin, Configuration: Release x86 ------
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'IShapeDrawingOptions.DrawShape' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'IShapeDrawingOptions.DrawRectangle' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'IShapeDrawingOptions.DrawPoint' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'IShapeDrawingOptions.DrawLine' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'ILinePattern.Draw' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'ILineSegment.Draw' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for '_DMap.DrawBackBuffer' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'ICharts.DrawChart' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'Map.DrawBackBuffer' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'ShapeDrawingOptions.DrawShape' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'ShapeDrawingOptions.DrawRectangle' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'ShapeDrawingOptions.DrawPoint' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'ShapeDrawingOptions.DrawLine' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'Charts.DrawChart' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'LinePattern.Draw' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3305: Processing COM reference "MapWinGIS" from path "C:\dev\MapWindow5\MapWinGIS\MapWinGIS.ocx". At least one of the arguments for 'LineSegment.Draw' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
1>CSC : warning CS1762: A reference was created to embedded interop assembly 'c:\Windows\assembly\GAC\stdole\7.0.3300.0__b03f5f7f11d50a3a\stdole.dll' because of an indirect reference to that assembly created by assembly 'c:\dev\MapWindow5\MW5.Api.dll'. Consider changing the 'Embed Interop Types' property on either assembly.
1>CSC : warning CS1762: A reference was created to embedded interop assembly 'c:\Windows\assembly\GAC\stdole\7.0.3300.0__b03f5f7f11d50a3a\stdole.dll' because of an indirect reference to that assembly created by assembly 'c:\dev\plugins-v5.0.2\MW5.TopoGISPlugin\obj\x86\Release\Interop.MapWinGIS.dll'. Consider changing the 'Embed Interop Types' property on either assembly.
1> MW5.TopoGISPlugin -> C:\dev\MapWindow5\Plugins\MW5.TopoGISPlugin.dll
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Can you please suggest some way forward, which will always be appreciated.

Kehinde Isijola
Nov 17, 2015 at 7:02 AM
Hi Kehinde,

it's difficult for me to be helpful when I don't see your code. Perhaps you can show it via some public repository (a fork here or GitHub for example). That would make things easier. As for the error message it seems that there is an issue with dependency injection (DI). You need to register classes which are injected in constructors with the DI container. In MW5 we have CompositionRoot class in each project to do that. BTW, if you don't feel comfortable with the concept of DI, you can write your code without it, instantiating classes manually, using static classes or any other technique.

Regards,
Sergei
Nov 17, 2015 at 2:45 PM
Grateful for your response.
The process of forking is not too clear to me.
I know I will create a new (named) fork.
Will I just simply paste the code in the description text box? Please explain the process or give me a link that explains the process
Kehinde Isijola
Coordinator
Nov 17, 2015 at 7:52 PM
Hi Kehinde,

The error you're getting is about the MenuListener.
It looks like you removed too much from the template.
Do you still have this line in InitPlugin.Initialize:
_menuListener = context.Container.GetInstance<MenuListener>();
Do you need a menu? If not you can remove all reference to it.
Add a break point in your code and start it with MW5 (see https://mapwindow5.codeplex.com/wikipage?title=Plug-in%20development&referringTitle=Documentation)
If you keep having trouble you can zip your project and mail it to me.
I will have a look.

Regards,
Paul
Nov 19, 2015 at 8:40 PM
Edited Nov 19, 2015 at 8:42 PM
He Paul,
I have checked the code and the problems persist. I have the project in
https://www.dropbox.com/s/i2gxn2ijgott57g/MW5.TopoGISPlugin.zip?dl=0
I use Visual Studio Community 2013.
Your assistance and time will always be highly appreciated.

The plugin is to read a data file prepared by another package and display as shapefile in mapwindow.
I added a table to add the same type of data manually.

Thanks.

Kehinde Isijola
Coordinator
Nov 20, 2015 at 7:51 AM
Hi Kehinde,

I looked at your code and I don't want to offend you but it is really messy.

You added several classes to the MenuListener class file. Because we use dependency injection the container gets confused.
You also reference MapWinGIS directly. You shouldn't do that. Use the MW5.API for that. If you have trouble finding the MW5.API equivalent you can ask here. We'll help you with that. In short: shapefiles are featuresets now:
var fs = new FeatureSet('name and location of your shapefile');
I removed your MenuLister.cs file and replaced it with the one from the template plug-in and now it is working again.
When you move your code to separate classes and files you can call them from the menu without adding all code to the menu class.

Regards,

Paul
Nov 20, 2015 at 10:17 AM
Good day Paul,

Thanks for your response and I want to say that I can not be offended in any way. Serious learner can not be offended. It is from your team that I know anything about dependency injection.
My problem initially is to get MW5.API equivalents. I will rework my code and if there is any problem, I will get in touch.

Thanks again.
Kehinde Isijola
Coordinator
Nov 20, 2015 at 10:30 AM
It might also be useful to just download the source code for MW5. Clone this URL: https://git01.codeplex.com/mapwindow5 using SourceTree.
You might not be able to compile it, but it will help you understand the structure.
Especially the unit tests are helpful.
If cloning is a step too far you can also look at the source code in a browser: https://mapwindow5.codeplex.com/SourceControl/latest#test/MW5.Tools.Test/GeoprocessingTests.cs
Nov 23, 2015 at 12:02 PM
Edited Nov 23, 2015 at 8:08 PM
Hello Paul,

I have looked in the source code, I want to add polygons into my FeatureSet, is my approach correct.
    public List<double> x = new List<double>();
    public List<double> y = new List<double>();
......................
           var fs = new FeatureSet(GeometryType.Polygon);


            var feature = new Geometry(GeometryType.Polygon);

            for (int i = 0; i < x.Count; i++)
            {

                var pnt = new Coordinate(x[i], y[i]);
                feature.Points.Add(pnt);

                }

              fs.Features.EditAdd(feature);
What is the equivalent of (sf = Shapefile object)
               sf.EditCellValue.(plotID, shpIndex, Plot);
in a FeatureSet.

Thanks always.

Kehinde Isijola
Nov 24, 2015 at 5:23 PM
It can be done like this:
int index = fs.Features.EditAdd(geometry);
fs.Features[index].SetValue(fieldIndex, val);
In fact as I see it now, it would better to return IFeature from EditAdd:
var ft = fs.Features.EditAdd(geometry);
ft.SetValue(fieldIndex, val);
I'll commit this change.
Marked as answer by Kehindeoaisijola on 12/4/2015 at 4:46 AM
Dec 4, 2015 at 8:55 PM
Thanks sleschinski, your direction works.

One more challenge,
My layer does not show name. The name is blank and I can not figure out the method or function to use.
Kindly assist.
Kehinde Isijola
Coordinator
Dec 5, 2015 at 9:19 AM
How are you adding your layer? Can you show some code?
Dec 5, 2015 at 8:09 PM
Thanks for your time. I have these code lines
            PointIDFeatureSet.SaveAs(PointIDLayerFile);
            int layerHandle = _context.Map.Layers.Add(PointIDFeatureSet);
            _context.Map.Redraw();
The layers appear in the legend panel but without name.

Thanks.

Kehinde Isijola
Dec 8, 2015 at 3:38 AM
I have been able to solve the problem by changing the name property as follows:
            _context.Legend.Layers.Current.Name = PointIDLayerFile;
Unless there is a better approach.

Thank you.

Kehinde Isijola