Problem while obfuscation of silverlight .xap

anand.mohananand.mohan Posts: 6
edited July 26, 2013 1:18PM in SmartAssembly
Hi,

I have some issues regarding obfuscating silverlight .xap.
actually in my project there are few third party dlls have been used, so when i am trying to obfuscate my project's xap then after obfuscation when i am hosting it gets blank.
While doing workaround for it I made the replica of that project and when i had excluded the user-control in which the T-Chart dll had been used then its working fine. But here is some more problem that in my project there are some modules in which there is some code parts and also it consists of TChart's dll.
For this I had go through some topics present on the forum where i found that using Custom Attributes we can exclude that code which we don't want to obfuscate but the problem remains same.
Plz. help in this matter.
Anand Mohan

Comments

  • hello sir,
    please reply me as soon as possible its very urgent...



    Thanks:
    Anand Mohan
  • Jessica RJessica R Posts: 1,319 Rose Gold 4
    Hi Anand, many thanks for your post.

    Could you kindly try turning on error reporting to see if you can get more details about what parts of code might need to be excluded?

    Also can you please check--if you run your application through SmartAssembly with all features turned off, does your application still crash/throw errors?

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


  • Thanks Jessica for replying me. I got error message after turning on the error reporting. This message comes when i try to open the child-window the message is as belo-
    " Failed to assign to property 'System.Windows.Controls.Primitives.ButtonBase.Click'. "
    My application is running fine if i run my application through SmartAssembly with all features turned off.
    I had excluded some of the Namespaces which contained third party dll after that i got success in running my application but now the problem is that the child-windows are not getting popped-up and one of my application's page which reads an .xml file using WCF.RIA services, is not getting executed.


    Thanks & Regards:
    Anand Mohan
  • Jessica RJessica R Posts: 1,319 Rose Gold 4
    I'm glad to hear you've got a bit further after adding some exclusions!

    One thing to make sure of: is every member called on by reflection from your XAML files excluded from obfuscation? SmartAssembly will automatically exclude some things from obfuscation to make sure your xaml file still works with your application, but sometimes you may need to manually exclude anything it missed.

    Pruning might also be an issue (if so, you can use the DoNotPrune attribute to exclude any types in question from pruning ). Are you using this feature by any chance?

    Also, just to confirm, did those exclusions you added resolve the "failed to assign to property" error? If not, it sounds like there is an event handler that you'll need to exclude from obfuscation (http://stackoverflow.com/questions/5482 ... ilverlight)

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


  • Hi Jessica, below is my sample project code in this i had added a hyperlink button and a button & on the click of it i am trying to open a child window.
    It is running fine without obfuscation but after obfuscation its not getting popped-up. Please look into this,
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    
    namespace Child_Window
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, RoutedEventArgs e)
            {        
                demo objdemo = new demo();
                objdemo.Show();
            }
    
            private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
            {
                demo objdemo = new demo();
                objdemo.Show();
            }
        }
    }
    

    XAML,
    <UserControl x:Class="Child_Window.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
    
        <Grid x:Name="LayoutRoot" Background="White">
            <HyperlinkButton Content="Click to Open Smart Assembly" Height="23" HorizontalAlignment="Left" Margin="108,79,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="175" Click="hyperlinkButton1_Click" />
            <Button Content="Click to Open Smart Assembly" Height="23" HorizontalAlignment="Left" Margin="92,147,0,0" Name="button1" VerticalAlignment="Top" Width="191" Click="button1_Click" />
        </Grid>
    </UserControl>
    


    Thanks & Regards:
    Anand Mohan
  • Jessica RJessica R Posts: 1,319 Rose Gold 4
    Many thanks for the sample project! Can you please try excluding the event handlers "hyperlinkButton1_Click" and "button1_Click" from being obfuscated?

    When they are obfuscated, they no longer can be found by the original names they are referenced by in the XAML. This is what causes the "failed to assign to property" error.

    You can either add the exclusion from the SmartAssembly UI or by using the custom attributes - http://www.red-gate.com/supportcenter/c ... Attributes

    I hope that helps! Please give it a try and let me know if there are any further issues.

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


  • Thanks a lot Jessica,
    It worked for me, now my application is running fine after obfuscating the xap. But still there is an issue present that when i am reflecting the obfuscated xap then the variables & fields are still present with their real names.
    Plz. look into this so that i will be able to fully obfuscate my xap which will increase its reliability in terms of code protection.


    Thanks & Regards:
    Anand Mohan
  • Jessica RJessica R Posts: 1,319 Rose Gold 4
    I'm glad to hear that got the application working! I think I may be working with one of your colleagues who mentioned the same issue with the names.. I explained to him that SmartAssembly automatically excludes some code if it determines that obfuscation might cause your application not to work, or if a string might be displayed in the user interface.

    The following types are always excluded from obfuscation to ensure that your application works correctly:
    -Public members of DLLs
    -Types with the Serializable attribute.
    -Types with a base class of System.MulticastDelegate.
    -Types with System.ServiceModel.OperationContractAttribute specified.
    -Types with System.ServiceModel.ServiceContractAttribute specified.
    -Types with any attribute starting System.Xml.Serialization.
    -Methods with System.Reflection.DefaultMemberAttribute specified.

    Also..
    -Enums are normally obfuscated, but SmartAssembly assumes that enum values which have Format, GetName, GetNames, Parse, or ToString called on them will be displayed to users. These enums are therefore excluded from obfuscation automatically.
    -If a member name is the same in one more than one class, the member names might not be renamed. To ensure that they are renamed, under Obfuscation, select the Advanced renaming fields name mangling option.
    (Note that selecting Advanced renaming prevents Decode Stack Trace from retrieving the names of the original fields.)

    To see why SmartAssembly has not obfuscated your code, you can create a log file in 'TRACE' mode. For more information, see Log file for SmartAssembly.

    Hope this information helps!

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


Sign In or Register to comment.