#StackBounty: #prediction #library #.net Pattern recogniser library for C# programs

Bounty: 100

I’m a regular user of the StackOverflow forum, but as this question is about a recommendation for libraries, which is supported at StackOverflow, and as my question is about data science libraries, I’ve decided to take my chance here (my original question has been kicked from the "Artificial Intelligence forum").

I’m developping a program that takes a table of a database and predicts the next (limited list of) tupple(s),
e.g. for the following table:

A    B    C    D
1   12    0    A
2   14    0    A
3   16    0    A
4   18    0    A
5   20    0    A

I would like to predict the following tupple:

A    B    C    D
6   22    0    A

For that, I have created two SQL queries:

    => if the result is 1, then all values are equal, easy peasy 🙂
  2. SELECT MAX(col1-lag_col1) FROM ( SELECT Col1, LAG(Col1) ... (take the difference between subsequent tupples)
    => If both maximum and minimum are equal and not zero, there’s an arithmetic progression (more information here).
    I thought I was on a good track, but then the first problems started arising:

In a list of +800 tupples, the arithmetic progression was disturbed by one single erroneous entry, messing up my prediction.
I have seen values like AB123, AB124, AB125, …: although this is easy for a person to predict, it’s not that straightforward for a computer (and what in case of ABC12x or AB12, AC12, AD12, …?).
In both cases, the key solution is pattern recognition: if I can feed the values to a pattern recogniser, it might find the pattern (and maybe the values, messing it up) and I might use that for predicting the next tupple(s).
What’s the programmers term for pattern recognition? Right: it’s A.I., artificial intelligence, more exactly data science. But as most of you know, that’s an enormously broad term.

Therefore I’m risking my chances here: does anybody know about a library (or whatever) I might use in my C# program in order to find patterns and predict values (numbers, strings and their combinations)?

Get this bounty!!!

#StackBounty: #c# #.net #roslyn #insertion C# Roslyn API: Insert Instructions/Methods between each nodes members

Bounty: 100

I just got into a personal project and I would like to be able to use the Roslyn API to insert instructions / methods between class members (So methods / instructions)

I am currently able to retrieve the different child nodes like here: Namespace> Class> Fileds / Méthods

But I would like to know how I can insert code between fields / method and not replace cod.

(At the location of the red lines below for example)


EDIT: After some more research i found that i can use InsertTokensBefore, InsertNodesBefore or InsertTriviaBefore but i don’t understand how parse my functions (actually in text/string format) to the needed parameters

Get this bounty!!!

#StackBounty: #c# #.net #wpf #windows How can I reset VisualTreeHelper.GetDpi() to return the true DPI?

Bounty: 50

VisualTreeHelper.GetDpi() gets the dpi when the application is launched. Subsequent calls return the same value even if the user has meanwhile changed the dpi in Settings -> Display.

How can I "reset" the dpi that VisualTreeHelper.GetDpi() sees without restarting the application?

Some code:

Title = VisualTreeHelper.GetDpi(this).DpiScaleX.ToString();

Get this bounty!!!

#StackBounty: #c# #.net #wpf #rdlc #reportviewer RDLC issues on monitors with higher recommended scaling

Bounty: 500

I’m on .net framework 4.8 in my WPF app and I have two usages on RDLC. 1st is a fully fetched ReportViewer that uses a DataTable from postgres, 2nd is just a LocalReport with small number of parameters rendered as EMF and printed directly with use of default printer.

They both have what would seem to be rendering issues, but just on monitors that have recommended scaling (RS) >100%. The outcome is squashing of letters vertically and adding some extra space in between (I can provide samples as soon as I get access to client machine again). If I just increase scaling on my 100% RS monitor, everything prints out just fine. If I replace the >100% RS monitor with a 1080p 100% RS one, again, everything prints out fine. Printouts on machines with monitors with >100% RS come out always messed up irrelevant of the scaling I set in Windows. Issues can be quickly reproduced with just ‘Print Layout’ view in ReportViewer, exporting to PDF produces same results.

Since I have ReportViewer and a direct printout of LocalReport I was able to try out several different approaches:

  • Making the app DPIAware / not aware / true/PM etc. (also included manifest, App.config and App.xaml changes)
  • Putting the ReportViewer in ViewBox
  • Using DpiX/Y and PrintDpiX/Y on DeviceInfo
  • ScaleTransform and DrawImageUnscaled on PrintPage callback with and without the DeviceInfo changes
  • countless printer options in Windows

Client machines run on either latest Windows 10 or close to latest and are rather empty otherwise.

Does it ring any bells? Any idea for potential fix?

I would love to use RDLC in my app, for the simplicity of development and usage, but those issues are really a no go for the technology.

Get this bounty!!!

#StackBounty: #c# #object-oriented #design-patterns #.net #memory-management Implement IDisposable correctly using object composition p…

Bounty: 50

Is it possible to implement IDisposable pattern correctly while using object composition principle to promote code-reuse, reduce code duplication and hide verbose "official" implementation?



Delegate the dispose logic to a dedicated class:

public class DisposeManager
    public Action Managed { get; set; }
    public Action Unmanaged { get; set; }

    protected virtual void Dispose(bool disposing)
        // only dispose once
        if (disposed)

        if (disposing)


        disposed = true; 

    public void DisposeObject(object o)
        Dispose(disposing: true);

    public void FinalizeObject()
        Dispose(disposing: false);

    private bool disposed;

Implement IDisposable in user class in the following way:

public class DisposeUser : IDisposable
    public DisposeUser()
        // using lambda
        disposeManager.Managed = () =>
            // [...]

        // or using member method
        disposeManager.Unmanaged = DisposeUnmanaged;


    public void Dispose()

    private void DisposeUnmanaged()
        // [...]

    private readonly DisposeManager disposeManager = new DisposeManager();


  • much simpler to implement for user classes
  • more explicit (managed, unmanaged)
  • use composition
  • remove the needs for multiple base classes all implementing the dispose pattern and creating code duplication


  • Is it ever a good idea or more of a programmer fancy "improvement" idea ?
  • I’ve made a decent number of research on the dispose pattern and implementation but never found someone suggesting such idea, any reason why?
  • Any potential problems around hard refs, especially with Action capturing members, etc. that would prevent the actual user class to be collected correctly?
  • Other thought?


Get this bounty!!!

#StackBounty: #c# #.net #proxy #webrequest #webproxy Connect over company proxy with user name

Bounty: 50

I am trying to connect to external IP address but I am behind company firewall, so I need to connect over the proxy.

I run a test with curl:

curl -v https://IP_ADDRESS_OF_EXTERNAL_CLIENT:6125 -x http://MyComparyProxyAddress.com:8080 -U MYUSERNAME:MYPASSWORD

but I am failing to replicate aforementioned cUrl command in C#:

private static Socket CreateTunnelThruProxy(string destIP, int destPort)
            string destUriWithPort = $"{destIP}:{destPort}";
            UriBuilder uriBuilder = new UriBuilder(destUriWithPort);
            Uri destUri = uriBuilder.Uri;

            var proxy = new WebProxy("http://MyComparyProxyAddress.com", 8080);
            proxy.UseDefaultCredentials = false;
            proxy.Credentials = new NetworkCredential("MYUSERNAME", "MYPASSWORD");
            WebRequest.DefaultWebProxy = proxy;

            IWebProxy webProxy = WebRequest.DefaultWebProxy;

                if (webProxy.IsBypassed(destUri))
                    return null;
            catch (PlatformNotSupportedException)
                // .NET Core doesn't support IWebProxy.IsBypassed
                // (because .NET Core doesn't have access to Windows-specific services, of course)
                return null;

            Uri proxyUri = webProxy.GetProxy(destUri);
            if (proxyUri == null)
                return null;

            IPAddress[] proxyEntry = Dns.GetHostAddresses(proxyUri.Host);
            int iPort = proxyUri.Port;
            IPAddress address = proxyEntry.First(a => a.AddressFamily == AddressFamily.InterNetwork);
            IPEndPoint proxyEndPoint = new IPEndPoint(address, iPort);
            Socket socketThruProxy = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            string proxyMsg = $"CONNECT {destIP}:{destPort} HTTP/1.1 nn";
            byte[] buffer = Encoding.ASCII.GetBytes(proxyMsg);
            byte[] buffer12 = new byte[50000];
            socketThruProxy.Send(buffer, buffer.Length, 0);
            int msg = socketThruProxy.Receive(buffer12, 50000, 0);
            string data;
            data = Encoding.ASCII.GetString(buffer12);
            int index = data.IndexOf("200");

            if (index < 0)
                throw new ApplicationException(
                    $"Connection failed to {destUriWithPort} through proxy server {proxyUri.ToString()}.");

            return socketThruProxy;

I keep getting following information from my company proxy:

HTTP/1.1 407 Proxy Authentication Required
Proxy-Authenticate: NEGOTIATE
Proxy-Authenticate: NTLM
Proxy-Authenticate: BASIC realm="ztb"
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Proxy-Connection: close
Connection: close
Content-Length: 797

<TITLE>Access Denied</TITLE>
<body bgcolor="#FFFFEA">
<TABLE border=0 cellPadding=1 width="80%">
<FONT face="Verdana">
<big>Access Denied (authentication_failed)</big>
<FONT face="Verdana">
Your credentials could not be authenticated: "Credentials are missing.". You will not be permitted access until your credentials can be verified.
<FONT face="Verdana">
This is typically caused by an incorrect username and/or password, but could also be caused by network problems.
<FONT face="Verdana" SIZE=2>
For assistance, contact your Tech Desk . PXFFM25

I can clearly see that webProxy object contains credentials set by me, the same credentials that are working with cUrl.

Also I am getting the same error when trying simply calling:

IWebProxy webProxy = WebRequest.GetSystemWebProxy();

instead of setting credentials manually, as per code snippet above. So it looks like my credentials are not taken into account….

Any ideas ?

Get this bounty!!!

#StackBounty: #.net #azure #azure-functions #azure-web-app-service Dynamically Adjust System Time of Azure App Service

Bounty: 50

We have an Azure Function (dotnet) deployed that relies heavily on the current date/time for many operations.

We are writing an integration test suite for it and would really love to keep a blackbox approach. That is, we’d rather not internally mock the date/time if possible.

Is there a way to adjust the system time of the app service to achieve this? Ideally, there would be a non-intrusive way to achieve this, but I’m open to lightly-instrusive options

Get this bounty!!!

#StackBounty: #.net #visual-studio #msbuild #continuous-integration #azure-functions Unable to publish Azure Function v1.0 on file syst…

Bounty: 100

I am trying to publish azure function v1.0 using publish profile and contents of publish profile is given below

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Platform>Any CPU</Platform>
    <PublishDir>C:New folder</PublishDir>

and this publish profile we are using with below given msbuild command (FolderProfile is the name of publish profile that we are using within command)

C:codemsbuild "mufunctionapp.csproj" /t:Rebuild /p:Configuration=Release;PublishProfile=PublishProfiles/FolderProfile

But after running this command nothing gets copied(published) into the folder (C:New folder) specified within publish profile. But I could see the publish artifacts ( binaries) being copied to objReleasenet48PubTmpOutbin

But If I use the same publish profile with Visual Studio 2019 ,the publish artifacts ( binaries) are getting copied into the folder specified within publish profile.

I want to publish the binaries using msbuild command with given publish profile within CI but as It is not working locally I am unable to use the msbuild there in CI pipeline.

Could you please tell me if there is anything that I am doing wrong in MSBUILD or in publish profile.

Get this bounty!!!

#StackBounty: #c# #.net Why do I get FatalExecutionEngineError when breakpoint editing parameters to System.Numerics functions on x64 b…

Bounty: 500

On AnyCPU or x86, I can run this program, set a breakpoint on Foo, edit the first parameter from 0.5f to 0.6f, and resume just fine.
On x64 though, it consistently crashes with FatalExecutionEngineError on resuming.

using System;
using System.Numerics;

public static class Interaction
    public static void Main(string[] args)
        while (true)

    private static Matrix4x4 Foo
            return Matrix4x4.CreateFromYawPitchRoll(0.5f /* breakpoint and set this to 0.6f*/, 0.5f, 0.5f);


At the very least, it’s happening on .NET Framework 4.7.2 and .NET Framework 4.6.2. Is there a way I can fix this?

Edit: Tested it on .NET Framework 4.8, after reading that they fixed some x64 stuff in that version, and it’s still crashing!

Get this bounty!!!