Libtorch CUDA predictions not working on .NET 6.0 debug version

I have some strange problem. I have created C++ DLL with LibTorch. It has two functions. One for loading model and one for predicting. It’s used for segmentation with U-net. C++ code is working fine but the problem occurs when I want to use it in C# with CUDA.

I tried to use it in C# .NET framework 4.7.2 and it works fine in both release and debug version. When I tried to use it in .NET 6.0 for some reason release version works, but debug doesn’t. Program crashes when it is trying to predict.