<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: WebView2 throws System.Runtime.InteropServices.COMException: 'The requested resource is in use. (0x800700AA)' in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/webview2-throws-system-runtime-interopservices-comexception-the/m-p/13423440#M1214</link>
    <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;@&lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/15843072" target="_self"&gt;&lt;SPAN class=""&gt;christev7HTEL&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp;Thank you for sharing your solution. It saved my time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;userDataFolder&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;Path&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;Combine&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Environment&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;GetFolderPath&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Environment&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;SpecialFolder&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;LocalApplicationData&lt;/SPAN&gt;&lt;SPAN&gt;), &lt;/SPAN&gt;&lt;SPAN&gt;"MonacoEditorTest"&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Sun, 13 Apr 2025 13:51:41 GMT</pubDate>
    <dc:creator>tnx2u2</dc:creator>
    <dc:date>2025-04-13T13:51:41Z</dc:date>
    <item>
      <title>WebView2 throws System.Runtime.InteropServices.COMException: 'The requested resource is in use. (0x800700AA)'</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/webview2-throws-system-runtime-interopservices-comexception-the/m-p/13291882#M1212</link>
      <description>&lt;P&gt;Just wanted to post some info on a _bug_ I've come across + fix. Maybe no one will run into this problem, but it took me a while to get to the bottom of.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It started with trying to use Auth0 in a Revit application, but the default implementation throws the exception and Revit crashes:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;System.Runtime.InteropServices.COMException: 'The requested resource is in use. (0x800700AA)'&lt;/LI-CODE&gt;&lt;P&gt;Now it is possible to fix this by instantiating your client with a `WebBrowserBrowser`:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;IBrowser browser = new WebBrowserBrowser();

client = new Auth0Client(new Auth0ClientOptions
{
Domain = domain,
ClientId = clientId,
RedirectUri = "http://localhost:3003",
PostLogoutRedirectUri = "http://localhost:3003",
Browser = browser
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or even &lt;A href="https://melmanm.github.io/misc/2023/03/04/article7-auth0-destkop-application-authentication-with-system-browser.html?" target="_blank" rel="noopener"&gt;creating an implementation&lt;/A&gt; to try to use the default `SystemBrowser`&lt;/P&gt;&lt;P&gt;but I still wanted WebView2 here. And it turns out the prickly bit of code boils down to the default environment that is created. Generally, when you are generating a WebView2 within an application, you should call the following code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
System.IO.Directory.CreateDirectory(appDataFolder);
var env = await CoreWebView2Environment.CreateAsync(null, appDataFolderACAD);
await webView.EnsureCoreWebView2Async(env);&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;It's important to create the environment or else the default implementation will register a data folder running out of a secured folder that can't write like Program Files..&lt;/P&gt;&lt;P&gt;And this was what happened to me. WebView2 in Revit was trying to create a directory at:&lt;BR /&gt;`C:\Program Files\Autodesk\Revit 2025\Revit.exe.WebView2\`&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which aside from being an absolute eye-sore, requires admin privileges to write to, and thus the resource cannot be used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As someone new to WebView2 this really tripped me up, so here's to hoping it will help someone else at some point too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I created a custom `UserEnvironmentWebViewBrowser` where the `UserDataFolder` can be set, and defaults to appdata. (This is by and large identical to the `WebViewBrowser` implementation, with the addition of the aforementioned):&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public class UserEnvironmentWebViewBrowser : IBrowser
{
private readonly Func&amp;lt;Window&amp;gt; _windowFactory;

private readonly bool _shouldCloseWindow;

public UserEnvironmentWebViewBrowser(Func&amp;lt;Window&amp;gt; windowFactory, bool shouldCloseWindow = true)
{
_windowFactory = windowFactory;
_shouldCloseWindow = shouldCloseWindow;
}

public UserEnvironmentWebViewBrowser(string title = "Authenticating...", string? userDataFolder = null, int width = 1024, int height = 768)
: this(() =&amp;gt; new Window
{
Name = "WebAuthentication",
Title = title,
Width = width,
Height = height
})
{
if (userDataFolder != null &amp;amp;&amp;amp; Directory.Exists(userDataFolder))
{
UserDataFolder = userDataFolder;
}
}

public string UserDataFolder { get; set; } = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

public async Task&amp;lt;BrowserResult&amp;gt; InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default(CancellationToken))
{
TaskCompletionSource&amp;lt;BrowserResult&amp;gt; tcs = new TaskCompletionSource&amp;lt;BrowserResult&amp;gt;();
Window window = _windowFactory();
WebView2 webView = new WebView2();
window.Content = webView;
webView.NavigationStarting += delegate (object? sender, CoreWebView2NavigationStartingEventArgs e)
{
if (e.Uri.StartsWith(options.EndUrl))
{
tcs.SetResult(new BrowserResult
{
ResultType = BrowserResultType.Success,
Response = e.Uri.ToString()
});
if (_shouldCloseWindow)
{
window.Close();
}
else
{
window.Content = null;
}
}
};
window.Closing += delegate
{
webView.Dispose();
if (!tcs.Task.IsCompleted)
{
tcs.SetResult(new BrowserResult
{
ResultType = BrowserResultType.UserCancel
});
}
};
window.Show();

var webView2Environment = await CoreWebView2Environment.CreateAsync(null, UserDataFolder);
await webView.EnsureCoreWebView2Async(webView2Environment);
webView.CoreWebView2.Navigate(options.StartUrl);
return await tcs.Task;
}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also check out the solution at my &lt;A href="https://github.com/bulgos/RevitWebView2Bug" target="_blank" rel="noopener"&gt;github&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;shoutout to&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1070920"&gt;@grahamcook&lt;/a&gt;&amp;nbsp;as I found the answer within his &lt;A href="https://forums.autodesk.com/t5/net/using-the-webviewer2-package-version-issues/m-p/12941602" target="_blank" rel="noopener"&gt;post&lt;/A&gt;.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2025 23:25:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/webview2-throws-system-runtime-interopservices-comexception-the/m-p/13291882#M1212</guid>
      <dc:creator>christev7HTEL</dc:creator>
      <dc:date>2025-01-30T23:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: WebView2 throws System.Runtime.InteropServices.COMException: 'The requested resource is in use. (0x800700AA)'</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/webview2-throws-system-runtime-interopservices-comexception-the/m-p/13300944#M1213</link>
      <description>&lt;P&gt;Thank you for sharing this interesting challenge and solution. I added it to the blog and hope it helps others as well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2025/02/tools-for-extensible-storage-and-oauth-auth0.html#4" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/2025/02/tools-for-extensible-storage-and-oauth-auth0.html#4&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2025 10:29:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/webview2-throws-system-runtime-interopservices-comexception-the/m-p/13300944#M1213</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2025-02-05T10:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: WebView2 throws System.Runtime.InteropServices.COMException: 'The requested resource is in use. (0x800700AA)'</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/webview2-throws-system-runtime-interopservices-comexception-the/m-p/13423440#M1214</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;@&lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/15843072" target="_self"&gt;&lt;SPAN class=""&gt;christev7HTEL&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp;Thank you for sharing your solution. It saved my time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;userDataFolder&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;Path&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;Combine&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Environment&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;GetFolderPath&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Environment&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;SpecialFolder&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;LocalApplicationData&lt;/SPAN&gt;&lt;SPAN&gt;), &lt;/SPAN&gt;&lt;SPAN&gt;"MonacoEditorTest"&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 13 Apr 2025 13:51:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/webview2-throws-system-runtime-interopservices-comexception-the/m-p/13423440#M1214</guid>
      <dc:creator>tnx2u2</dc:creator>
      <dc:date>2025-04-13T13:51:41Z</dc:date>
    </item>
  </channel>
</rss>

