Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: PowershellSensor as Satellite Service - error_during_execution #343

Open
2 of 4 tasks
Skons opened this issue Aug 15, 2023 · 47 comments
Open
2 of 4 tasks

Bug: PowershellSensor as Satellite Service - error_during_execution #343

Skons opened this issue Aug 15, 2023 · 47 comments

Comments

@Skons
Copy link

Skons commented Aug 15, 2023

Describe the bug
Powershell sensor does not work as satellite service. It works when Test Command/Script is executed, and it works as a hass.agent sensor.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Satellite Service
  2. Click on Sensors
  3. Click on Add New
  4. Select PowerShellSensor
  5. Add this as command $(get-date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss')
  6. Click Store Sensor
  7. Click Send & Active Sensors

Expected behavior
The date as state in Home Assistant

Screenshots
image
image

Misc info (please complete the following information):

  • Windows build (ideally screenshot/info of winver.exe output): Win10 22H2
  • Windows' UI language: EN
  • HASS.Agent version: 2022.14.0

Please check what's applicable (multiple answers possible):

  • Installed via installer
  • Installed manually
  • Problem occurs in HASS.Agent
  • Problem occurs in Satellite Service
@amadeo-alex
Copy link

Hello,
I cannot reproduce this:
obraz

Snippet from satellite sensor config:

  {
    "Type": "PowershellSensor",
    "Id": "67ce197d-bcb0-4a61-a604-a6f276aacd32",
    "FriendlyName": "",
    "UpdateInterval": 30,
    "Query": "$(get-date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss')",
    "Scope": null,
    "WindowName": "",
    "Category": "",
    "Counter": "",
    "Instance": "",
    "Name": "AMADEO-PC-satellite_powershellsensor",
    "ApplyRounding": false,
    "Round": null
  },

@Skons
Copy link
Author

Skons commented Aug 31, 2023

this is mine:

[
  {
    "Type": "PowershellSensor",
    "Id": "3a0ef5bd-22bb-475d-9df2-d7ae48bb5430",
    "UpdateInterval": 30,
    "Query": "$(get-date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss')",
    "Scope": null,
    "WindowName": "",
    "Category": "",
    "Counter": "",
    "Instance": "",
    "Name": "[snip]-satellite_powershellsensor"
  }
]

I noticed i missed ApplyRounding and Round. Stopped the service, edited the json, started the service again. No success. After send and activate the custom config was gone.

The satelite service is 2022.20.0.0. I am running the client from another disk (D:) then the satelite service (C:).

I also tried to change the command to $env:computername, that dit not work either

@Zarox666
Copy link

Zarox666 commented Sep 5, 2023

I get the same Error Code executing a Powershell Script that gets the the GPU Power Consumption via some String-Extraction out of nvidia-smi.exe.
This works perfectly fine from the Agent or when testing from the Config, but HomeAssistant shows the value as "error_during_execution".
image0
image

Other Sensors, such as ProcessActive work without any problem.

@Zarox666
Copy link

Any ETA on this?
Running the PowerShell Sensor as User instead of Service works, but relogging everytime as User is not the idea behind a Server/Service.

@amadeo-alex
Copy link

@Zarox666
Hard to give ETA for a fix PR as I'm not able to reproduce this issue.
You may try to help with the investigation by posing the script that is not working for you.

@Skons
Strange that it removes the round config options, are you using newest available version of HASS.Agent?

@Skons
Copy link
Author

Skons commented Sep 10, 2023

Yes, it is stated in the first post: 2022.14.0.

if you want me to run a debug version, or enable debug logging (if possible), then i am happy to help

@Zarox666
Copy link

Zarox666 commented Sep 11, 2023

OK now its gettinig wiered.....

For me the service based sensor on my Server startet to work this morning (without any interaction from my end)
At that time the expected value changed from 0 to 5 and later back to 0.
The Service Sensor changed from unknown to 5 and later correctly to 0.
image

However the Service based sensor on my PC still reports unknown instead of the correct value of 0
image

Here is the Script that is used by both Sensors:
(in essence it reads lines out of a .ini file and fills a path variable with that. Then it counts how many running process exist that have their .exe file somewhere under that path and returns that number.)
`
#$DebugPreference = "Continue"

#Include

#Variables
$MinerInstances = 0
Get-Content $PSScriptRoot\mining.ini | Foreach-Object{
$var = $_.Split('=')
New-Variable -Name $var[0] -Value $var[1] -ErrorAction SilentlyContinue
}

Write-Debug "#####################################"
Write-Debug "MineManagerPath= $MineManagerPath"
Write-Debug "#####################################"

Get-ChildItem -Path $MineManagerPath -Filter .exe -Recurse -File -Name| ForEach-Object {
$ProcessName = [System.IO.Path]::GetFileNameWithoutExtension($_)
if (Get-Process -Name $ProcessName -ErrorAction SilentlyContinue)
{
$Process = Get-Process -Name $ProcessName
$ProcessPath = $Process.Path
$ProcessID = $Process.Id
Write-Debug "Found running Process $ProcessName out of $ProcessPath with ProcessID $ProcessID"
if ($ProcessPath -like $MineManagerPath+"
" )
{
Write-Debug "Mining-Process found!"
$MinerInstances++
}
}
}

return $MinerInstances
`
The other Script that has the same issue retrieves GPU Power consumption via String extraction from an NVIDIA .exe file.
Its a lot more complex.

Let me set up a Test-Sensor with a power-shell Script that just returns 0 and see how that fares.

EDIT:
And yes, I am fully aware that it now shows "unknown" instead of the original "error_in_execution". I have no explanation for this.
I can even pinpoint when this happend:
image

@Zarox666
Copy link

Zarox666 commented Sep 11, 2023

OK,

succesfull Repro, but only on my PC not on my Server (more on that later).
image

The Names appended with _service are Service Sensors in HASS, the others are normal Sensors.
all 4 sensor are powershell sensors executing a powershell script containing just one line:
return 0

So this makes it clear, that its not due to the logic inside the Powershell script, but other factors must be at play here.
my Server is a Windows Server 2022 Version 21H2.
my PC is a Windows 10 Versiojn 22H2.
HASS Agent Version on both 2022.14.0

However we need to depart from the notion, that it never works:
(any number including 0 is a valid value)
(times where ZaroxOmega goes black is due to my PC beeing switched off)
(the problem are the yellow "error_during_execution" and grey "unknown" blocks)
last week:
image

@Zarox666
Copy link

Zarox666 commented Sep 11, 2023

I might have made some progress.

My Service Log File on my PC is full with these messages:
2023-09-11 14:32:12.851 +02:00 [FTL] 1 is not a supported code page. (Parameter 'codepage') System.ArgumentException: 1 is not a supported code page. (Parameter 'codepage') at System.Text.Encoding.GetEncoding(Int32 codepage) at HASS.Agent.Shared.Managers.PowershellManager.ExecuteWithOutput(String command, TimeSpan timeout, String& output, String& errors) 2023-09-11 14:32:12.851 +02:00 [FTL] 1 is not a supported code page. (Parameter 'codepage') System.ArgumentException: 1 is not a supported code page. (Parameter 'codepage') at System.Text.Encoding.GetEncoding(Int32 codepage) at HASS.Agent.Shared.Managers.PowershellManager.ExecuteWithOutput(String command, TimeSpan timeout, String& output, String& errors) 2023-09-11 14:32:13.613 +02:00 [FTL] 1 is not a supported code page. (Parameter 'codepage') System.ArgumentException: 1 is not a supported code page. (Parameter 'codepage') at System.Text.Encoding.GetEncoding(Int32 codepage) at HASS.Agent.Shared.Managers.PowershellManager.ExecuteWithOutput(String command, TimeSpan timeout, String& output, String& errors) 2023-09-11 14:32:13.613 +02:00 [FTL] 1 is not a supported code page. (Parameter 'codepage') System.ArgumentException: 1 is not a supported code page. (Parameter 'codepage') at System.Text.Encoding.GetEncoding(Int32 codepage) at HASS.Agent.Shared.Managers.PowershellManager.ExecuteWithOutput(String command, TimeSpan timeout, String& output, String& errors) 2023-09-11 14:32:13.613 +02:00 [FTL] 1 is not a supported code page. (Parameter 'codepage') System.ArgumentException: 1 is not a supported code page. (Parameter 'codepage') at System.Text.Encoding.GetEncoding(Int32 codepage) at HASS.Agent.Shared.Managers.PowershellManager.ExecuteWithOutput(String command, TimeSpan timeout, String& output, String& errors) 2023-09-11 14:32:14.364 +02:00 [FTL] 1 is not a supported code page. (Parameter 'codepage') System.ArgumentException: 1 is not a supported code page. (Parameter 'codepage') at System.Text.Encoding.GetEncoding(Int32 codepage) at HASS.Agent.Shared.Managers.PowershellManager.ExecuteWithOutput(String command, TimeSpan timeout, String& output, String& errors) 2023-09-11 14:32:14.364 +02:00 [FTL] 1 is not a supported code page. (Parameter 'codepage') System.ArgumentException: 1 is not a supported code page. (Parameter 'codepage') at System.Text.Encoding.GetEncoding(Int32 codepage) at HASS.Agent.Shared.Managers.PowershellManager.ExecuteWithOutput(String command, TimeSpan timeout, String& output, String& errors) 2023-09-11 14:32:14.364 +02:00 [FTL] 1 is not a supported code page. (Parameter 'codepage') System.ArgumentException: 1 is not a supported code page. (Parameter 'codepage') at System.Text.Encoding.GetEncoding(Int32 codepage) at HASS.Agent.Shared.Managers.PowershellManager.ExecuteWithOutput(String command, TimeSpan timeout, String& output, String& errors)
I do not see these Messages in the Services Log on my Server, where the Powershell sensor works.

Digging into the Error Message searching for System.Text.Encoding.GetEncoding I found that "1" is indeed not a valid codepage.
See:
https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getencoding?view=net-7.0
https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding?view=net-7.0
However its not clear to me, why this would behave different between the two Systems.
1 is not a valid code page for either of them, so I can only assume, that
HASS.Agent.Shared.Managers.PowershellManager.ExecuteWithOutput
might be behaving differently between the two otherwise "identical?" scenarios.

@Skons
Copy link
Author

Skons commented Sep 11, 2023

It could be that the .Net version makes a difference. Mine is 4.8.09032. Nice find!

Edit: Same here

2023-09-11 17:13:22.842 +02:00 [FTL] 1 is not a supported code page. (Parameter 'codepage')
System.ArgumentException: 1 is not a supported code page. (Parameter 'codepage')
   at System.Text.Encoding.GetEncoding(Int32 codepage)
   at HASS.Agent.Shared.Managers.PowershellManager.ExecuteWithOutput(String command, TimeSpan timeout, String& output, String& errors)

@amadeo-alex
Copy link

Good find, thank you both!
I'll take a look at what may be causing this.

@amadeo-alex
Copy link

amadeo-alex commented Sep 11, 2023

From what I've been able to research, it looks like this might be some kind of incompatibility between the .net/.netframework and the keyboard/system languages which are installed on a given system.
@Zarox666 could you please check the keyboard/system languages on both of your systems and look for discrepancies?
In the meantime I'll create a fallback logic to UTF-16 and put it as part of LAB02-Research/HASS.Agent.Staging#14 which should remediate the issue.

@Skons
Copy link
Author

Skons commented Sep 11, 2023

These are mine
image
But, as a user i do not have any problem running this. As SYSTEM it is a problem. Maybe there is something else in regards to the SYSTEM "user"?

@amadeo-alex
Copy link

Fix added to the PR and merged to the bulk PR LAB02-Research/HASS.Agent.Staging#24.
Unfortunately for now the only reliable way to get it is to build the project yourself :\ (I don't recommend accepting exe files/binaries from me or any other random internet user)

@Skons
Copy link
Author

Skons commented Sep 11, 2023

There is progress, but its not what i expected:
image

@amadeo-alex
Copy link

What the...I'm quite certain that is neither English or Dutch :D
Can I please have those ?chinese? characters?

@amadeo-alex
Copy link

Yeah, using unicode/utf-16 causes "normal" characters to become chinese and using utf-8 causes the chinese characters to be broken. How one cannot love text encoding...

@Skons
Copy link
Author

Skons commented Sep 11, 2023

image
In the hass agent, the value is correct

@Skons
Copy link
Author

Skons commented Sep 11, 2023

Just a side note: i saw that the implementation is done by executing powershell.exe. Are you aware that you could implement powershell c# natively? https://learn.microsoft.com/en-us/powershell/scripting/developer/hosting/host01-sample?view=powershell-7.3

And second: if you'll keep on using the commandline, did you know the command executed by powershell.exe can be base64 encoded? https://devblogs.microsoft.com/scripting/powertip-encode-string-and-execute-with-powershell/

@amadeo-alex
Copy link

image In the hass agent, the value is correct

Ok now I think I'm missing something, if I force the sensor to use utf-16 both the HASS.Agent preview and HA are malformed for me:
pfl4Qc
oRr9dt

Script:
$(get-date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss')

@Skons
Copy link
Author

Skons commented Sep 11, 2023

I am unable to store the sensor with the latest version. The sensors.json is not created.:

2023-09-11 22:47:52.639 +02:00 [INF] [SENSORSMANAGER] Processing 1 received sensor(s), deleting 0 sensor(s) ..
2023-09-11 22:47:52.663 +02:00 [FTL] [SENSORSMANAGER] Error while storing: PerformanceCounter not found
System.Exception: PerformanceCounter not found
   at HASS.Agent.Shared.HomeAssistant.Sensors.PerformanceCounterSensor..ctor(String categoryName, String counterName, String instanceName, Boolean applyRounding, Nullable`1 round, Nullable`1 updateInterval, String name, String friendlyName, String id) in C:\Users\Kevin\source\repos\HASS.Agent.Staging-bulk-s1\src\HASS.Agent.Staging\HASS.Agent.Shared\HomeAssistant\Sensors\PerformanceCounterSensor.cs:line 34
   at HASS.Agent.Satellite.Service.Settings.StoredSensors.ConvertConfiguredToAbstractSingleValue(ConfiguredSensor sensor) in C:\Users\Kevin\source\repos\HASS.Agent.Staging-bulk-s1\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\Settings\StoredSensors.cs:line 144
   at HASS.Agent.Satellite.Service.Sensors.SensorsManager.StoreAsync(List`1 sensors, List`1 toBeDeletedSensors) in C:\Users\Kevin\source\repos\HASS.Agent.Staging-bulk-s1\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\Sensors\SensorsManager.cs:line 266

@amadeo-alex
Copy link

You're using this branch? LAB02-Research/HASS.Agent.Staging#14

@amadeo-alex
Copy link

amadeo-alex commented Sep 11, 2023

Ok, I've changed it to fallback to utf-8 since I need to drop from the PC and don't want to leave a borked PR hanging around.
This should fix the issue partially as all "standard" characters should work. Everything else like chinese/polish characters will not display correctly.

I tried to fiddle with the settings but no matter what/how I configure the process which is launched, the "normal" part of the output is malformed when utf-16 is used.
I'll try to tackle this from other side tomorrow.
Main issue stays the same, on some systems, for some reason when "CultureInfo.CurrentCulture.TextInfo.OEMCodePage" is called from the service context, it returns 1 instead of proper code page.

@Skons
Copy link
Author

Skons commented Sep 11, 2023

You're using this branch? LAB02-Research/HASS.Agent.Staging#14

Yes

For what its worth, I also found this in regards to the OEMcodePage: https://stackoverflow.com/questions/1812104/relation-between-net-encoding-and-characterset

@Zarox666
Copy link

Zarox666 commented Sep 11, 2023

As requested:

There is indeed differences in the language settings. But as Skons has pointed out, this affects only the Service.

Server
image
PC
image

.NET Runtime on the Server is 6.0.3 while on the PC it is 6.0.21

Now let me read up on the remainder of the Thread :-)

@Zarox666
Copy link

Some thoughts.....

Is it smart to call OEMCodePage? as afaik the OEM in this context would be the hardware manufacturer... and that can vary widely from a laptop over a desktop to a virtual machine.
Instead of explicitly setting the CodePage wouldnt it be better to just let the System use its defaults?
https://learn.microsoft.com/en-us/dotnet/api/system.globalization.textinfo?view=net-7.0
(See "Remarks")

Sorry if these thoughts are silly... I am just an Escalation Engineer, not a Programmer :-)

@amadeo-alex
Copy link

I have small progress with the investigation...so, the main culprit here is that even if the process running powershell has the input/output set to X or Y encoding, the powershell internally will still use system encoding.
This causes issues because powershell will output for example "asdäöüąęć" in the current system encoding whatever it might be and process stream reader will interpret it as X or Y encoding that was configuring before running it.

I've found a workaround where "injecting" for example:
[Console]::OutputEncoding = [System.Text.Encoding]::Unicode
before the script/command itself works properly with Unicode/utf-16 encoding set for the process - this however is not an optimal solution.
This main issue persists that for some reason the "CultureInfo.CurrentCulture.TextInfo.OEMCodePage" returns an invalid value of "1" on some system/keyboard/locale configurations...

@amadeo-alex
Copy link

amadeo-alex commented Sep 13, 2023

This is going to look like a personal notebook but maybe it'll be useful for someone someday :D
As @Zarox666 suggested, not setting the input/output/error encoding causes the scrip/command to work properly with a caveat that some charactes come out as "?":
asdśćżń1äöü23说/説
becomes
asdśćżń1äöü23?/?
I'll take a wild guess that is has something to do with number of bytes required to encode a given character.

Installing additional display language borked this just because so, fun!

What is interesting is that restoring the code setting "StandardOutputEncoding" to OEMCodePage changes nothing in the output.

I'll rewind the git history of this file trying to find a good reasoning to remove this part of the code but if not, the safest way will be to set the StandardOutputEncoding when it is possible (OEMCodePage returns an actual value) and not touch it otherwise.

@amadeo-alex
Copy link

It was added as part of https://lab02research.youtrack.cloud/issue/hassagent-164 due to #201 so it definitely stays.
Ignoring the encoding when "OEMCodePage fails" is also not a good solution as it'll end up with "Issue: powershell sensor works in HASS.Agent but not in service" sooner or later.

@amadeo-alex
Copy link

@Skons @Zarox666 could you please try this branch - https://github.com/amadeo-alex/HASS.Agent.Staging/tree/test-powershell-sensor-encoding - on the affected machines and then post the logs? (this branch will create the log entries each time the sensor is updated so don't run it too long)

Expected output is something similar to this:

2023-09-13 22:42:46.730 +02:00 [ERR] ENCODING-TEST: currentCulture  {"ANSICodePage":1252,"OEMCodePage":437,"MacCodePage":10000,"EBCDICCodePage":37,"LCID":9,"CultureName":"en","IsReadOnly":false,"ListSeparator":",","IsRightToLeft":false}
2023-09-13 22:42:46.730 +02:00 [ERR] ENCODING-TEST: currentUICulture  {"ANSICodePage":1252,"OEMCodePage":437,"MacCodePage":10000,"EBCDICCodePage":37,"LCID":9,"CultureName":"en","IsReadOnly":false,"ListSeparator":",","IsRightToLeft":false}
2023-09-13 22:42:46.730 +02:00 [ERR] ENCODING-TEST: currentInstalledUICulture  {"ANSICodePage":1250,"OEMCodePage":852,"MacCodePage":10029,"EBCDICCodePage":20880,"LCID":1045,"CultureName":"pl-PL","IsReadOnly":true,"ListSeparator":";","IsRightToLeft":false}
2023-09-13 22:42:46.730 +02:00 [ERR] ENCODING-TEST: invariantCulture  {"ANSICodePage":1250,"OEMCodePage":852,"MacCodePage":10029,"EBCDICCodePage":20880,"LCID":1045,"CultureName":"pl-PL","IsReadOnly":true,"ListSeparator":";","IsRightToLeft":false}

In case something goes wrong (which we expect) there'll be additional
ENCODING-TEST: first/second/third/fourth fail

@Zarox666
Copy link

Zarox666 commented Sep 13, 2023

I tried to build the branch, but I get a lot of errors.
Not sure what to do about them. This is my first time building something in Visual Studio:

PS C:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service> dotnet run --project "c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj"
Building...
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'Google.Protobuf (>= 3.21.8)' for 'net6.0-windows7.0'.
C:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Shared\HASS.Agent.Shared.csproj : error NU1100: Unable to resolve 'ByteSize (>= 2.1.1)' for '.NETStandard,Version=v2.1'. [c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Servic
e.csproj]
....
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'CoreAudio (>= 1.18.0)' for 'net6.0-windows7.0'.
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'LibreHardwareMonitorLib (>= 0.9.1)' for 'net6.0-windows7.0'.
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'Microsoft.Win32.Registry (>= 5.0.0)' for 'net6.0-windows7.0'.
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'Microsoft.Win32.SystemEvents (>= 6.0.1)' for 'net6.0-windows7.0'.
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'Newtonsoft.Json (>= 13.0.1)' for 'net6.0-windows7.0'.
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'System.Diagnostics.PerformanceCounter (>= 6.0.1)' for 'net6.0-windows7.0'.
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'System.DirectoryServices.AccountManagement (>= 6.0.0)' for 'net6.0-windows7.0'.
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'System.Management (>= 6.0.0)' for 'net6.0-windows7.0'.
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'System.ServiceProcess.ServiceController (>= 6.0.0)' for 'net6.0-windows7.0'.
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'Microsoft.NETCore.App.Ref (= 6.0.22)' for 'net6.0-windows7.0'.
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'Microsoft.WindowsDesktop.App.Ref (= 6.0.22)' for 'net6.0-windows7.0'.
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'Microsoft.AspNetCore.App.Ref (= 6.0.22)' for 'net6.0-windows7.0'.
c:\Temp\HASS.Agent.Staging-test-powershell-sensor-encoding\src\HASS.Agent.Staging\HASS.Agent.Satellite.Service\HASS.Agent.Satellite.Service.csproj : error NU1100: Unable to resolve 'Microsoft.NETCore.App.Host.win-x64 (= 6.0.22)' for 'net6.0-windows7.0'.

The build failed. Fix the build errors and run again.

@amadeo-alex
Copy link

Don't worry :)
Are there any error in the VisualStudio UI before trying to build the project?
I see the PS commandline, just to be sure, have you tried running the command manually or via the VisualStudio UI? (should be the latter)
Please also make sure you have those selected in the VisualStudio Installer:
IfbgRF
Text is in one of my languages but the icons are the same no matter the language :)

@Zarox666
Copy link

This is what I clicked:
image

Not sure where I find the Elements that you shared in your screenshot.
Its it th elist of extensions?
image

Overall it feels to me as if there is something missing in order to resolve / download these dependancies!?

@amadeo-alex
Copy link

Oh, looks like you're trying to open the project in Visual Studio Code (it's a multipurpose "light" IDE).
It may be possible to compile c# projects with it but I've never done it - not the "right tool" for this.
To compile c# project/HASS.Agent you need a Visual Studio - https://visualstudio.microsoft.com/pl/vs/community/
The images that I've added are from the "installer".

@Zarox666
Copy link

Zarox666 commented Sep 14, 2023

I see.... well ya gotta love Microsoft Product Names

With the crappy internet connection installation will take a while.
I try to get it compiled and tested tomorrow.

But now I finaly know where the Screenshot was taken lol

@Skons
Copy link
Author

Skons commented Sep 15, 2023

image
@amadeo-alex here it seems to be fixed :)

@amadeo-alex
Copy link

amadeo-alex commented Sep 15, 2023

Thanks for letting me know @Skons ! Could you please upload part of the logs I mentioned? They should be in the logs folder of satellite service.
They'll tell me which of the possible parameters return sensible values and help with getting the best approach to patch this :D

@Skons
Copy link
Author

Skons commented Sep 15, 2023

I believe this is what you are searching for?

2023-09-15 16:33:36.382 +02:00 [ERR] ENCODING-TEST: currentCulture  {"ANSICodePage":0,"OEMCodePage":1,"MacCodePage":2,"EBCDICCodePage":500,"LCID":4096,"CultureName":"en-NL","IsReadOnly":true,"ListSeparator":",","IsRightToLeft":false}
2023-09-15 16:33:36.383 +02:00 [ERR] ENCODING-TEST: currentUICulture  {"ANSICodePage":1252,"OEMCodePage":437,"MacCodePage":10000,"EBCDICCodePage":37,"LCID":1033,"CultureName":"en-US","IsReadOnly":true,"ListSeparator":",","IsRightToLeft":false}
2023-09-15 16:33:36.383 +02:00 [ERR] ENCODING-TEST: currentInstalledUICulture  {"ANSICodePage":0,"OEMCodePage":1,"MacCodePage":2,"EBCDICCodePage":500,"LCID":4096,"CultureName":"en-NL","IsReadOnly":true,"ListSeparator":",","IsRightToLeft":false}
2023-09-15 16:33:36.383 +02:00 [ERR] ENCODING-TEST: invariantCulture  {"ANSICodePage":0,"OEMCodePage":1,"MacCodePage":2,"EBCDICCodePage":500,"LCID":4096,"CultureName":"en-NL","IsReadOnly":true,"ListSeparator":",","IsRightToLeft":false}
2023-09-15 16:33:36.383 +02:00 [ERR] ENCODING-TEST: first fail
2023-09-15 16:33:36.977 +02:00 [INF] [MQTT] Initial registration completed
2023-09-15 16:33:37.508 +02:00 [ERR] ENCODING-TEST: currentCulture  {"ANSICodePage":0,"OEMCodePage":1,"MacCodePage":2,"EBCDICCodePage":500,"LCID":4096,"CultureName":"en-NL","IsReadOnly":true,"ListSeparator":",","IsRightToLeft":false}
2023-09-15 16:33:37.508 +02:00 [ERR] ENCODING-TEST: currentUICulture  {"ANSICodePage":1252,"OEMCodePage":437,"MacCodePage":10000,"EBCDICCodePage":37,"LCID":1033,"CultureName":"en-US","IsReadOnly":true,"ListSeparator":",","IsRightToLeft":false}
2023-09-15 16:33:37.508 +02:00 [ERR] ENCODING-TEST: currentInstalledUICulture  {"ANSICodePage":0,"OEMCodePage":1,"MacCodePage":2,"EBCDICCodePage":500,"LCID":4096,"CultureName":"en-NL","IsReadOnly":true,"ListSeparator":",","IsRightToLeft":false}
2023-09-15 16:33:37.508 +02:00 [ERR] ENCODING-TEST: invariantCulture  {"ANSICodePage":0,"OEMCodePage":1,"MacCodePage":2,"EBCDICCodePage":500,"LCID":4096,"CultureName":"en-NL","IsReadOnly":true,"ListSeparator":",","IsRightToLeft":false}
2023-09-15 16:33:37.508 +02:00 [ERR] ENCODING-TEST: first fail

@Zarox666
Copy link

I am getting exaclty the same Error Messages when trying to build from Visual Studio:

image

But good that @Skons got it running and can provide feedback.

@Skons
Copy link
Author

Skons commented Sep 15, 2023

@Zarox666 you’ll need to add nuget as a package manager. This url tells you how to add a custom, but in the screens nuget.org is visible
https://learn.microsoft.com/en-us/azure/devops/artifacts/nuget/consume?view=azure-devops&tabs=windows

after adding, the packages are added automatically i believe.

@amadeo-alex
Copy link

Hopefully this time I got if fully right, added the change to both PRs mentioned before :)

@Zarox666
Copy link

Ok,
with the help of NuGet I could build the solution and run it.
The Installer Poped up and I went through it, giving it a different name to distinguish it from the original install.
Afterwards my Sensors where gone and only the Sensors from the Service were still there.
The Error and the Lines in the Logfile remained unchanged.
However I noticed, that it is reconnecting MQTT every second or so.
When checking the version it said its running the BETA.
After exiting HASS Agent and restarting it again and recreating the missing Sensors, all went back to normal...

Not sure if I did something wrong there, but if you are certain enough that you found and fixed the problem, and @Skons seems to be able to confirm... what about porting this fix into the release version?

@Skons
Copy link
Author

Skons commented Sep 18, 2023

I made a backup of the service folder in the program files folder. After copying the new service folder, i could also copy the config folder of the other to the test folder.

@Zarox666
Copy link

Zarox666 commented Oct 4, 2023

Sorry for not responding for so long.
My Server (that is also running HA) died and I had a hard time getting it back up and running.
@amadeo-alex
Are further tests still required or are you good with the logs @Skons was able to provide?

@Zarox666
Copy link

is there any news on this? any ETA when this will be rolled out as update?

@Zarox666
Copy link

has this been implemented by now?

@amadeo-alex
Copy link

Yesn't :D
It will be part of 2.0.0 release very soon but not in this (original repo) but rather here https://github.com/hass-agent where fork development is in progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants