c# - Image.FromFile() 或 FromStream() 在 GdiplusStartup 上挂起

标签 c# .net mono xamarin

我有一个包含这一行的简单 C# 应用程序:

var mImage = System.Drawing.Image.FromFile(filename);

在 Windows (.NET) 上运行此代码时,图像会正确加载。 在 OS X (Mono) 上运行相同的代码时,应用程序会挂起。调试器永远留在那个调用中。无一异常(exception)。

调用堆栈显示应用程序挂起于:

System.Drawing.GDIPlus.GdiplusStartup ()

这里会出什么问题?

PS:我安装了最新版本的 Xamarin Studio 和 Mono。

最佳答案

1) 不仅要检查您是否拥有最新的 Xamarin Studio 版本,还要检查您是否拥有最新版本!!!

错误报告:

这个问题是由 Troy Dawson 使用 Xamarin Studio Version 5.5 (build 198) 报告的,就在一个多月前:https://bugzilla.xamarin.com/show_bug.cgi?id=23444

"With the latest Mono from the alpha release channel, attached project should raise an typenotfound exception when run at:

var image = Image.FromStream(content);

Because GDIPlus can't be initialized or something.

This is similar to another bug I filed where Image.FromStream() takes a very long time to return when Mono is first run."

完全异常:

An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.Exception: GdiplusStartup

解决方案:

在 2014-09-29 报告错误后的第二天,Sadik Ali 确认他可以重现该问题 Comment 1 ,然后 4 天后,Troy Dawson 确认Xamarin Studio 版本 5.5(内部版本 227)修复了该问题 Comment 2 .


2) 如果最新版本仍然失败,我建议您检查限制并确保支持您加载的图像: https://github.com/mono/libgdiplus/blob/master/TODO

关于c# - Image.FromFile() 或 FromStream() 在 GdiplusStartup 上挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26894157/

相关文章:

c# - 如何模拟一个只读属性,其值取决于 Mock 的另一个属性

c# - 如何在 Metro 应用程序中关闭 WebView

c# - C# WebBrowser Control 和我电脑上安装的 IE 有什么关系?

.net - 如何使用 Unity DI 加载具有依赖项的程序集,然后注册内部组件

c# - 如何在没有 ASPX 的情况下在 C# 中创建 Web 框架?

mono - linux 上的 RavenDB 客户端使用单声道 http 连接到 windows 服务器

c# - 从嵌入式资源更改 Gtk.Button 图像

c# - 输入显示空白而不是零

c# - System.Timers 定时器不触发事件

c# - 暂停/恢复异步任务的模式?