簡體   English   中英

在我的 F# 應用程序中實例化 WebBrowser 控件時出現異常

[英]I get an exception when I instantiate a WebBrowser Control in my F# app

我正在嘗試在我的 F# 應用程序中實例化 WebBrowser 控件:

open System;;
open System.Net.Http;;
open System.Windows.Forms;;
...
let browser =
    new WebBrowser(ScriptErrorsSuppressed = true,
                   Dock = DockStyle.Fill,
                   DocumentText = fsharpOrg.Result)

但我得到了這個例外:

System.IO.FileLoadException: **Could not load file or assembly 'System.Drawing.Common**, Version=6.0.0.0,...

我正在使用 dotnet sdk 版本 6.0.100。 我在論壇和文檔中搜索了答案或類似問題,但我沒有找到可以引導我解決問題的東西。 我們將不勝感激任何見解。

不要在代碼中使用#r ,只在腳本文件中使用。

發生錯誤是因為運行時試圖在 output 文件夾中找到System.Drawing.Common ,例如bin/debug/net6.0/ ,但不在C:/Program Files/dotnet/shared/...

要修復錯誤,您應該:

  1. 創建項目文件,
  2. <UseWindowsForms>true</UseWindowsForms>添加到<PropertyGroup>中,因此項目將如下所示:
<Project Sdk="Microsoft.Net.SDK">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <OutputType>winexe<OutputType>
    <UseWindowsForms>true</UseWindowsForms> <!-- all magic in this line -->
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>
</Project>
  1. MSBuild 將解析所有必要的引用,您將能夠運行程序

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM