[英]I get an exception when I instantiate a WebBrowser Control in my F# app
I am trying to instantiate a WebBrowser control within my F# application:我正在尝试在我的 F# 应用程序中实例化 WebBrowser 控件:
open System;;
open System.Net.Http;;
open System.Windows.Forms;;
...
let browser =
new WebBrowser(ScriptErrorsSuppressed = true,
Dock = DockStyle.Fill,
DocumentText = fsharpOrg.Result)
But I get this exception:但我得到了这个例外:
System.IO.FileLoadException: **Could not load file or assembly 'System.Drawing.Common**, Version=6.0.0.0,...
I am using dotnet sdk version 6.0.100.我正在使用 dotnet sdk 版本 6.0.100。 I have searched for answers or similar problems in forums and documentation, but I have not found something that can lead me to the fix.
我在论坛和文档中搜索了答案或类似问题,但我没有找到可以引导我解决问题的东西。 Any insight we'll be appreciated.
我们将不胜感激任何见解。
Don't use #r
in code, use it only in script files.不要在代码中使用
#r
,只在脚本文件中使用。
Error occurs because runtime tries to find System.Drawing.Common
inside output folder, eg bin/debug/net6.0/
, but not in C:/Program Files/dotnet/shared/...
发生错误是因为运行时试图在 output 文件夹中找到
System.Drawing.Common
,例如bin/debug/net6.0/
,但不在C:/Program Files/dotnet/shared/...
To fix error you should:要修复错误,您应该:
<UseWindowsForms>true</UseWindowsForms>
into <PropertyGroup>
, so project will look like this:<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.