Base solution for your next web application
Open Closed

Xamarin project and Dotfuscator #5418


User avatar
0
mikatmlvertti created

Hi

Has anyone tried Xamarin project with dotfuscator? We are trying to use Dotfuscator with Android project, but it fails to install on device. When I disable dotfuscator, it installs succesfully.


5 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    might be the same case as yours <a class="postlink" href="https://stackoverflow.com/a/46568547/1767482">https://stackoverflow.com/a/46568547/1767482</a>

  • User Avatar
    0
    mikatmlvertti created

    I have followed those instructions and it builds without errors. When app is started, after splash screen, app crashes. I set dotfuscator to work with debug mode and when LoadApplication(new App()) is being called in MainActivity, it crashes with:

    07-26 08:20:43.405 I/MonoDroid( 5690): UNHANDLED EXCEPTION: 07-26 08:20:43.470 I/MonoDroid( 5690): Xamarin.Forms.Xaml.XamlParseException: Position 1:335. Type Runtime not found in xmlns clr-namespace:_livexaml 07-26 08:20:43.470 I/MonoDroid( 5690): at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.GetRealNameAndType (System.Type& elementType, System.String namespaceURI, System.String& localname, Xamarin.Forms.Xaml.HydrationContext context, System.Xml.IXmlLineInfo lineInfo) [0x0004f] in D:\a\1\s\Xamarin.Forms.Xaml\ApplyPropertiesVisitor.cs:263 07-26 08:20:43.470 I/MonoDroid( 5690): at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.SetPropertyValue (System.Object xamlelement, Xamarin.Forms.Xaml.XmlName propertyName, System.Object value, System.Object rootElement, Xamarin.Forms.Xaml.INode node, Xamarin.Forms.Xaml.HydrationContext context, System.Xml.IXmlLineInfo lineInfo) [0x00066] in D:\a\1\s\Xamarin.Forms.Xaml\ApplyPropertiesVisitor.cs:316 07-26 08:20:43.470 I/MonoDroid( 5690): at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.Visit (Xamarin.Forms.Xaml.ValueNode node, Xamarin.Forms.Xaml.INode parentNode) [0x0006a] in D:\a\1\s\Xamarin.Forms.Xaml\ApplyPropertiesVisitor.cs:57 07-26 08:20:43.470 I/MonoDroid( 5690): at Xamarin.Forms.Xaml.ValueNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00000] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:86 07-26 08:20:43.470 I/MonoDroid( 5690): at Xamarin.Forms.Xaml.RootNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00044] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:200 07-26 08:20:43.470 I/MonoDroid( 5690): at Xamarin.Forms.Xaml.XamlLoader.Visit (Xamarin.Forms.Xaml.RootNode rootnode, Xamarin.Forms.Xaml.HydrationContext visitorContext) [0x0007b] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:143 07-26 08:20:43.470 I/MonoDroid( 5690): at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.String xaml) [0x00058] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:89 07-26 08:20:43.470 I/MonoDroid( 5690): at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.Type callingType) [0x00026] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:67 07-26 08:20:43.470 I/MonoDroid( 5690): at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TXaml] (TXaml view, System.Type callingType) [0x00000] in D:\a\1\s\Xamarin.Forms.Xaml\ViewExtensions.cs:36 07-26 08:20:43.470 I/MonoDroid( 5690): at namespacereplaced.App.b () [0x00001] in <5ebdb37f30e141e3a0a4de5211876276>:0 07-26 08:20:43.470 I/MonoDroid( 5690): at namespacereplaced.App.SavePropertiesAsync () [0x00008] in <5ebdb37f30e141e3a0a4de5211876276>:0 07-26 08:20:43.470 I/MonoDroid( 5690): at namespacereplaced.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0009f] in C:\Projects\uReporting\src\namespacereplaced.Mobile.Droid\MainActivity.cs:51 07-26 08:20:43.470 I/MonoDroid( 5690): at Android.App.Activity.n_OnCreate_Landroid_os_Bundle (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <263adecfa58f4c449f1ff56156d886fd>:0 07-26 08:20:43.470 I/MonoDroid( 5690): at (wrapper dynamic-method) System.Object.899a059f-8de8-419b-85f4-121e56dee9ef(intptr,intptr,intptr) 07-26 08:20:43.489 W/art ( 5690): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable 07-26 08:20:43.493 D/Mono ( 5690): DllImport searching in: '__Internal' ('(null)'). 07-26 08:20:43.493 D/Mono ( 5690): Searching for 'java_interop_jnienv_throw'. 07-26 08:20:43.493 D/Mono ( 5690): Probing 'java_interop_jnienv_throw'. 07-26 08:20:43.494 D/Mono ( 5690): Found as 'java_interop_jnienv_throw'. An unhandled exception occured.

  • User Avatar
    0
    alper created
    Support Team

    Uninstall LiveXamlNuget package. Not needed for your case.

  • User Avatar
    0
    mikatmlvertti created

    Thanks alper, now I got:

    Unhandled Exception *: Castle.MicroKernel.ComponentActivator.ComponentActivatorException: ComponentActivator: could not instantiate namespace_replaced.Views.LoginView ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object. at namespace_replaced.Behaviors.EventHandlerBehavior.b (System.String A_0) [0x00053] in <c7dfb3b24d764a8fad8fbd5300bdb4ed>:0 at namespace_replaced.Behaviors.EventHandlerBehavior.OnAttachedTo (Xamarin.Forms.VisualElement bindable) [0x00010] in <c7dfb3b24d764a8fad8fbd5300bdb4ed>:0 at Xamarin.Forms.Behavior1[T].OnAttachedTo (Xamarin.Forms.BindableObject bindable) [0x00007] in D:\a\1\s\Xamarin.Forms.Core\Interactivity\Behavior.cs:49 at Xamarin.Forms.Behavior.Xamarin.Forms.IAttachedObject.AttachTo (Xamarin.Forms.BindableObject bindable) [0x00027] in D:\a\1\s\Xamarin.Forms.Core\Interactivity\Behavior.cs:23 at Xamarin.Forms.AttachedCollection1[T].InsertItem (System.Int32 index, T item) [0x0002b] in D:\a\1\s\Xamarin.Forms.Core\Interactivity\AttachedCollection.cs:58 at System.Collections.ObjectModel.Collection`1[T].Add (T item) [0x00020] in

    and this works without Dotfuscator. I have selected only Mobile.Shared.dll in dotfuscator input.

  • User Avatar
    0
    alper created
    Support Team

    Hi,

    You have to be careful while using Dotfuscator. Because it removes some classes which it thinks unnecessary. In Xamarin project there ModelViews and Views which have no dependency between. That's why Dotfuscator might think some ModelViews are not used. And it might remove those. I guess you have to write custom rules to exclude ModelViews folder to be obfuscated.