MonoTouch:在iPhone版本上使用嵌入式resx文件

时间:2010-01-20 02:45:25

标签: iphone resources xamarin.ios embedded-resource

我可以在使用MonoTouch构建的iPhone应用程序的模拟器版本中加载和访问resx文件。 csproj文件中的resx文件条目如下所示:

  <ItemGroup>
    <EmbeddedResource Include="MapMenu\Resources\MapMenu.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>MapMenu.Designer.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>

.resx文件本身有一个这样的条目:

  <data name="Main_Menu" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>Main Menu.mm;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
  </data>

生成的MapMenu.Designer.cs文件包含:

    internal static string Main_Menu {
        get {
            return ResourceManager.GetString("Main_Menu", resourceCulture);
        }
    }

如上所述,调用Main_Menu访问器在模拟器上运行正常。但是,在设备上,它会产生:

<Notice>: Unhandled Exception: System.MissingMethodException: No constructor found for System.Resources.RuntimeResourceSet::.ctor(System.IO.UnmanagedMemoryStream)
<Notice>:   at System.Activator.CreateInstance (System.Type type, BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x00000] in <filename unknown>:0 
<Notice>:   at System.Activator.CreateInstance (System.Type type, System.Object[] args, System.Object[] activationAttributes) [0x00000] in <filename unknown>:0 
<Notice>:   at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in <filename unknown>:0 
<Notice>:   at System.Resources.ResourceManager.InternalGetResourceSet (System.Globalization.CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) [0x00000] in <filename unknown>:0 
<Notice>:   at System.Resources.ResourceManager.GetString (System.String name, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0  
<Notice>:   at MapMenu.Resources.MapMenu.get_Main_Menu () [0x00000] in <filename unknown>:0 

进行了一些健全性检查,并且我想知道Monotouch中是否真的缺少功能。

谢谢,

1 个答案:

答案 0 :(得分:1)

它看起来像链接器中的一个错误,它删除了一个只能通过资源加载器代码反射调用的构造函数。作为解决方法,您可以禁用链接器(如果直接使用mtouch,则使用-nolink,或者通过在MonoDevelop中指定链接器选项。

file a bug