我有一个跨平台解决方案,有4个项目,
3个 *** 作系统细节
MyApp.android,
MyApp.Winphone,
MyApp.IOS
和一个PCL项目
MyApp.BLL
在MyApp.BLLbll中,我正在使用MyApp命名空间,在根目录中我有TranslateExtension.cs类
namespace MyApp{ [contentproperty("Text")] public class TranslateExtension: IMarkupExtension{ Readonly CultureInfo ci; const string ResourceID = "MyApp.Resources.AppResource"; public TranslateExtension() { ci = DependencyService.Get<ILocalize>().GetCurrentCultureInfo(); } public string Text { get; set; } public object ProvIDeValue(IServiceProvIDer serviceProvIDer) { if (Text == null) return ""; ResourceManager resmgr = new ResourceManager(ResourceID,typeof(TranslateExtension).GetTypeInfo().Assembly); var translation = resmgr.GetString(Text,ci); try { if (translation == null) {#if DEBUG throw new ArgumentException( String.Format("Key '{0}' was not found in resources '{1}' for culture '{2}'.",Text,ResourceID,ci.name),"Text");#else translation = Text; // Hack: returns the key,which GETS disPLAYED TO THE USER#endif } } catch (Exception exp) { } return translation; }}
在Xamarin Forms中,我使用以下内容来启用标签的翻译等.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MyApp.VIEws.RegisterWebServiceXaml" xmlns:trans="clr-namespace:MyApp;assembly=MyApp.BLL" IsBusy="{Binding IsWorking}" > <ContentPage.Content> <StackLayout OrIEntation="Vertical" VerticalOptions="FillAndExpand" padding="0,75,0"> <Entry Text="{Binding Path=OrganizationID,Mode=TwoWay}" Placeholder="{trans:Translate OrganizationID}" Style="{StaticResource LoginStyle}" /> ... <Label Text="{trans:TranslateUpper Next}" x:name="LoginLabel" HorizontalOptions="Center" Style="{StaticResource BasicLabel}" /> </StackLayout> </ContentPage.Content></ContentPage>
这就像使用调试模式的魅力一样,但是当我尝试在发布模式下编译AndroID解决方案时,我的应用程序在加载启动画面后突然停止,说明“MyApp已停止”
查看应用程序输出,我可以找到以下错误消息:
[Xamarin.Insights] Warning: Unhandled exception: Xamarin.Forms.Xaml.XamlParseException: MarkupExtension not found for trans:Translate[Xamarin.Insights] at System.Runtime.ExceptionServices.ExceptiondispatchInfo.Throw () <0x00028>[Xamarin.Insights] at System.Runtime.CompilerServices.AsyncmethodBuilderCore.<ThrowAsync>m__0 (object) <0x0003f>[Xamarin.Insights] at AndroID.App.SyncContext/<Post>c__AnonStorey0.<>m__0 () <0x00027>[Xamarin.Insights] at java.lang.Thread/RunnableImplementor.Run () <0x0003f>[Xamarin.Insights] at java.lang.IRunnableInvoker.n_Run (intptr,intptr) <0x0003b>[Xamarin.Insights] at (wrapper dynamic-method) object.44dc0140-8f03-4bf1-a261-186aa2a7ef42 (intptr,intptr) <0x0003b>[art] JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable[AndroIDRuntime] Shutting down VM[AndroIDRuntime] FATAL EXCEPTION: main[AndroIDRuntime] Process: MyApp.MyApp,PID: 32091[AndroIDRuntime] java.lang.RuntimeException: java.lang.reflect.InvocationTargetException[AndroIDRuntime] at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:1184)[AndroIDRuntime] Caused by: java.lang.reflect.InvocationTargetException[AndroIDRuntime] at java.lang.reflect.Method.invoke(Native Method)[AndroIDRuntime] at java.lang.reflect.Method.invoke(Method.java:372)[AndroIDRuntime] at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)[AndroIDRuntime] ... 1 more[AndroIDRuntime] Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: Xamarin.Forms.Xaml.XamlParseException: MarkupExtension not found for trans:Translate[AndroIDRuntime] at System.Runtime.ExceptionServices.ExceptiondispatchInfo.Throw () <0x00028>[AndroIDRuntime] at System.Runtime.CompilerServices.AsyncmethodBuilderCore.<ThrowAsync>m__0 (object) <0x0003f>[AndroIDRuntime] at AndroID.App.SyncContext/<Post>c__AnonStorey0.<>m__0 () <0x00027>[AndroIDRuntime] at java.lang.Thread/RunnableImplementor.Run () <0x0003f>[AndroIDRuntime] at java.lang.IRunnableInvoker.n_Run (intptr,intptr) <0x0003b>[AndroIDRuntime] at (wrapper dynamic-method) object.44dc0140-8f03-4bf1-a261-186aa2a7ef42 (intptr,intptr) <0x0003b>[AndroIDRuntime] [AndroIDRuntime] at mono.java.lang.RunnableImplementor.n_run(Native Method)[AndroIDRuntime] at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)[AndroIDRuntime] at androID.os.Handler.handleCallback(Handler.java:739)[AndroIDRuntime] at androID.os.Handler.dispatchMessage(Handler.java:95)[AndroIDRuntime] at androID.os.Looper.loop(Looper.java:145)[AndroIDRuntime] at androID.app.ActivityThread.main(ActivityThread.java:5944)[AndroIDRuntime] ... 4 more
有没有人能解决这个问题呢?我找不到它.我已经尝试使用几个名称空间(MyApp.androID,MyApp,MyApp.BLL,MyApp.MyApp),但直到现在我还没找到合适的名称空间.
为什么这在调试模式下工作而不在发布/应用商店模式下?
解决方法 检查项目设置,确保关闭链接或SDK-ony.
如果它是“链接所有程序集”而没有它,则代码变得太大,您可能希望改为使用类上的[Preserve]属性.
有关Xamarin linker的更多信息,请参阅this page
总结以上是内存溢出为你收集整理的c# – Xamarin.Forms.Xaml.XamlParseException:找不到trans的MarkupExtension:在发布模式下使用PCL进行翻译全部内容,希望文章能够帮你解决c# – Xamarin.Forms.Xaml.XamlParseException:找不到trans的MarkupExtension:在发布模式下使用PCL进行翻译所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)