Project Build Error

February 25, 2007

Error messages always seem to make far more sense when you know the solution.

System.IO.FileNotFoundException was unhandled
  Message=”Could not load file or assembly ‘GISSettings, Version=1.0.0.17923, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.”

This error occurred when building a deployment project in Visual Studio 2005. The GISSettings was a custom made DLL that was referenced by another custom DLL, and it was definitely still there on my machine…

The cause of this was that the second project was looking for a specific version of the GISSettings DLL which no longer existed. I had automated the version numbers for all my DLLs by using the 1.0.0.* syntax for the Assembly Version in the Assembly information of each project. The solution was as follows:

– Show all the files for the project in Visual Studio
– Expand the References
– Check that the Copy Local Property for the relevant DLL is set to true

I had referenced several other custom DLLs which had this property set to true, so why this one had behaved differently I have no idea..VS 2005 does seem to have a few idiosyncrasies, such as when half my projects in a solution disappear, so I guess I’ll have to wait for a few more service packs before I start blaming myself for these issues =)

Advertisement

Posting Code on the Web

February 25, 2007

An important part of the blog will be code snippets. I thought it would be prettier if these snippets had the same nicely coloured syntax as I have in Visual Studio 2005. As will all things computer based things are never easy, and take time. After a good hour or so of messing around I found the following:

i) Copying and pasting to Word or Frontpage will convert the text to HTML (of a fashion..), but spacing and fonts are not retained, and the time spent cleaning up the code is probably equal to manually coding the HTML from scratch.

ii) I found a .NET macro that can be added to Visual Studio at Jeff Atwood’s blog – Coding Horror. This was a useful exercise in seeing how .NET macros could be written and run from Visual Studio, and what is involved in converting the text. Unfortunately when posting in the WordPress code box there were gaps appeared between code lines that had to be deleted manually. For large amounts of code this became somewhat annoying…

iii) The solution! A link from the page at Coding Horror suggested a Visual Studio Add-In created by Colin Coller at his blog Needs Improvement – the latest version can be found here. This Add-In creates a short cut when right clicking on selected code in Visual Studio, with a variety of options such as including code line numbers, and setting indent levels. The HTML can be pasted in WordPress and is displayed perfectly. The only minor problem seems to be if I then run the spell checker some spaces disappear. I’ll just have to be more careful when writing in futur.

Another interesting find, that is not really a requirement for the blog, is this web control. This allows a code text property to be set and when the web page is generated it can be rendered with syntax highlighting from a wide choice of programming languages.

    1     Public Sub VeryHappy()

    2 

    3         Dim LotsOfTimeSaved As Long = 10

    4 

    5         Try

    6             ‘copying and pasting

    7             LotsOfTimeSaved += 10

    8         Catch ex As Exception

    9             ‘not needed =)

   10         Finally

   11             ‘no need to search for another solution!

   12         End Try

   13 

   14     End Sub


Using ArcObjects to get Unique Values from a Table

February 25, 2007

A common requirement in many user dialogs is to display a list of unique values from a table, in order to delete or select records. While it is often easier to use Microsoft’s data objects, I try to use ArcObjects as the relevant libraries will always be installed on a user’s machine. The function will normally part of a larger project and I don’t like mixing the two methods to retrieve values from tables. I usually reuse a custom class for dealing with different types of geodatabases so that if a client changes from Access to SQL Server code changes will be minimal. Keeping up with changes to ESRI’s data access objects and Microsoft’s in the same project could get nasty..

There is a VBA / VB6 sample on how to get unique values at the EDN Site – but no .NET equivalent, hence my code sample below. There are no major changes except now a standard System.Collections enumerator is used rather than the ESRI IEnumVariantSimple.

    Public Sub ListUniqueRecords()

 

        Dim pMyTable As ITable

        Dim pCurs As ICursor = Nothing

        Dim intFieldIdx As Integer

        Dim pDataStatistics As IDataStatistics

        Dim pEnumVar As IEnumerator

        Dim pWorkspaceFactory As IWorkspaceFactory

        Dim pWorkspace As IWorkspace

        Dim pFeatWorkSpace As IFeatureWorkspace

        Dim strMyField As String = “VAL”

 

        Try

            pWorkspaceFactory = New AccessWorkspaceFactory

            pWorkspace = pWorkspaceFactory.OpenFromFile(“C:\MyPath\MyGDB.mdb”, 0)

            pFeatWorkSpace = CType(pWorkspace, IFeatureWorkspace)

            pMyTable = pFeatWorkSpace.OpenTable(“MyTableName”)

            intFieldIdx = pMyTable.FindField(strMyField)

 

            pCurs = pMyTable.Search(Nothing, True)

            pDataStatistics = New DataStatistics

            pDataStatistics.Field = strMyField

            pDataStatistics.Cursor = pCurs

 

            pEnumVar = CType(pDataStatistics.UniqueValues, IEnumerator)

 

            Do Until pEnumVar.MoveNext = False

                Debug.Print(pEnumVar.Current.ToString)

            Loop

 

        Catch ex As Exception

            Trace.WriteLine(ex.ToString)

        Finally

            ‘clean up

            pCurs = Nothing

            pWorkspace = Nothing

        End Try

 

    End Sub


SharpMap

February 20, 2007

I have recently downloaded, and been playing around with an OpenSource map renderer for the .Net 2.0 framework – SharpMap.

The development site can be found at http://www.codeplex.com/SharpMap. The development site is stored in CodePlex which is descriped in Wikipedia as a site website for OpenSource projects hosted by Microsoft providing “wiki pages, source control based on Team Foundation Server, discussion forums, issue tracking, project tagging, RSS support, statistics, and releases. ” This is the first time I have heard of CodePlex, but it is an interesting and well designed concept in itself.

SharpMap itself is very quick to install and comes with a set of demo pages that show some very fancy AJAX zooming, WMS capabilities, and symbology. The code classes themselves seem simple to use, and getting some of your own test data into a sample page was quick and easy. I hope to get a sample site together myself in the coming months, as it seems a very useful way to publish data without having to pay extortionate license fees in order to display geographic data – on a Windows server. In the meantime feast your eyes on this lavish screenshot…

SharpMap Rendering


Windows Installer Woes

February 20, 2007

Finally…all the major bugs have ironed out for a new custom ArcMap tool, a “simple” installer package has been created in Visual Studio and emailed to a colleague for testing. I can now turn off the computer happy in the knowledge that the project is thankfully out of my hands for a few days.

First email the next day..it wouldn’t install, there were errors. Specifically:

“Unable to get installer types in the [name of DLL] assembly. –> Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. “

Well I never  did work out how to retrieve the LoaderExceptions property, but after seemingly recreating and installing in an infinite loop I ascertained the following:

i) The DLL I was installing relied on another custom made DLL that had to be installed on the system to even allow the package to run.

ii) On my development machine the latest DLL had been registered as it was part of the same Visual Studio solution.

iii) On the test machine an older version of the DLL was still being used. I believe this lacked a new class I had since added that was in turn required by the new DLL. This had to be removed, and the latest version of this DLL installed.

iv) Hindsight has 20/20 vision…the new DLL and installer package were deployed without problems.

I believe this error also occurs when trying to install a DLL created on a machine with ArcGIS 9.x, on a machine with ArcGIS 8.x. This would be for the same reasons – a class which the custom DLL relies on has been added/modified/removed.

An invaluable tool in the whole install/uninstall process is the “Windows Installer CleanUp Utility”, downloadable from the Microsoft site at http://support.microsoft.com/kb/290301. This is very useful when the control panel’s Add/Remove Programs interface no longer seems to work.

UPDATE

This error has since made a few reappearances, but this time for a different (albeit) similar reason. After several fruitless hours I decided I would make the effort to “Retrieve the LoaderExceptions property for more information.”

There is a useful program named FUSLOGVW.exe. I found this in C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\ – it had been installed as part of Visual Studio 2005. This progam logs exceptions for “failed Assembly bindsfurther details can be seen on MSDN here.

I set the program to record all application binds for my installation and set the custom log path to the folder where the .DLLs would be installed:

Assembly Binding Log Viewer

Just after the error message popped up I hit refresh and was pleasantly suprised to see the log viewer had filled with entries as shown below.

Assembly Binding Log Viewer

This list included both successful and unsuccessful “binds.” Double clicking on the last entry opened up a browser with further details, including the fact that the “operation” had failed.

Assembly Binding Log Viewer

The (fairly obvious) clue was in the “system cannot find the file specified” when trying to bind to the ESRI.ArcGIS.ADF.DLL. One of my custom tools was trying to call functions in this file, but could not find it. I had excluded all ESRI DLLs from my setup package as I had assumed they would be on any machine with ArcMap…apparently not! By default the .NET support (basically all the ESRI .NET DLLs) are notinstalled. After modifying the ArcGIS installation from the DVD and adding this option the installation ran without further issues =)

.NET Support

A final point on this issue – I would recommend setting all your custom DLL version numbers manually. To check if this is already the case go to Project >> Properties >> Application >> Assembly Information, and make sure there are no asterisks amongst the version numbers.