Error trying to import metadata using MetadataImporter_conversion

5024
3
10-11-2012 03:45 PM
MatthewGerbrandt
New Contributor II
I'm trying to write a script for updating the metadata in a geodatabase by importing XML files. What the script does is to loop through a geodatabase and collect the names of every feature class. Then, it looks for an XML file whose name is equal to the name of the feature class + ".xml".

Unfortnately, I'm getting the following error and I don't know what it means "Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly GpMetadataFunctions".

The XML file is in the same directory that houses the GDB and the python script. My script and the full error are as follows. Any help would be tremendously appreciated.

import arcgisscripting, arcpy, os, sys
from arcpy import env
from arcpy import mapping

gp = arcgisscripting.create(9.3) 

# Set the current workspace by passing the name of the geodatabase
# for example: python ImportMetadata2.py HomeViewGeoPlatfrom.gdb
gdb = sys.argv[1]

folder = gdb
env.workspace = folder

# The following file will serve as a list of what we've done and will provide links for pasting into the config file
LogFile = open(folder.replace('.gdb','')+'LogFile.csv', 'w')
LogFile.write("FeatureClass,XMLFileNameGuess,Results" + "\n")

def listFcsInGDB(gdb): 
    ''' list all Feature Classes in a geodatabase, including inside Feature Datasets ''' 
    gp.workspace = gdb 
    print 'Processing ', gp.workspace 

    # create an array that contains the names of all of the FeatureClasses in the geodatabase
    # this info will be used for making a list of XML files with similar names
    fcs = [] 
    for fds in gp.ListDatasets('','feature') + ['']: 
        for fc in gp.ListFeatureClasses('','',fds):
            # If you want to include the name of the FeatureDataset in the XML file name, use this line
            # fcs.append(os.path.join(fds, fc))

            # The following line does not include the FeatureDataset name in the XML file name
            fcs.append(os.path.join(fc))
    return fcs 
 
fcs = listFcsInGDB(gdb) 
for fc in fcs: 
    print fc    

    #  the field name, type, and length.
    layer = fc
    
    # Phase to add in between Popup and Layer Name.xml
    LookForThisXMLFile = layer.replace("\\","_") + ".xml"
    
    try:
        arcpy.MetadataImporter_conversion (LookForThisXMLFile,fc)
        LogFile.write(layer + "," + LookForThisXMLFile + "," + "Success" + "\n")
    except Exception, e:
        LogFile.write(layer + "," + LookForThisXMLFile + "," + e + "\n")
        continue


LogFile.close()



C:\Data\GISData\>python ImportMetadata2.py Test.gdb
Processing  Test.gdb
CD_112th

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'GpMetadataFunctions, Version=10.1.0.0, Culture=neutral, PublicKeyToken=8f
c3cc631e44ad86' or one of its dependencies. The system cannot find the file specified.
File name: 'GpMetadataFunctions, Version=10.1.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86'
   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boo
lean throwOnFileNotFound, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence
 assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence as
semblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.Load(String assemblyString) at GetManagedType(Char* _assembly, Char* _path, Char* _className)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Tags (2)
0 Kudos
3 Replies
MatthewGerbrandt
New Contributor II
As it turns out, the script works great. I had to copy GpMetadataFunctions.dll and MetadataTranslator.dll to the Global Assembly Cache (GAC) directory.

If you have this problem, you may need to open up a command-line windows as Administrator and copy the files that way.
ZuoqiChen
New Contributor
As it turns out, the script works great. I had to copy GpMetadataFunctions.dll and MetadataTranslator.dll to the Global Assembly Cache (GAC) directory.

If you have this problem, you may need to open up a command-line windows as Administrator and copy the files that way.


can u tell me what is GAC directory and how to get the GpMetadataFunctions.dll and MetadataTranslator.dll?
0 Kudos
PaulDavidson1
Occasional Contributor III
Google gacutil for info on adding dlls to the GAC.
gacutil comes with Visual Studio and probably available other places.

gacutil /i "filepath\filename"
is the basic command. 
for example:
gacutil /i "C:\Program Files (x86)\ArcGIS\Desktop10.0\Bin\GpMetadataFunctions.dll"
will install GpMetadataFunctions.dll

However, in my case, ArcGIS 10.0.0 SP4, I'm still not able to read metadata and I'm not sure why.
One thing of note is that most of the ESRI dlls in the GAC are referenced with more info,
ESRI.ArcGIS.Geoprocessor, Version=10.0.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86, processorArchitecture=x86
where as my GpMetadata... looks like:
  GpMetadataFunctions, Version=10.0.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86, processorArchitecture=x86

which makes me wonder...
One thing is certain, Esri has really made metadata complicated with 10.x
I have spent days importing, exporting, playing with xml, xlst, python, etc... and it really makes very little sense.
I import and export and things like GeoProcessing History stay there in the file but are never exported.