Pages

Wednesday, April 25, 2012

Load assemblies with different versions

Basically we can load only the same version of assemblies into the application. But i need the requirement like , i have one WPF application and also having Class library. My class library will be having the version 5.0 of assemblies and my exe project will be having the 3.0 version of assemblies.
To execute the above requirement , we should do the following steps very carefully.

1. Add app.config file in the application:-

When we create the WPF application by default we will not be having app.config file in the application as like in the Asp.Net project. But we can achieve this by doing the couple of steps.
i) Right click in the project properties and choose ApplicationConfiguration file and the name should be App.config [ not App1.config as it suggests].

ii) Add Reference to the application

then finally it will execute the app.config settings to the current application.

2. Add the following settings in the app.config file:-

We can load the assemblies with the different versions in to the project by the following syntax. We can learn more details in the below msdn link.
http://msdn.microsoft.com/en-us/library/15hyw9x3(v=vs.100).aspx

The following syntax should be added in the app.config file.
<configuration>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="A.wpf.dll" publicKeyToken="3d67ed1f87d44c89" />
        <codeBase version="3.0" href="...\A.wpf.dll"/>
        <codeBase version="5.0" href="...\A.wpf.dll"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="B.wpf.dll" publicKeyToken="632609b4d040f6b4" />
        <codeBase version="3.0" href="...\B.wpf.dll"/>
        <codeBase version="5.0" href="...\B.wpf.dll"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

By the above syntax i just want to add A.wpf.dll and B.wpf.dll in the respective project. Public key token needs to be added for the corresponding assembly.
We can generate the public key token by executing the following commands in the visual studio command prompt.
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin   sn.exe -T  [ assembly name ].
Wow...Finally my try gave success and everything works fine. So everyone can load the assemblies with the different versions now...

Sunday, April 15, 2012

Silverlight Printing

Silverlight printing will be pretty easy when compare to WPF for single and Multiple pages. PrintDocument plays the vital role to print the pages of the document.

Actually PrintDocument class provides 3 events to completely work with the Silverlight Printing.

PrintDocument document = new PrintDocument();
document.PrintPage += new EventHandler<PrintPageEventArgs>(document_PrintPage);
document.EndPrint += new EventHandler<EndPrintEventArgs>(document_EndPrint);
document.BeginPrint += new EventHandler<BeginPrintEventArgs>(document_BeginPrint);
document.Print("Print Document");

1.BeginPrint:-

BeginPrint will be used to determine the pages to be printed for the document. It just prepares the UI before to print the document.

2. PrintPage:-

It has the PageVisual property in the PrintPageEventArgs. It will just decide the current page visual to be printed.

3. EndPrint:-

EndPrint will release all the resources which have been prepared while begin print event is triggered.

The above events will be getting triggered only when we call the Print("") method. Once this method is called Printing will be started to print all the available pages in the document depend upon of BeginPrint event.