justcoding121 / titanium-web-proxy

A cross-platform asynchronous HTTP(S) proxy server in C#.
MIT License
1.93k stars 618 forks source link

SystemProxyManager.openInternetSettingsKey null reference #734

Closed kakins closed 1 year ago

kakins commented 4 years ago

Trying to use this in a Unity3d project. I'm not sure if this has something to do with the Unity itself, perhaps because it is running Mono? I get the following error when using some of the example code:

NullReferenceException: Object reference not set to an instance of an object
Titanium.Web.Proxy.Helpers.SystemProxyManager.openInternetSettingsKey () (at <0ffc67c1d5eb437194b5d20a4fd33c88>:0)
Titanium.Web.Proxy.Helpers.SystemProxyManager.GetProxyInfoFromRegistry () (at <0ffc67c1d5eb437194b5d20a4fd33c88>:0)
Titanium.Web.Proxy.ProxyServer.Start () (at <0ffc67c1d5eb437194b5d20a4fd33c88>:0)

It appears the null reference is in the body of openInternetSettingsKey.

However, when I try to run the same code in my Immediate Window in Visual Studio while debugging, I do not get a null reference:

Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true)

"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
    base: "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
    Handle: {Microsoft.Win32.SafeHandles.SafeRegistryHandle}
    Name: "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
    SubKeyCount: 10
    ValueCount: 15
    View: Default
honfika commented 4 years ago

Yes, on Unity it seems to be unsuppoprted... I'll add a check for that.

honfika commented 4 years ago

The Registry.CurrentUser is null, right? Could you please check it?

kakins commented 4 years ago

Well, I assuming it is null when code path reaches openInternetSettingsKey. However, when I check Registry.CurrentUser before starting the proxy server, it is not null. There's no way for me to check the state of Registry.CurrentUser once the execution reaches openInternetSettingsKey, I can't debug into that method.

honfika commented 4 years ago

I added a null check. Please try the latest beta packade... Do you still receive the nullreference exception in TPW openInternetSSettingsKey?

kakins commented 4 years ago

That seemed to do it. The proxy starts and says it's listening, however none of the handlers are hit. For instance, just using the default setup from the readme, and navigating to something like google.com, no traffic seems to be intercepted. That may be a separate issue, though.

honfika commented 4 years ago

From where do you send the requests? Are you sure that you corretly set the proxy URL in your browser (if it is a browser)?

kakins commented 4 years ago

I was sending the requests just from a regular web browser. I didn't know there was a specific proxy URL I needed to use.

honfika commented 4 years ago

You should set the proxy address in your browser. Is everything ok after you set the proxy?

kakins commented 1 year ago

Closing this guy because I'm no longer working with this