Search code examples
c#dllgrasshopperaleagpurhino3d

Alea Gpu runtime error not finding a file or dependecy in a Rhino/GrassHopper project


I have a runtime problem with Alea Gpu which doesn't find all related files (dll's I guess). Being new to .NET I have a problem figuring out the correct paths when it doesn't work out of the box, so if anyone can give me some hints based on the paths I present below, it would be gold.

Background

I installed the Alea Gpu packages for VS2017 using Nuget, and my project code compiles and creates the desired GrassHopper component for Rhino3d. This component also shows up properly in RT, but fails with the following error message when entering the the "solver" method containing Alea Gpu calls.

Error message

The error message (my translation from Swedish):

"1. Solution exception:Cannot find the File or the Assembly Alea, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ba52afc3c2e933d6 or one of its dependencies. Cannot find the file."

Perhaps not the most relevant, but here's the failing component with the error message (in Swedish):

http://misc.rilsource.org/w/images/misc.rilsource.org/Alea_Gpu_GH_Component_Debug_error_00.png

The calling .dll (.gha)

The code that runs this so called "GrassHopper definition" (a .gha file which essentially is a .dll) is located in the following folder structure in a VS project where also the Alea package structure is Shown.

The calling GrassHopper (.gha) file:

C:\Workbench\VS\RILGH_Development\RILGH_CSUtils\RILGH_CSUtils\bin\x64\Debug\RILGH_CSUtils.gha

VS Project folder structure

Alea.targets

The content of the file "...\packages\Alea.3.0.3\Alea.targets is as follows :

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AleaPackageDir Condition="$(AleaPackageDir) == '' Or $(AleaPackageDir) == '*Undefined*'">$(MSBuildThisFileDirectory)..\</AleaPackageDir>
    <AleaResourceDir Condition="$(AleaResourceDir) == '' Or $(AleaResourceDir) == '*Undefined*'">$(OutputPath)</AleaResourceDir>
    <AleaDoExtractCTResources Condition="$(AleaDoExtractCTResources) == '' Or $(AleaDoExtractCTResources) == '*Undefined*'">true</AleaDoExtractCTResources>
  </PropertyGroup>
  <UsingTask
    TaskName="Alea.Build.ExtractCTResourcesTask"
    AssemblyFile="$(AleaPackageDir)tools\Alea.Build.dll"/>
  <Target AfterTargets="AfterBuild" Name="AleaExtractCTResources" Condition="$(AleaDoExtractCTResources) == 'true' Or $(AleaDoExtractCTResources) == 'True'">
    <Alea.Build.ExtractCTResourcesTask
      ResourceAssemblyDir="$(AleaPackageDir)tools\"
      ResourceDir="$(AleaResourceDir)" />
  </Target>
  <Target AfterTargets="AfterClean" Name="AleaCUDACleanCTResources">
    <RemoveDir Directories="$(AleaResourceDir)\Alea.CUDA.CT.LibDevice"/>
    <RemoveDir Directories="$(AleaResourceDir)\Alea.CUDA.CT.Native.ARM.B32.Linux"/>
    <RemoveDir Directories="$(AleaResourceDir)\Alea.CUDA.CT.Native.X86.B32.MacOSX"/>
    <RemoveDir Directories="$(AleaResourceDir)\Alea.CUDA.CT.Native.X86.B32.Windows"/>
    <RemoveDir Directories="$(AleaResourceDir)\Alea.CUDA.CT.Native.X86.B64.Linux"/>
    <RemoveDir Directories="$(AleaResourceDir)\Alea.CUDA.CT.Native.X86.B64.MacOSX"/>
    <RemoveDir Directories="$(AleaResourceDir)\Alea.CUDA.CT.Native.X86.B64.Windows"/>
  </Target>
</Project>

.csproj settings

<ItemGroup>
    <Reference Include="Alea, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ba52afc3c2e933d6, processorArchitecture=MSIL">
      <HintPath>..\packages\Alea.3.0.3\lib\net45\Alea.dll</HintPath>
    </Reference>
    <Reference Include="Alea.IL, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ba52afc3c2e933d6, processorArchitecture=MSIL">
      <HintPath>..\packages\Alea.3.0.3\lib\net45\Alea.IL.dll</HintPath>
    </Reference>
    <Reference Include="Alea.Parallel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ba52afc3c2e933d6, processorArchitecture=MSIL">
      <HintPath>..\packages\Alea.3.0.3\lib\net45\Alea.Parallel.dll</HintPath>
    </Reference>
    <Reference Include="nunit.framework, Version=3.7.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
      <HintPath>..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="RhinoCommon">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>C:\Program Files\Rhinoceros 5 (64-bit)\System\RhinoCommon.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="Grasshopper">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>C:\Program Files\Common Files\McNeel\Rhinoceros\5.0\Plug-ins\Grasshopper (b45a29b1-4343-4035-989e-044e8580d9cf)\0.9.76.0\Grasshopper.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="GH_IO">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>C:\Program Files\Common Files\McNeel\Rhinoceros\5.0\Plug-ins\Grasshopper (b45a29b1-4343-4035-989e-044e8580d9cf)\0.9.76.0\GH_IO.dll</HintPath>
      <Private>False</Private>
    </Reference>
  </ItemGroup>

... last rows in .csproj :

  <Import Project="..\packages\Alea.3.0.3\build\Alea.targets" Condition="Exists('..\packages\Alea.3.0.3\build\Alea.targets')" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\packages\Alea.3.0.3\build\Alea.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Alea.3.0.3\build\Alea.targets'))" />
    <Error Condition="!Exists('..\packages\Fody.1.29.4\build\dotnet\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.1.29.4\build\dotnet\Fody.targets'))" />
  </Target>
  <Import Project="..\packages\Fody.1.29.4\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.1.29.4\build\dotnet\Fody.targets')" />

Hopefully this is enough info about paths and where to make any modifications so that the runtime files can be found, given the path to the individual calling GrassHopper file ("C:\Workbench\VS\RILGH_Development\RILGH_CSUtils\RILGH_CSUtils\bin\x64\Debug\RILGH_CSUtils.gha") and the general paths where the GrassHopper execution platform searches for related component dll's (a path which Alea seemingly doesn't care much about), "C:\Program Files\Common Files\McNeel\Rhinoceros\5.0\Plug-ins\Grasshopper (b45a29b1-4343-4035-989e-044e8580d9cf)\0.9.76.0\Components\". I have told GrassHopper to search in both these directories, and even tried dropping copies of the Alea dll's in this (the last) folder, but no go.

Q: So how does package library like Alea actually control the paths it uses in runtime based on the files and path (se above) which I can control?

Reading through the posts tagged aleagpu was not helpful to me, nor the sparse troubleshooting info on the alea documentation pages (possibly due to being newbie with .Net and VS)

Thanks in advance.

// Rolf


Solution

  • It seems that this is an old unsolved problem in Grasshopper.

    Anyway, I probably have a solution for that, at least it worked for me.

    From this discussion: http://www.grasshopper3d.com/forum/topics/how-do-i-install-a-custom-ghx?id=2985220%3ATopic%3A168876&page=2#comments

    To summarize, to solve the issue:

    1. Copy the Alea.dll file to thisdirectory C:\Program Files\Rhinoceros 5 (64-bit)\System\

    2. In Rhino type the command GrasshopperDeveloperSettings and uncheck the option: Memory load *.GHA assemblies using COFF byte arrays

    It could probably work even without launching Rhino as Admin and with the COFF box checked, but i haven't tried yet.