본문 바로가기
C#

[C#] Webview2 STATUS_INVALID_IMAGE_HASH 오류 해결

by Jcoder 2021. 7. 26.

오류
이벤트 뷰어 확인

 

Endpoint Protector\csprnthk.dll that did not meet the Microsoft signing level requirements.

 

보안 프로그램으로 인해 실행이 안 되는 것을 확인할 수 있다.

위 오류를 Google에서 찾으면 

https://answers.microsoft.com/en-us/microsoftedge/forum/all/microsoft-edge/8b600ac0-e077-4244-a97e-076a25fdd746

 

Microsoft Edge

When I try and start edge I get this error: Error code: STATUS_INVALID_IMAGE_HASH When I go and look into this error via Event Viewer this is what I get Code Integrity determined that a process

answers.microsoft.com

https://techcommunity.microsoft.com/t5/discussions/dev-channel-update-to-88-0-673-0-is-live/m-p/1800811/page/2

 

Dev channel update to 88.0.673.0 is live

Hello Insiders!  Today we’re releasing build 88.0.673.0 to the Dev channel.  As you can see, this is the first build from major version 88, and it’s a very special build, because it marks our first release for Linux to the Dev channel!  For all the

techcommunity.microsoft.com

Server 2012 R2 Test project not working. · Issue #675 · MicrosoftEdge/WebView2Feedback (github.com)

 

Server 2012 R2 Test project not working. · Issue #675 · MicrosoftEdge/WebView2Feedback

Description Can't get a small test WPF project to work on server 2012. Comes up in a blank window. It works fine in windows 10 Here is the XAML:

github.com

위와 같이 나오는데 보통 사용자에게 런타임으로 배포를 하기 때문에 C:\Program Files (x86)\Microsoft\EdgeWebView\Application\92.0.902.55\msedgewebview2.exe 에 옵션을 넣어주면 되지 않을까 생각했다.

하지만 winform, wpf에서 로드를 하면서 명령어를 줄 수 있기 때문에 아래 코드처럼 new CoreWebView2EnvironmentOptions("--disable-features=RendererCodeIntegrity") 을 넣어주고 실행하면

CoreWebView2Environment coreWebView2Environment = await CoreWebView2Environment.CreateAsync(null, null, new CoreWebView2EnvironmentOptions("--disable-features=RendererCodeIntegrity"));
await webView21.EnsureCoreWebView2Async(coreWebView2Environment);

2022-04-08

- userControl로 사용시

public partial class uc_Webview2 : UserControl
{
    private readonly WebView2 _webView2 = new WebView2();
    private bool isInitWebView2 = false;

    public uc_Webview2()
    {
        InitializeComponent();

        this.AutoScaleMode = AutoScaleMode.Dpi;
        this.Controls.Add(_webView2);
        _webView2.Dock = DockStyle.Fill;
    }

    protected override void OnHandleDestroyed(EventArgs e)
    {
        base.OnHandleDestroyed(e);
        _webView2.Dispose();
    }

    private async Task SetCoreWebView2EnvironmentAsync()
    {
        // RendererCodeIntegrity -> 보안 프로그램 무시
        // PreloadMediaEngagementData,AutoplayIgnoreWebAudio,MediaEngagementBypassAutoplayPolicies -> 자동 재생 정책 무시
        var coreWebView2Environment = await CoreWebView2Environment.CreateAsync(null, null, new CoreWebView2EnvironmentOptions("--disable-features=RendererCodeIntegrity,PreloadMediaEngagementData,AutoplayIgnoreWebAudio,MediaEngagementBypassAutoplayPolicies"));
        await _webView2.EnsureCoreWebView2Async(coreWebView2Environment);

        isInitWebView2 = true; // 보안 프로그램 무시 초기화 옵션으로 인해 중복 초기화 에러 방지를 위한 플래그.
    }

    public async Task NavigateToUri(string url)
    {
        if (string.IsNullOrEmpty(url))
            return;

        try
        {
            if (!isInitWebView2)
                await SetCoreWebView2EnvironmentAsync();

            _webView2.CoreWebView2.Navigate(url);
        }
        catch (Exception e)
        {
            StaticLogManager.WriteLog($"NavigateToUri() Exception message : {e.Message}");
        }
    }

    public void ReloadPage()
    {
        if (!string.IsNullOrEmpty(_webView2.Source.AbsoluteUri))
            _webView2.CoreWebView2.Reload();
    }
}

 

 

실행

 

Webview2가 정상적으로 로드된 것을 확인할 수 있다

'C#' 카테고리의 다른 글

[C#] Get HttpStatusCode Message  (0) 2021.08.02
[C#] Webview2 API POST 하기  (0) 2021.07.27
[C#] IP 변경  (0) 2021.07.25
[C#] Everything SDK 사용  (0) 2021.07.25
[C#] Slack Message 보내기  (0) 2021.06.01