Xamarin.Forms.Xaml.XamlParseException: MarkupExtension not found for trans:Translate using a PCL in Release Mode
I'm pretty desperate finding the solution for the problem stated below.
I have a cross platform solution which has 4 projects,
3 OS specifics
MyApp.android,
MyApp.Winphone,
MyApp.IOS
and a PCL project
MyApp.BLL
inside the MyApp.BLLbll, I'm using the MyApp namespace and in the root I have the class 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; } }
inside the Xamarin Forms I'm using the following to enable the translation for the labels, etc.
<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,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>
This is working like a charm using the debug modus, but when I try to compile the solution for Android in release mode, my application is suddenly stopping directly after loading the splashscreen stating 'MyApp is stopped'
looking in the Application output, I can find the following error message:
[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(NativeMethod)[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
Does any body has a solution for this problem? I can't find it. I have tried using the several namespaces ( MyApp.android, MyApp, MyApp.BLL, MyApp.MyApp ), but until now I haven't found the right one.
Why is this working in Debug mode and not in Release/App store mode?
Check the project settings, make sure linking is turned off or SDK-ony
.
If it was "Link all assemblies" and without it your code becomes too big you may want to instead use the [Preserve]
attribute on your class.
See this page for more info on Xamarin Linker
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
2012-08-06 未能在指定文件夹中创建本地存储区,请选择其他位置。可以检查事件日志以了解详细信息
2010-08-06 SQL Server 2000 安装错误,解决方法 Process Exit Code: (1060) 指定的服务未安装
2010-08-06 SQLServer无法安装-提示command line option syntax error
2010-08-06 SQL未能排它地锁定数据库以执行该操作解决
2010-08-06 MS SQL 2000 安全设置
2010-08-06 SQL日志文件丢失,只有MDF恢复