Select to view content in your preferred language

SilverPDF dll make Xap file bigger RSS

1394
3
Jump to solution
07-09-2012 03:02 PM
ForamParikh
Regular Contributor
Hello everyone,

I know it is something related to silverlight i just post it if anybody has answer then he or she can help me.

everything is working fine in my application but I noticed that XAP file is getting bigger and bigger I have used silverpdf.dll which size is around 2 mb if i remove it from project than xap file will reduce by 800 kb.but i am using many methods of that dll.I create class library but the xap file is same

so any body know that how to add third party dll in reference with out changing xap file size?

Please help,

Thanks

Foram
0 Kudos
1 Solution

Accepted Solutions
JoeHershman
MVP Alum
Hello everyone,

I know it is something related to silverlight i just post it if anybody has answer then he or she can help me.

everything is working fine in my application but I noticed that XAP file is getting bigger and bigger I have used silverpdf.dll which size is around 2 mb if i remove it from project than xap file will reduce by 800 kb.but i am using many methods of that dll.I create class library but the xap file is same

so any body know that how to add third party dll in reference with out changing xap file size?

Please help,

Thanks

Foram


There is no way to do that.  The xap contains all the assemblies you reference.  It needs to be there otherwise your application would not run.  A Silverlight application runs inside the Silverlight plugin on the clients machine.  All assemblies required by the application must, therefore, be downloaded to the client machine.  There are ways to break things into multiple Xap files so it only downloads what it needs when it needs it, but that is a pure (advanced) Silverlight discussion which you could try to search MSDN or other Silverlight sites for.
Thanks,
-Joe

View solution in original post

0 Kudos
3 Replies
JoeHershman
MVP Alum
Hello everyone,

I know it is something related to silverlight i just post it if anybody has answer then he or she can help me.

everything is working fine in my application but I noticed that XAP file is getting bigger and bigger I have used silverpdf.dll which size is around 2 mb if i remove it from project than xap file will reduce by 800 kb.but i am using many methods of that dll.I create class library but the xap file is same

so any body know that how to add third party dll in reference with out changing xap file size?

Please help,

Thanks

Foram


There is no way to do that.  The xap contains all the assemblies you reference.  It needs to be there otherwise your application would not run.  A Silverlight application runs inside the Silverlight plugin on the clients machine.  All assemblies required by the application must, therefore, be downloaded to the client machine.  There are ways to break things into multiple Xap files so it only downloads what it needs when it needs it, but that is a pure (advanced) Silverlight discussion which you could try to search MSDN or other Silverlight sites for.
Thanks,
-Joe
0 Kudos
ForamParikh
Regular Contributor
Thanks Joe Hershman
0 Kudos
hcgis
by
Deactivated User
HI Foram
you can do it by putting the silverPDF.dll in clientbin folder and call it when needed like this
AssemblyPart apSilverPDF;
System.IO.Stream PDFStream;

        /// <summary>
        /// Load the silverPDF library if it hasn't been loaded already
        /// or use the library if already loaded        
        /// </summary>
        public void LoadPDFLibraryAndSaveFile()
        {
            SaveFileDialog savePDF = new SaveFileDialog();
            savePDF.Filter = "PDF file format|*.pdf";
            savePDF.DefaultExt = ".pdf";
            if (savePDF.ShowDialog() == true)
            {
                //catch the error if the user tries to save over a file that is currently open
                try
                {
                    PDFStream = savePDF.OpenFile();
                    //if silverPDF library is not loaded already, load it
                    if (apSilverPDF == null)
                    {
                        LoadPDFLibrary();
                    }
                    else
                    {
                        //if the library is loaded, just save the PDF file
                        SavePDF();
                    }
                }
                catch (IOException ioe)
                {
                    //tell the user the file is open
                    MessageBox.Show("Selected PDF file is open. Close the file and try again!", "Open File Error", MessageBoxButton.OK);
                }
            }
        }

        /// <summary>
        /// Send a request to load the silverPDF library dynamically
        /// </summary>
        private void LoadPDFLibrary()
        {
            WebClient client = new WebClient();
            client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
            Uri _uri = new Uri("silverPDF.dll", UriKind.Relative);
            client.OpenReadAsync(new Uri("silverPDF.dll", UriKind.Relative));
        }

        /// <summary>
        /// Load the library and use it to create the PDF
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            if ((e.Error == null) && (e.Cancelled == false))
            {
                apSilverPDF = new AssemblyPart();
                apSilverPDF.Load(e.Result);

                SavePDF();
            }
            else
            {
                MessageBox.Show("There was a problem loading PDF Library", "PDF Library Loading Error", MessageBoxButton.OK);
            }
        }



tell me if it works
0 Kudos