shimat / opencvsharp

OpenCV wrapper for .NET
Apache License 2.0
5.22k stars 1.13k forks source link

CLR/System.TypeInitializationException on raspberry pi #1679

Open behroozbc opened 5 days ago

behroozbc commented 5 days ago

Summary of your issue

I got this error on linux-arm64 raspberry pi

Exception has occurred: CLR/System.TypeInitializationException
An exception of type 'System.TypeInitializationException' occurred in OpenCvSharp.dll but was not handled in user code: 'The type initializer for 'OpenCvSharp.Internal.NativeMethods' threw an exception.'
 Inner exceptions found, see $exception in variables window for more details.
 Innermost exception     System.DllNotFoundException : Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: 
/opt/dotnet/shared/Microsoft.NETCore.App/8.0.6/OpenCvSharpExtern.so: cannot open shared object file: No such file or directory
/opt/dotnet/shared/Microsoft.NETCore.App/8.0.6/libOpenCvSharpExtern.so: cannot open shared object file: No such file or directory
/opt/dotnet/shared/Microsoft.NETCore.App/8.0.6/OpenCvSharpExtern: cannot open shared object file: No such file or directory
/opt/dotnet/shared/Microsoft.NETCore.App/8.0.6/libOpenCvSharpExtern: cannot open shared object file: No such file or directory
   at OpenCvSharp.Internal.NativeMethods.redirectError(CvErrorCallback errCallback, IntPtr userdata, IntPtr& prevUserdata)
   at OpenCvSharp.Internal.ExceptionHandler.RegisterExceptionCallback()
   at OpenCvSharp.Internal.NativeMethods.LoadLibraries(IEnumerable`1 additionalPaths)
   at OpenCvSharp.Internal.NativeMethods..cctor()

Environment

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <RootNamespace>resize_files</RootNamespace>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="OpenCvSharp4" Version="4.10.0.20240616" />
    <PackageReference Include="OpenCvSharp4.Extensions" Version="4.10.0.20240616" />
    <PackageReference Include="OpenCvSharp4.runtime.linux-arm" Version="4.10.0.20240616" />
    <PackageReference Include="OpenCvSharp4.runtime.win" Version="4.10.0.20240616" />
  </ItemGroup>

</Project>
.NET SDK:
 Version:           8.0.302
 Commit:            ef14e02af8
 Workload version:  8.0.300-manifests.f6879a9a
 MSBuild version:   17.10.4+10fbfbf2e

Runtime Environment:
 OS Name:     debian
 OS Version:  12
 OS Platform: Linux
 RID:         linux-arm64
 Base Path:   /opt/dotnet/sdk/8.0.302/

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.6
  Architecture: arm64
  Commit:       3b8b000a0e

.NET SDKs installed:
  8.0.302 [/opt/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.6 [/opt/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.6 [/opt/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/opt/dotnet]

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

What did you do when you faced the problem?

Write here

Example code:

using var image = Cv2.ImRead(file.FullName);

Output:

Exception has occurred: CLR/System.TypeInitializationException
An exception of type 'System.TypeInitializationException' occurred in OpenCvSharp.dll but was not handled in user code: 'The type initializer for 'OpenCvSharp.Internal.NativeMethods' threw an exception.'
 Inner exceptions found, see $exception in variables window for more details.
 Innermost exception     System.DllNotFoundException : Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: 
/opt/dotnet/shared/Microsoft.NETCore.App/8.0.6/OpenCvSharpExtern.so: cannot open shared object file: No such file or directory
/opt/dotnet/shared/Microsoft.NETCore.App/8.0.6/libOpenCvSharpExtern.so: cannot open shared object file: No such file or directory
/opt/dotnet/shared/Microsoft.NETCore.App/8.0.6/OpenCvSharpExtern: cannot open shared object file: No such file or directory
/opt/dotnet/shared/Microsoft.NETCore.App/8.0.6/libOpenCvSharpExtern: cannot open shared object file: No such file or directory
   at OpenCvSharp.Internal.NativeMethods.redirectError(CvErrorCallback errCallback, IntPtr userdata, IntPtr& prevUserdata)
   at OpenCvSharp.Internal.ExceptionHandler.RegisterExceptionCallback()
   at OpenCvSharp.Internal.NativeMethods.LoadLibraries(IEnumerable`1 additionalPaths)
   at OpenCvSharp.Internal.NativeMethods..cctor()

What did you intend to be?

read a file

behroozbc commented 1 day ago

I found out the linux-arm64 native file is missing and the arm nuget package does not have it. I think a good solution for this problem is adding a linux-arm64 nuget package.