|
| 1 | +# Background |
| 2 | +The WebView2 loader code is what knows where to find and start or connect to already running WebView2 runtimes. This can either be statically linked for C based projects, or is also available as a standalone DLL. For .NET projects they must use the DLL since the loader code is native and we don't have a way to merge the native code into a managed module. Before this change the .NET WebView2 API module would look for the WebView2Loader.dll in the its same folder. But some .NET projects have requirements about where they can place DLLs and so this property is introduced to allow end developers to place the WebView2Loader.dll in any folder and specify the path of 'WebView2Loader.dll' explicitly. |
| 3 | +So we add an API to enable them to specify the path, so that they can use 'WebView2Loader.dll' from any path. |
| 4 | + |
| 5 | +# Description |
| 6 | +We add new static `SetLoaderDllFolderPath` function in `CoreWebView2Environment` class. |
| 7 | +The function allow the end developers to specify the folder's path containing `WebView2Loader.dll`. |
| 8 | + |
| 9 | +# Examples |
| 10 | +## C# |
| 11 | +``` c# |
| 12 | +// Use default path |
| 13 | +Task<CoreWebView2Environment> CreateEnvironmentAsync() |
| 14 | +{ |
| 15 | + // To use default path, just do not call SetLoaderDllFolderPath function or give a empty string:CoreWebView2Environment.SetLoaderDllFolderPath("") will use the default path; |
| 16 | + // The default search path logic is the same as loadlibrary |
| 17 | + return CoreWebView2Environment.CreateAsync(); |
| 18 | +} |
| 19 | + |
| 20 | +// Specify a absolute path |
| 21 | +Task<CoreWebView2Environment> CreateEnvironmentAsync() |
| 22 | +{ |
| 23 | + // Specify a absolute path 'D:\\folder', and there should be a 'WebView2Loader.dll' file in the folder. |
| 24 | + CoreWebView2Environment.SetLoaderDllFolderPath("D:\\folder"); |
| 25 | + return CoreWebView2Environment.CreateAsync(); |
| 26 | +} |
| 27 | + |
| 28 | +// Specify a relative path |
| 29 | +Task<CoreWebView2Environment> CreateEnvironmentAsync() |
| 30 | +{ |
| 31 | + // Specify a relative path 'sub/sub'. The absolute folder path is '%Microsoft.Web.WebView2.Core.dll%\sub\sub', and there should be a 'WebView2Loader.dll' file in the folder. |
| 32 | + CoreWebView2Environment.SetLoaderDllFolderPath("sub\\sub"); |
| 33 | + return CoreWebView2Environment.CreateAsync(); |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +# Remarks |
| 38 | +This function allows you to set the path of the folder containing the `WebView2Loader.dll`. This should be the path of a folder containing `WebView2Loader.dll` and not a path to the `WebView2Loader.dll` file itself. |
| 39 | +Note that the WebView2 SDK contains multiple `WebView2Loader.dll` files for different CPU architectures. When specifying folder path, you must specify one containing a `WebView2Loader.dll` module with a CPU architecture matching the current process CPU architecture. |
| 40 | +This function is used to load the `WebView2Loader.dll` module during calls to any other static methods on `CoreWebView2Environment`. So, the path should be specified before any other API is called in `CoreWebView2Environment` class. Once `WebView2Loader.dll` is successfully loaded this function will throw an InvalidOperationException exception. |
| 41 | +The path can be relative or absolute. Relative paths are relative to the path of the `Microsoft.Web.WebView2.Core.dll` module. |
| 42 | +If the `WebView2Loader.dll` file does not exist in that path or LoadLibrary cannot load the file, or LoadLibrary fails for any other reason, an exception corresponding to the LoadLibrary failure is thrown when any other API is called in `CoreWebView2Environment` class. For instance, if the file cannot be found a `DllNotFoundException` exception will be thrown. |
| 43 | + |
| 44 | +# API Notes |
| 45 | +See [API Details](#api-details) section below for API reference. |
| 46 | + |
| 47 | +# API Details |
| 48 | +## .NET and WinRT |
| 49 | +```c# |
| 50 | +namespace Microsoft.Web.WebView2.Core |
| 51 | +{ |
| 52 | + /// <summary> |
| 53 | + /// Set the path of the folder containing the `WebView2Loader.dll`. |
| 54 | + /// </summary> |
| 55 | + /// <param name="folderPath">The path of the folder containing the `WebView2Loader.dll`.</param> |
| 56 | + /// <exception cref="InvalidOperationException"> |
| 57 | + /// Thrown when `WebView2Loader.dll` has been successfully loaded. |
| 58 | + /// </exception> |
| 59 | + /// <remarks> |
| 60 | + /// This function allows you to set the path of the folder containing the `WebView2Loader.dll`. This should be the path of a folder containing `WebView2Loader.dll` and not a path to the `WebView2Loader.dll` file itself. |
| 61 | + /// Note that the WebView2 SDK contains multiple `WebView2Loader.dll` files for different CPU architectures. When specifying folder path, you must specify one containing a `WebView2Loader.dll` module with a CPU architecture matching the current process CPU architecture. |
| 62 | + /// This function is used to load the `WebView2Loader.dll` module during calls to any other static methods on `CoreWebView2Environment`. So, the path should be specified before any other API is called in `CoreWebView2Environment` class. Once `WebView2Loader.dll` is successfully loaded this function will throw an InvalidOperationException exception. |
| 63 | + /// The path can be relative or absolute. Relative paths are relative to the path of the `Microsoft.Web.WebView2.Core.dll` module. |
| 64 | + /// If the `WebView2Loader.dll` file does not exist in that path or LoadLibrary cannot load the file, or LoadLibrary fails for any other reason, an exception corresponding to the LoadLibrary failure is thrown when any other API is called in `CoreWebView2Environment` class. For instance, if the file cannot be found a `DllNotFoundException` exception will be thrown. |
| 65 | + /// </remarks> |
| 66 | + public static void SetLoaderDllFolderPath(string folderPath); |
| 67 | +} |
| 68 | +``` |
0 commit comments