2017-01-11 30 views
1

我發展與Xamarin移動應用程序和運行時,它得到一個錯誤。
錯誤常常但並不總是發生。
我在三星的Galaxy S6測試它。單聲道。 Xamarin。加載svg圖像時出錯。 System.MethodAccessException

,我使用的代碼(位於渲染器):

  • Xamarin 4.2.0.680
  • Xamarin.Android 7.0.0.18
:版本

new SvgReader(new StreamReader(svgStream), 
       new StylesParser(new ValuesParser()), 
       new ValuesParser()); 

Xamarin

例外:

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 

如何解決這個錯誤?

回答

2

我一直得到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嚇跑。

+0

非常感謝,它幫助了我。 – nikelyn

0

壞消息,這將出現在以下Xamarin Bugzilla的帖子被覆蓋:

  1. https://bugzilla.xamarin.com/show_bug.cgi?id=44134; (的式兩份)
  2. https://bugzilla.xamarin.com/show_bug.cgi?id=41133

這裏是Xamarin說明對這一異常。

https://developer.xamarin.com/api/type/System.MethodAccessException/

現在,我會建議實施的變通建議在這些論壇上簡單地捕獲異常,並繼續前進(可悲...)。

+0

該錯誤被標記爲NEEDINFO,這意味着沒有客戶能夠提供一個好的測試用例; @nikelyn請聯繫Xamarin團隊,讓他們測試您的應用程序,不要放置解決方法,否則這將永遠不會得到解決 – ympostor