HRESULT E_FAIL has been returned from a call to a com component

4981
20
09-17-2010 05:17 AM
NagmaYasmin
Occasional Contributor III
Hi,

I started to get HRESULT error when trying to solve network dataset in Arc10 programatically. In 9.3, the code works fine. It is in vb.net. In program i added code to release object and garbage collector, but nothing helps.

Any idea? Appreciate any help.


Nagma
Tags (2)
0 Kudos
20 Replies
MichaelRice
New Contributor III
What is happening in the SetSolverSettings function? Are you calling UpdateContext after changing your solver settings (I don't see any calls to this in your document)? If not, you certainly should be. If you are indeed calling this before calling solve, then I would ask for you to package up your code and maybe a small sample dataset and send it to me to look at. You may reach me at mrice@esri.com. If you would rather track this through official channels, then sending this issue to ESRI Technical Support would work as well (and you may be able to get a faster response, as I don't know exactly when I would be able to look into this in further detail [although I will certainly try]).
0 Kudos
NagmaYasmin
Occasional Contributor III
Setsolversettings function adds impedance attribute, restrictions, best order. Attached is the SetSolverSettings function. I called updatecontext after calling SetSolversettings, still the same error. The program is pretty big and it is an extension of desktop called Smartr. I will email it to you with data and as well as to esri tech support. Again thanks.
0 Kudos
PatrickStevens
Esri Contributor
Hello, Nagma!

I'll help Michael look through the code once he gets it from you in email.  In the meantime, could you try something else, as well?  Before you do the solve, save out the layer as a layer file.  It's often easier to see a problem with a layer file in Desktop.

Please add this code just before solve:

  Dim naLayer As INALayer3 = TryCast(m_pNAContext.Solver.CreateLayer(m_pNAContext), INALayer3)
  Dim layerfile As ILayerFile = New LayerFileClass()
  layerfile.[New]("c:\temp\MyLayer.lyr")
  layerfile.ReplaceContents(TryCast(naLayer, ILayer))
  layerfile.Save()
  layerfile.Close()

Could you send along that layer file as well?  Also, what network dataset are you using? 

Thanks!
0 Kudos
NagmaYasmin
Occasional Contributor III
Thanks Michael and Steven. I will send you the data, layer file, .net project and also instruction via email. The network dataset we are using is from our customers. Appreciate your help.
0 Kudos
PatrickStevens
Esri Contributor
Nagma,

Thanks for sending along your data and code.  The layer file you sent solves fine when loaded into ArcMap.  This means that we need to look further into the code to try and find the problem.

As for the error you get when you access the GPMessages, currently your code is this:

   MsgBox("Solve failed " & pGPMessages.Messages.Element(0))

To avoid the exception you are getting, you could try to loop through the GPMessages:

  Dim messageCount As Integer = pGPMessages.Count()
  If (messageCount <> 0) Then
    Dim gpMessageIndex As Integer
    Dim stringBuilder As StringBuilder = New StringBuilder()
    For gpMessageIndex = 0 To messageCount - 1
      stringBuilder.Append("GPMessage[" + gpMessageIndex + "]: " + pGPMessages.GetMessage(gpMessageIndex).Description).AppendLine()
    Next
      MsgBox("Solve failed." + stringBuilder.ToString())
  Else
    MsgBox("Solve failed without any GPMessages")
  End If


Sorry if there are any typos in there. I'm a C# developer most of the time.
0 Kudos
PatrickStevens
Esri Contributor
Already found a typo.  The line:

For gpMessageIndex = 0 To messageCount

Should be:

For gpMessageIndex = 0 To messageCount - 1
0 Kudos
NagmaYasmin
Occasional Contributor III
Steven/Michael,

I added the code and tested with the dataset I sent to you. The message I am getting is that - "Solve required two valid stops". I tested with another dataset, I got message " Solve failed without any GPmessages". But none of them could be solved.
One more thing, the layer file I sent it to you, I could see only couple of stops, there is no route with that.
Let me know your thoughts.

Thanks
0 Kudos
MichaelRice
New Contributor III
I added the code and tested with the dataset I sent to you. The message I am getting is that - "Solve required two valid stops".


Okay, now we are getting somewhere. This means that there is something wrong with one or more of your stops. Either you didn't load in more than one stop, or one of your stops is unlocated or perhaps located on a restricted element (depending on the restrictions you are applying). Is this the exact error message you are getting? I do not think we have an error message in our system that is worded exactly as you have written, but we do have one that is similar: "Need at least 2 valid stops". Can you please verify your exact error message for this case? Also, you should take a look into the data you are loading into your stops and make sure they have valid field values after loading. If they do, and there is more than one stop being loaded, then turn off your restrictions to see if this is what was invalidating some of your stops. If that is the case, then at 10.0, you have the option to avoid locating on restricted elements, which could help. Let me know what you find, and we can proceed from there.

I tested with another dataset, I got message " Solve failed without any GPmessages".


I assume that you placed Patrick's suggested code in the "catch" part of the try/catch block, correct? Otherwise, if the solve is successful, and there are no GPMessages, then executing Patrick's code outside of the catch block would indeed say "Solve failed without any GPmessages". If this is actually within the catch block, then the solve did throw an error, but did not enter any GPMessages. Try checking the message associated with the actual exception being thrown/caught (this is not in the GPMessages object). Below is some sample VB.NET code for catching and reporting an exception's message:

 ' Give user information about an exception.  
 Try  
     ' We will purposely create a File Exception for the  
     ' purpose of this example. We will be invoking the exception  
     ' by providing a path of an illegal form.  
     Dim fileContents As String = System.IO.File.ReadAllText("iShouldn'tWork :)")  
 Catch ex As Exception  
     ' ex.ToString will give the user a large technical dump.  
     MessageBox.Show("ToString: " & ex.ToString)  
     ' ex.Message will give the user a brief, more user friendly error message.  
     MessageBox.Show("Message: " & ex.Message)  
 End Try 

If you changed datasets, but did not change your solver settings (e.g., impedance name, restriction names, accumulate attribute names, etc.), then these settings may not match appropriately with the attributes available in your other dataset. This may explain this particular error. Please investigate further (as best you can) and let me know.
0 Kudos
NagmaYasmin
Occasional Contributor III
Hi Michael,

Sorry for late reply. You are right. The error message is like that "Solve failed. Need at least two valid stops". I was trying to find out why it gives me that error for invalid stops, even it has valid stops loaded. I also added the exception.

The steps I followed:

The progam added a layer in the map with all stops even it couldn't create a route. but it gives me the exception (pls. see the first 2 screenshotof attached document). I tried to solve it right clicking the run from the map and it creates route without any error. Then again I tried to rebuild that route using the program it gives me the message "Solve failed. Need at least two valid stops" . I am not sure whether it makes any sense to you.

It happens to other dataset too. Thanks
0 Kudos
MichaelRice
New Contributor III
Okay, well I can't be sure, but we seem to have at least identified that the problem (at least for part of what you discussed above) appears to be with one or more of your input stops. There could be several possibilities here:

  1. If you are giving each stop a RouteName field value, then it could be that these field values are not identical. If you are trying to assign them to an explicit RouteName, please look at these field values in your loaded layer and make sure these are consistent.

  2. If you are assigning time windows to some of your stops, please make sure that these values are valid. For example, the time window start cannot be after your time window end.

  3. Your location field values are incorrect for one or more of your stops.


How are you loading your stops into your layer file before you see this error? If none of these suggestions help, and you are unable to see any potential issues with your stops' field values when you see this error message, then I would advise you to go through ESRI Technical Support, so that we can better track down this problem.
0 Kudos