单核细胞增多症。 Xamarin。加载 svg 图像时出错。 System.MethodAccessException
Mono. Xamarin. Error loading svg images. System.MethodAccessException
我正在使用 Xamarin 开发移动应用程序,运行 时出现错误。
该错误经常发生,但并非总是如此。
我正在 Sumsung Galaxy S6 上进行测试。
我正在使用的代码(位于渲染器中):
new SvgReader(new StreamReader(svgStream),
new StylesParser(new ValuesParser()),
new ValuesParser());
Xamarin 版本:
- Xamarin 4.2.0.680
- Xamarin.Android 7.0.0.18
异常:
ERROR: System.MethodAccessException: Method `System.Xml.Linq.XContainer:ReadContentFrom (System.Xml.XmlReader)' is inaccessible from method `System.Xml.XmlReader:get_DtdInfo ()'
at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_throw_method_access (intptr,intptr)
at System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader r) [0x001a0] in /Users/builder/data/lanes/3511/f4db8a57/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:3073
at System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader r, System.Xml.Linq.LoadOptions o) [0x00008] in /Users/builder/data/lanes/3511/f4db8a57/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:3090
at System.Xml.Linq.XDocument.Load (System.Xml.XmlReader reader, System.Xml.Linq.LoadOptions options) [0x0009b] in /Users/builder/data/lanes/3511/f4db8a57/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:5747
at System.Xml.Linq.XDocument.Load (System.IO.TextReader textReader, System.Xml.Linq.LoadOptions options) [0x0000f] in /Users/builder/data/lanes/3511/f4db8a57/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:5693
at System.Xml.Linq.XDocument.Load (System.IO.TextReader textReader) [0x00000] in /Users/builder/data/lanes/3511/f4db8a57/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:5666
at NGraphics.Custom.Parsers.SvgReader..ctor (System.IO.TextReader reader, NGraphics.Custom.Parsers.IStylesParser stylesParser, NGraphics.Custom.Parsers.IValuesParser valuesParser) [0x0001f] in <c787e3d8c9e842909bf317040008966c>:0
如何解决错误?
坏消息,这似乎包含在以下 Xamarin bugzilla 帖子中:
- https://bugzilla.xamarin.com/show_bug.cgi?id=44134; (重复)
- https://bugzilla.xamarin.com/show_bug.cgi?id=41133
这是此异常的 Xamarin 描述。
https://developer.xamarin.com/api/type/System.MethodAccessException/
现在,我建议实施这些论坛中建议的解决方法,以简单地捕获异常并继续(遗憾...)。
我一直随机收到 Method 'System.Xml.XmlReader:get_DtdInfo ()' is inaccessible
异常,直到我删除了 gfx 编辑器倾向于放在那里的文档类型和 xmlns 中的所有多余内容。
以前,我的 SVG 文件看起来像这样..
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
<!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/">
<!ENTITY ns_ai "http://ns.adobe.com/AdobeIllustrator/10.0/">
<!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/">
<!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/">
<!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacement/1.0/">
<!ENTITY ns_sfw "http://ns.adobe.com/SaveForWeb/1.0/">
<!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNamespace/1.0/">
<!ENTITY ns_adobe_xpath "http://ns.adobe.com/XPath/1.0/">]>
<svg version="1.1" id="Layer_1" xmlns:x="&ns_extend;" xmlns:i="&ns_ai;" xmlns:graph="&ns_graphs;"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
<metadata>
<sfw xmlns="&ns_sfw;">
<slices></slices>
<sliceSourceBounds width="427.66" height="361.922" x="42.17" y="-436.961" bottomLeftOrigin="true"></sliceSourceBounds>
</sfw>
</metadata>
<g>
...
但我删除了所有不必要的东西,直到我得到...
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
<g>
...
随机崩溃对我来说消失了。复杂 dtd/xmlns 一定会吓坏 lib。
我正在使用 Xamarin 开发移动应用程序,运行 时出现错误。
该错误经常发生,但并非总是如此。
我正在 Sumsung Galaxy S6 上进行测试。
我正在使用的代码(位于渲染器中):
new SvgReader(new StreamReader(svgStream),
new StylesParser(new ValuesParser()),
new ValuesParser());
Xamarin 版本:
- Xamarin 4.2.0.680
- Xamarin.Android 7.0.0.18
异常:
ERROR: System.MethodAccessException: Method `System.Xml.Linq.XContainer:ReadContentFrom (System.Xml.XmlReader)' is inaccessible from method `System.Xml.XmlReader:get_DtdInfo ()'
at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_throw_method_access (intptr,intptr)
at System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader r) [0x001a0] in /Users/builder/data/lanes/3511/f4db8a57/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:3073
at System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader r, System.Xml.Linq.LoadOptions o) [0x00008] in /Users/builder/data/lanes/3511/f4db8a57/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:3090
at System.Xml.Linq.XDocument.Load (System.Xml.XmlReader reader, System.Xml.Linq.LoadOptions options) [0x0009b] in /Users/builder/data/lanes/3511/f4db8a57/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:5747
at System.Xml.Linq.XDocument.Load (System.IO.TextReader textReader, System.Xml.Linq.LoadOptions options) [0x0000f] in /Users/builder/data/lanes/3511/f4db8a57/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:5693
at System.Xml.Linq.XDocument.Load (System.IO.TextReader textReader) [0x00000] in /Users/builder/data/lanes/3511/f4db8a57/source/mono/mcs/class/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs:5666
at NGraphics.Custom.Parsers.SvgReader..ctor (System.IO.TextReader reader, NGraphics.Custom.Parsers.IStylesParser stylesParser, NGraphics.Custom.Parsers.IValuesParser valuesParser) [0x0001f] in <c787e3d8c9e842909bf317040008966c>:0
如何解决错误?
坏消息,这似乎包含在以下 Xamarin bugzilla 帖子中:
- https://bugzilla.xamarin.com/show_bug.cgi?id=44134; (重复)
- https://bugzilla.xamarin.com/show_bug.cgi?id=41133
这是此异常的 Xamarin 描述。
https://developer.xamarin.com/api/type/System.MethodAccessException/
现在,我建议实施这些论坛中建议的解决方法,以简单地捕获异常并继续(遗憾...)。
我一直随机收到 Method 'System.Xml.XmlReader:get_DtdInfo ()' is inaccessible
异常,直到我删除了 gfx 编辑器倾向于放在那里的文档类型和 xmlns 中的所有多余内容。
以前,我的 SVG 文件看起来像这样..
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
<!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/">
<!ENTITY ns_ai "http://ns.adobe.com/AdobeIllustrator/10.0/">
<!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/">
<!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/">
<!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacement/1.0/">
<!ENTITY ns_sfw "http://ns.adobe.com/SaveForWeb/1.0/">
<!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNamespace/1.0/">
<!ENTITY ns_adobe_xpath "http://ns.adobe.com/XPath/1.0/">]>
<svg version="1.1" id="Layer_1" xmlns:x="&ns_extend;" xmlns:i="&ns_ai;" xmlns:graph="&ns_graphs;"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
<metadata>
<sfw xmlns="&ns_sfw;">
<slices></slices>
<sliceSourceBounds width="427.66" height="361.922" x="42.17" y="-436.961" bottomLeftOrigin="true"></sliceSourceBounds>
</sfw>
</metadata>
<g>
...
但我删除了所有不必要的东西,直到我得到...
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
<g>
...
随机崩溃对我来说消失了。复杂 dtd/xmlns 一定会吓坏 lib。