Exception in Analyze.solve

Hi,

I’m working on a project that analyse a bridge configuration using Karamba 3.1.41125. It worked without problem for a while but now I get this exception:

SEHException: External component has thrown an exception.

The error is similar to this post:

In my case, the exception always occurs. The only way to fix it is to comment out the analysis function in the C# component, output only the assembled Karamba model, and then perform the analysis using the Analyze component (which always works). Once the analysis is complete, I can uncomment the analysis function in the C# component. After this, the exception no longer appears until I reopen Rhino.

Here is the code snippet that generate the error:

    public static void AnalyseOneBridge(BridgeUniqueConfiguration oneBRG, List<double> posToRetrieve, bool retrieveForces, bool retrieveDisplacements, int stepReductionFactor, List<MovingLoadCase> movingLCListToUse, out List<Model> modelsOut)
    {

        // CREATE THE STEEL AND CONCRETE MATERIALS

        // CREATE COMMON ELEMENTS

        // CREATE MODEL ELEMENTS
        var modelS = AssembleModelFactory.CreateModel_S(oneBRG, materials, supports, intDiaphElements, intDiaphRlElements);
        var modelS1n = AssembleModelFactory.CreateModel_S1n(oneBRG, materials, supports, intDiaphElements, intDiaphRlElements, stepReductionFactor, movingLCListToUse);
        var modelS3n = AssembleModelFactory.CreateModel_S3n(oneBRG, materials, supports, intDiaphElements, intDiaphRlElements, stepReductionFactor, movingLCListToUse);

        // ANALYSE THE MODELS
        List<Model> models = new()
        {
        RunAnalysis(modelS),
        RunAnalysis(modelS1n),
        RunAnalysis(modelS3n)
        };

        // RETRIEVE RESULTS FOR THE GIRDERS
        oneBRG.AllResults.LoadCasesResultsList.Clear();
        RetrieveGirdersResults(oneBRG, models, posToRetrieve, retrieveForces, retrieveDisplacements);

        modelsOut = models;
    }

    public static Model RunAnalysis(Model model)
    {
        List<string> LCList = model.lcCombinationCollection.OrderedLoadCaseCombinations.Select<LoadCaseCombination, string>((Func<LoadCaseCombination, string>) (i => ((LoadComponent) i).Name)).ToList<string>();
        Analyze.solve(model,LCList,out _,out _,out _,out Model AnalysedModel,out string warning);  //<--- Error there
        return AnalysedModel;
    }

I’m using a custom .dll to generate the bridge configuration, so it’s challenging for me to create a simplified version that reproduces the same issue.

Hi @Maxime8,
do you use RH7 or RH8?
I tried to recreate the error under RH7 with this script:
Beam_Cantilever_SEHException_Test.gh (24.6 KB) where I used the analysis-part of your code. However, in my case it works. Could you please try it out and tell me the result in your case?

The Analyze component in Karamba3D does not do more than your RunAnalysis-method. So it is surprising that they behave differently. One thing you could check is whether your script references the same KarambaCommon.dll as Grasshopper. When for example one installs Karamba3D via msi-installer and package manager there will be duplicate versions of Karamba3D. What you could try is to uninstall Karamba3D, check whether the installation folder is completely gone and then reeinstall it.
– Clemens

Hi Clemens,

I use RH8 (forgot to mention that).

The file you provided works for me until the “Step” slider reaches 21. After that, I get this error:

External component has thrown an exception. (line: 0)

I completely deleted Karamba and reinstalled it using the PackageManager to be safe, but I still get the same problem. I thought that maybe my DLL wasn’t referencing the same KarambaCommon as you mentioned. However, my Visual Studio project has the following assembly references:

<Reference Include="Karamba">
  <HintPath>C:\Users\AppData\Roaming\McNeel\Rhinoceros\packages\8.0\Karamba3D\3.1.41125\net7.0-windows\Karamba.gha</HintPath>
  <Private>False</Private>
</Reference>
<Reference Include="KarambaCommon">
  <HintPath>..\..\..\..\..\AppData\Roaming\McNeel\Rhinoceros\packages\8.0\Karamba3D\3.1.41125\net7.0-windows\KarambaCommon.dll</HintPath>
</Reference>

while my C# component use this:

#r “Karamba.gha”
#r “karambaCommon.dll”

I am not sure if the C# component use the “net7.0-windows” or the “net48” or if it have an impact on my problem.

Thank you for your time,
-Maxime

Hi @Maxime8,
I think I found the bug. When implementing async execution of the Analysis-component I moved the license check out of the Analyze.solve()-method which causes now the problem - sorry.

In the next service release of Karamba3D the license checks will be back where they were. As a workaround for the meantime add these lines of code before calling Analyze.solve():

string errorMessage;
if (!License.license_is_valid(model, out errorMessage))
{
throw new Exception(errorMessage);
}

See also here:
241211_1_Beam_Cantilever_SEHException_Test.gh (20.3 KB)

Sorry for the inconvenience and thank you very much for the bug report!

– Clemens

1 Like

Hi Clemens,

Your code resolved my problem, thank you!