Giter VIP home page Giter VIP logo

Comments (4)

minren118 avatar minren118 commented on June 30, 2024

the error image below
image

System.Runtime.InteropServices.COMException
HResult=0x80004004
Message=已中止操作 (异常来自 HRESULT:0x80004004 (E_ABORT))
Source=mscorlib
StackTrace:
在 System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
在 Microsoft.Web.WebView2.Core.CoreWebView2Environment.d__98.MoveNext()
在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
在 Microsoft.Web.WebView2.WinForms.WebView2.d__25.MoveNext()
在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter.GetResult()
在 MyCustomTaskPane.d__2.MoveNext() 在 D:\VisualStudio项目\EasyShu\WebView2Test\MyCustomTaskPane.cs 中: 第 28 行

此异常最初是在此调用堆栈中引发的:
[外部代码]
MyCustomTaskPane.InitializeWebView2() (位于 MyCustomTaskPane.cs 中)

from exceldna.

andrewkittredge avatar andrewkittredge commented on June 30, 2024

This is the code we use to instantiate the webView2

        private static async Task<CoreWebView2Environment> WebView2EnvironmentAsync()
        {
            if (webView2Environment == null)
            {
                Environment.SetEnvironmentVariable("COREWEBVIEW2_FORCED_HOSTING_MODE", "COREWEBVIEW2_HOSTING_MODE_WINDOW_TO_VISUAL"); // https://github.com/MicrosoftEdge/WebView2Feedback/issues/951#issuecomment-1064624832
                string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                string cacheFolder = Path.Combine(localAppData, "WindowsFormsWebView2");
                LogDisplay.RecordLine($"Available Browser Version String is {CoreWebView2Environment.GetAvailableBrowserVersionString()}, cache folder is {cacheFolder}");
                webView2Environment = await CoreWebView2Environment.CreateAsync(null, cacheFolder);
                LogDisplay.RecordLine($"CoreWebView2Environment is {webView2Environment}");
            }

            return webView2Environment;
        }
            WebView2 webView21;
            var environment = await WebView2EnvironmentAsync();
            await webView21.EnsureCoreWebView2Async(environment);

from exceldna.

minren118 avatar minren118 commented on June 30, 2024

This is the code we use to instantiate the webView2

        private static async Task<CoreWebView2Environment> WebView2EnvironmentAsync()
        {
            if (webView2Environment == null)
            {
                Environment.SetEnvironmentVariable("COREWEBVIEW2_FORCED_HOSTING_MODE", "COREWEBVIEW2_HOSTING_MODE_WINDOW_TO_VISUAL"); // https://github.com/MicrosoftEdge/WebView2Feedback/issues/951#issuecomment-1064624832
                string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                string cacheFolder = Path.Combine(localAppData, "WindowsFormsWebView2");
                LogDisplay.RecordLine($"Available Browser Version String is {CoreWebView2Environment.GetAvailableBrowserVersionString()}, cache folder is {cacheFolder}");
                webView2Environment = await CoreWebView2Environment.CreateAsync(null, cacheFolder);
                LogDisplay.RecordLine($"CoreWebView2Environment is {webView2Environment}");
            }

            return webView2Environment;
        }
            WebView2 webView21;
            var environment = await WebView2EnvironmentAsync();
            await webView21.EnsureCoreWebView2Async(environment);

I user the above code,but also fail ,my windows is win11,so Environment.SetEnvironmentVariable("COREWEBVIEW2_FORCED_HOSTING_MODE", "COREWEBVIEW2_HOSTING_MODE_WINDOW_TO_VISUAL"); is not necessary ,thanks anything

from exceldna.

minren118 avatar minren118 commented on June 30, 2024

I found out why. I didn't give MyCustomTaskPane a [ComVisible(true)] attribute. I made a stupid mistake, sorry

from exceldna.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.