Pythonnet stackoverflow exception in Python.Runtime.dll when calling Py.Import - c#

I'm using python 3.5 installed in a virtual conda environment. The stackoverflow happens during a call to Py.Import:
dynamic np = Py.Import("numpy");
This was once working on my machine, but I decided to reinstall my Python environment. I set PythonEngine.PythonPath to the location of my virtual environment. My root Python install is also version 3.5. If I uninstall numpy, Py.Import fails expectedly due to the module not being found. If I reinstall numpy, I get a stackoverflow:
An unhandled exception of type 'System.StackOverflowException'
occurred in Python.Runtime.dll
Worker Thread Python.Runtime.dll!Python.Runtime.ImportHook.import Normal
[External Code]
The maximum number of stack frames supported by Visual Studio has been exceeded.
Importing built-in python modules works. I tried importing one of my own modules with a print statement at the first line, and the print statement gets called twice, so something is fishy. Any ideas why the stackoverflow exception is occurring?
Python 3.5.3
64-bit
numpy 1.13.1
VS2015
Pythonnet 2.30-py35-dotnet

Related

Unable to load libgdiplus in Signal R web application with web sockets (Mac OS)

I downloaded this repository from GitHub and try to run it on my MacOS laptop. It uses Signal R and web sockets.
It builds, it starts, it works
But when I try to open web socket I get an error:
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
---> System.DllNotFoundException: Unable to load shared library 'libgdiplus' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibgdiplus, 0x0001): tried: 'liblibgdiplus' (no such file), '/System/Volumes/Preboot/Cryptexes/OSliblibgdiplus' (no such file), '/usr/lib/liblibgdiplus' (no such file, not in dyld cache), 'liblibgdiplus' (no such file), '/usr/local/lib/liblibgdiplus' (no such file), '/usr/lib/liblibgdiplus' (no such file, not in dyld cache)
at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
at System.Drawing.SafeNativeMethods.Gdip..cctor()
--- End of inner exception stack trace ---
I did brew install mono-libgdiplus but it didn't help.
I'm new to C# and Microsoft frameworks so what else can I do? (MacOS Ventura, Apple M1)
Solved: System.Drawing is not supported on my MacOS, so the peaces of code where this library is using should not be executed.
While the project you played with was very well designed for cross platform, it was unfortunately developed before .NET 6 introduced an important breaking change, that System.Drawing related API is only supported on Windows.
Like you found out, commenting out the lines related to System.Drawing works. But if you want similar functionalities, you will have to rewrite that part with another drawing library. There are many such options out there if search engines are used.

The type initializer for 'Sap.Data.Hana.HanaConnection' threw an exception. ---> System.IO.FileNotFoundException: Cannot find libADONETHDB.dll

I have a problem only on a specific machine.
I have two programs with a reference to Sap.Data.Hana.v4.5.dll, the ADO.NET Provider for .NET 4.5 for HANA database.
When my programs instantiates a connection object with
dbConnection = new HanaConnection(...);
I get this error:
System.TypeInitializationException: The type initializer for 'Sap.Data.Hana.HanaConnection' threw an exception. ---> System.IO.FileNotFoundException: Cannot find libADONETHDB.dll.
at Sap.Data.Hana.HanaUnmanagedDll.SearchNativeDlls(String regKeyName)
at Sap.Data.Hana.HanaUnmanagedDll..ctor()
at Sap.Data.Hana.HanaUnmanagedDll.get_Instance()
at Sap.Data.Hana.HanaConnection..cctor()
--- End of inner exception stack trace ---
at [...my program calls...]
Why can't it find libADONETHDB.dll?
My applications are build one in 32-bit, the other in 64-bit.
On this machine I installed SAP HANA client 2.8.20.23662 (latest version) both 32-bit and 64-bit.
The file that cannot be found seems to exist:
You could use Process Monitor while running the relevant part of the program to see, which file is missing and the path it should be in. Exclude all other events than file events and filter out all SUCCESS messages.
Perhaps it is referenced relative to the calling DLL (where Sap.Data.Hana.HanaUnmanagedDll.SearchNativeDlls is defined).
My hipotesis is that GAC had been corrupted with version 1 of Sap.Data.Hana.v4.5.dll:
Probably in the past HANA Client version 1 had been installed and removed and uninstallation hadn't cleaned the GAC.
My program uses HANA Client of any version, works both with version 1 and 2. For some reason when they start they seem to take version 1 of Sap.Data.Hana.v4.5.dll in the GAC. Process Monitor (thanks #sc911) confirms it:
This .NET DLL then looks for some unmanaged DLLs in C:\Program Files (x86)\hdbclient. Version 1 seems to look for libADONETHDB.dll in root folder.
But currently in this machine in that folder we have HANA Client 2.x and its folder structure is quite different from that of version 1 (there is no libADONETHDB.dll in root folder).
Hence the error in this question.
All this is valid both for 32-bit and 64-bit HANA Client.
I solved renaming or deleting version 1 folder in C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Sap.Data.Hana.v4.5 (probably there are better ways for performing this cleanup).

Unhandled Exception: System.InvalidProgramException: Common Language Runtime det ected an invalid program

I bought a new computer recently and uploaded this project to a FTP server and then downloaded it to my new computer but now it is causing this error:
Unhandled Exception: System.InvalidProgramException: Common Language Runtime det
ected an invalid program.
at Nancy.Conventions.NancyConventions.<Validate>b__1(Tuple'2 result)
at System.Linq.Enumerable.WhereEnumerableIterator'1.MoveNext()
at Nancy.Conventions.NancyConventions.Validate()
at Nancy.Bootstrapper.NancyBootstrapperBase'1.Initialise()
at Nancy.Hosting.Self.NancyHost..ctor(INancyBootstrapper bootstrapper, HostCo
nfiguration configuration, Uri[] baseUris)
at Nancy.Hosting.Self.NancyHost..ctor(Uri baseUri, INancyBootstrapper bootstr
apper, HostConfiguration configuration)
at PokerServer.Program.startServer() in f:\Projects\Visual Studio\PokerServer
\PokerServer\Program.cs:line 93
at PokerServer.Program.Main() in f:\Projects\Visual Studio\PokerServer\PokerS
erver\Program.cs:line 23
It worked well on the old computer.
I have updated .NET (and all other updates under Windows Update as mentioned in another thread).
I have tried deactive and active "Code optimization" without any problems.
The directory is not the same as before, not sure if that can cause this problem?
I verify my code with peverify and if I understand it correctly everything looks good:
F:\Projects\Visual Studio\PokerServer\PokerServer\bin\Debug>peverify PokerServer
.exe /md /il
Microsoft (R) .NET Framework PE Verifier. Version 4.0.30319.33440
Copyright (c) Microsoft Corporation. All rights reserved.
All Classes and Methods in PokerServer.exe Verified.
Any help is highly appreciated!
Are you actually compiling the project on the new computer or just running the application?
If you're just running it, did you verify that the application assembly or assemblies are actually identical on both computers? I suggest, you first rule out the option, that something happened during the data transfer.
If you're compiling it, what are you compiling it with? VIsual Studio? Which version?
In any case, the error is not related to the file directory, the application is in. According to MSDN, the exception should only be thrown when the compiled application is invalid (i.e. in case of a bug in the compiler). You can find more info in this knowledge base article. Try running the PEVerify tool and rebuilding the application in debug configurtion as the article suggests.
I removed the old Nancy dependency and installed it again from Nuget and now it works.

SonarException: Unknown metric: temp-method-lines

I was searching for answer many hours but I haven't found any solution.
I'm running sonar for C# project, I using Sonar 3.4 and sonar-runner 2.0 and C# plugins:
sonar-csharp-core-plugin-1.4
sonar-csharp-fxcop-plugin-1.4
sonar-csharp-gallio-plugin-1.4
sonar-csharp-gendarme-plugin-1.4
sonar-csharp-ndeps-plugin-1.4
sonar-csharp-squid-plugin-1.4
sonar-csharp-stylecop-plugin-1.4
and after running the analysis by sonar-runner I getting that exception
Exception in thread "main" org.sonar.runner.RunnerException: org.sonar.api.utils.SonarException: Fail to decorate 'org.sonar.api.resources.File#243e2c21[key=ApplicationName.cs,dir=,filename=ApplicationName.cs,language=C#]'
at org.sonar.runner.Runner.delegateExecution(Runner.java:288)
at org.sonar.runner.Runner.execute(Runner.java:151)
at org.sonar.runner.Main.execute(Main.java:84)
at org.sonar.runner.Main.main(Main.java:56)
Caused by: org.sonar.api.utils.SonarException: Fail to decorate'org.sonar.api.resources.File#243e2c21[key=ApplicationName.cs,dir=,filename=ApplicationName.cs,language=C#]'
at org.sonar.batch.phases.DecoratorsExecutor.executeDecorator(DecoratorsExecutor.java:84)
at org.sonar.batch.phases.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:70)
at org.sonar.batch.phases.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:63)
at org.sonar.batch.phases.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:63)
at org.sonar.batch.phases.DecoratorsExecutor.execute(DecoratorsExecutor.java:55)
at org.sonar.batch.phases.Phases.execute(Phases.java:92)
at org.sonar.batch.bootstrap.ProjectModule.doStart(ProjectModule.java:129)
at org.sonar.batch.bootstrap.Module.start(Module.java:68)
at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:147)
at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:141)
at org.sonar.batch.bootstrap.BatchModule.doStart(BatchModule.java:136)
at org.sonar.batch.bootstrap.Module.start(Module.java:68)
at org.sonar.batch.bootstrap.BootstrapModule.doStart(BootstrapModule.java:83)
at org.sonar.batch.bootstrap.Module.start(Module.java:68)
at org.sonar.batch.Batch.execute(Batch.java:106)
at org.sonar.runner.internal.batch.Launcher.executeBatch(Launcher.java:6
at org.sonar.runner.internal.batch.Launcher.execute(Launcher.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.sonar.runner.Runner.delegateExecution(Runner.java:285)
... 3 more
Caused by: org.sonar.api.utils.SonarException: Unknown metric: temp-method-lines
at org.sonar.batch.index.DefaultIndex.addMeasure(DefaultIndex.java:184)
at org.sonar.batch.DefaultDecoratorContext.saveMeasure(DefaultDecoratorContext.java:111)
at org.sonar.plugins.uselesscodetracker.decorator.TempMethodLinesDecorator.computeDistributionFromChildren(TempMethodLinesDecorator.java:58)
at org.sonar.plugins.uselesscodetracker.decorator.TempMethodLinesDecorator.decorate(TempMethodLinesDecorator.java:49)
at org.sonar.batch.phases.DecoratorsExecutor.executeDecorator(DecoratorsExecutor.java:79)
... 24 more
I don't know what this "temp-method-lines" metric can be, never heard of it...
Please install the latest version of the .NET & C# Plugins Ecosystem: version 2.0. Also, make sure you uninstall any other plugin that could have brought this unknown metric (maybe a custom plugin that you wrote??).
And please upgrade to Sonar 3.4.1 as version 3.4 suffers from a critical bug.

CUDAfy.NET giving Win32Exception: The system cannot find the file specified

I've added a reference to the CUDAfy.NET library via NuGet.
<package id="CUDAfy.NET" version="1.12.4695.21111" targetFramework="net45" />
When I run my program, I hit a Win32Exception:
The system cannot find the file specified
This happens on the first actual line of the program:
CudafyModule km = CudafyTranslator.Cudafy();
There's no indication from the exception object as to what file they're attempting to load.
How can I get past this problem?
EDIT
I see the same exception when running the bundled examples from the Codeplex download in VS2010 using .NET 4.0.
The strack trace is:
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at Cudafy.CudafyModule.Compile(eGPUCompiler mode, Boolean deleteGeneratedCode)
at Cudafy.Translator.CudafyTranslator.Cudafy(ePlatform platform, eArchitecture arch, Version cudaVersion, Boolean compile, Type[] types)
at Cudafy.Translator.CudafyTranslator.Cudafy(ePlatform platform, eArchitecture arch, Type[] types)
at Cudafy.Translator.CudafyTranslator.Cudafy()
Setting VS to break on thrown exceptions shows the ProcessStartInfo object at the top of the stack in the locals pane of the debugger.
The relevant properties are:
FileName = nvcc
Arguments = -m64 -arch=sm_12 "c:\<path>\CUDAFYSOURCETEMP.cu" -o "c:\<path>\CUDAFYSOURCETEMP.ptx" --ptx
Some information from this article explains that the CUDA Toolkit must be installed. Fair enough.
Ensure that the C++ compiler (cl.exe) is on the search path. This set-up of NVCC is actually the toughest stage of the whole process, so please persevere. Read any errors you get carefully - most likely they are related to not finding cl.exe or not having either 32-bit or 64-bit CUDA Toolkit.
That article discusses version 4 of the toolkit, but version 5 is available now and supported since CUDAfy v1.1.
Download from https://developer.nvidia.com/cuda-downloads
Note that the 64-bit version of the CUDA Toolkit 5.0 is a 942 MB download. If you install everything you'll need an additional 2815 MB. The toolkit alone requires 928 MB.
EDIT After installing the CUDA Toolkit 5.0, the program failed with a CudafyCompileException at the same source line:
Compilation error: nvcc : fatal error : Cannot find compiler 'cl.exe' in PATH
Searching my system drive:
C:\>dir /s cl.exe
This shows many different versions of the compiler/linker, both from VS 10.0 and 11.0. Apparently only cl.exe versions 9 and 10 are supported, so I opted for the VS10.0 amd64 version, I included the following in my PATH environment variable:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64
Your path may be different, depending upon your CPU. I recommend running the search to see your options.
Note that you will have to restart VS after changing the PATH environment variable if you already have it open.
After taking these steps, my basic program ran successfully.
This may also happen if you had at some point installed CUDA Toolkit v7.5, but realized that the most recent version of CUDAfy supports CUDA 7.0.
On uninstalling CUDA 7.5 from the control panel, some files/folders may still remain. You should delete these manually. You may use CUDAfyViewer to see which version of CUDA Toolkit is being accessed.

Categories

Resources