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

Console sink throws error on initialization when used in VSCode PS integrated console preview #3

Open
gitbute opened this issue Jun 12, 2020 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@gitbute
Copy link
Contributor

gitbute commented Jun 12, 2020

Hi there

First up, cool module you have here!
I ran into following error upon installing v 2.0.0 from powershellgallery,
and trying to use it in VSCodes Powershell integrated console:

(PowerShell 5.1, Server 2016,
=====> PowerShell Preview Integrated Console v2020.6.1 <=====)

New-Logger |
    Add-SinkFile -Path 'C:\Data\my_awesome.log' |
    Add-SinkConsole |
    Start-Logger
Cannot find an overload for "Console" and the argument count: "7".
At C:\Program Files\WindowsPowerShell\Modules\PoshLog\2.0.0\functions\sinks\Add-SinkConsole.ps1:50 char:3
+         $LoggerConfig = [Serilog.ConsoleLoggerConfigurationExtensions ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

It works in the normal console tho

@gitbute gitbute changed the title Console sink throws error on initialization Console sink throws error on initialization when used in VSCode PS integrated console Jun 12, 2020
@gitbute gitbute changed the title Console sink throws error on initialization when used in VSCode PS integrated console Console sink throws error on initialization when used in VSCode PS integrated console preview Jun 12, 2020
@TomasBouda TomasBouda self-assigned this Jun 12, 2020
@TomasBouda TomasBouda added the bug Something isn't working label Jun 12, 2020
@TomasBouda
Copy link
Member

Hi,
thanks for testing PoShLog. I've seen this issue before, but I'm not sure what's causing it. I will dig deeper and hopefully i will resolve that. I know how it's anoying 😢.
Until it's resolved you can try to switch to Powershell 7.0 in VS Code.
image

@TomasBouda
Copy link
Member

TomasBouda commented Jun 14, 2020

After spening couple of hours trying to find out what is going on, I unfotunately did not find the root cause. The issue is definitely connected to VS Code as this issue shows only there. I tryed powershell 5.1, 7.0, x86 and x64 versions, outside VS Code and everything worked like charm.
At the and I at least found solution 😏I ran following snippet:

[appdomain]::currentdomain.getassemblies() | ?{$_.CodeBase -match "Console"}

and I noticed that Serilog.Sinks.Console.dll is not in GAC.

GAC    Version        Location
---    -------        --------
True   v4.0.30319     C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.ConsoleHost\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.ConsoleHost.dll
False  v4.0.30319     C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Serilog.Sinks.Console\v4.0_3.1.1.0__24c2f752a8e58a10\Serilog.Sinks.Console.dll
True   v4.0.30319     C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Console\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Console.dll

So I opened Developer Command Prompt for VS 2019 and ran(Change your path to dll, before running following snippet)

gacutil /i "C:\PoShLog\lib\Serilog.Sinks.Console.dll"

to add Serilog.Sinks.Console.dll to GAC, restarted VS Code and that exception saying "Cannot find an overload for..." disappeared!
Hope this helps 👍

Edit
Here is link how to add dll into GAC with powershell:
https://www.andrewcbancroft.com/2015/12/16/using-powershell-to-install-a-dll-into-the-gac/

#Note that you should be running PowerShell as an Administrator
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")            
$publish = New-Object System.EnterpriseServices.Internal.Publish            
$publish.GacInstall("C:\Path\To\DLL.dll")

@TomasBouda TomasBouda pinned this issue Jun 15, 2020
@TomasBouda TomasBouda unpinned this issue Jun 15, 2020
@digitalcardboard
Copy link

digitalcardboard commented Jun 21, 2021

For anyone that needs a quick resolution to this, as of v2.1.1 use the following:

#Note that you should be running PowerShell as an Administrator
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")            
$publish = New-Object System.EnterpriseServices.Internal.Publish            
$publish.GacInstall("C:\Program Files\WindowsPowerShell\Modules\PoShLog\2.1.1\lib\Serilog.Sinks.Console.dll")
$publish.GacInstall("C:\Program Files\WindowsPowerShell\Modules\PoShLog\2.1.1\lib\Serilog.Sinks.File.dll")
$publish.GacInstall("C:\Program Files\WindowsPowerShell\Modules\PoShLog\2.1.1\lib\Serilog.dll")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants