none
How to use Silverlight in ASP.NET 2.0 web project (Visual Studio 2005)

    Question

  • I would like to use the Silverlight in ASP.NET website project with Visual Studio 2005. I know the trick that Scott Louvau mentioned to use the class library project template for that. In my case, I have to use the website project template. I tried to add the System.dll, System.Core.dll, agclr.dll, System.SilverLight.dll, Microsoft.Scripting.dll, Microsoft.Scripting.Silverlight.dll and Microsoft.Scripting.Vestigial.dll in my website project. (As there is no option for "'Do not reference mscorlib.dll'" in website project, I can't do that step.)  then, when I build the application, I got the error below. I tried to remove the mscorlib and system.dll from web.config under this folder "C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG". but this trick doesn't work too.

    Error    1    An assembly with the same identity 'System, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' has already been imported. Try removing one of the duplicate references.       
     

    Any idea would be appreciated. Thanks in advance.

    Sunday, December 02, 2007 11:38 AM

Answers

  • Thanks for reply. You mean that it is not possible to add the silverlight components to website project because they are using the different CLR?

    But the reason why I want this in website project is that I wanna use silverlight with WCSF. seems like I have to compile the files separately. :( (you know, I dislike the commandline.)

    Sunday, December 02, 2007 9:47 PM
  • Hello, here’s how you create a Silverlight and use it in an ASP.NET website:

    1.         Create a Silverlight project. If you want to use VS 2005, you can use the hack above, but you should use a class library project instead of ASP.NET website project.

    2.         Build your Silverlight project.

    3.         Create an ASP.NET website project.

    4.         Create a folder named “ClientBin” in your ASP.NET website.

    5.         Copy the output of your Silverlight project (the dll) to the ClientBin folder in your ASP.NET website.

    6.         Copy the main XAML file and Silverlight.js to the root folder of your ASP.NET website. If you want to use other folders, make sure ClientBin is a direct sub folder of the folder you put the XAML file.

    7.         Add the necessary JavaScript to create the Silverlight plugin in one of the aspx files.

    8.         If you modified the Silverlight project, make sure to copy the dll and XAML file again.

     

    Actually if you have VS 2008 and Silverlight tools, you should be able to use “Add Silverlight Reference” to add a Silverlight project in the ASP.NET website. But currently the public tool has some problems against this feature…

     

    Tuesday, December 04, 2007 12:56 AM

All replies

  • I am not sure about your scenario. But you have to keep the two projects seperate because they both compile against different version of the CLR. Please refer to this thread for more info http://silverlight.net/forums/p/6455/19907.aspx 

    Sunday, December 02, 2007 12:10 PM
  • Thanks for reply. You mean that it is not possible to add the silverlight components to website project because they are using the different CLR?

    But the reason why I want this in website project is that I wanna use silverlight with WCSF. seems like I have to compile the files separately. :( (you know, I dislike the commandline.)

    Sunday, December 02, 2007 9:47 PM
  • Hello, here’s how you create a Silverlight and use it in an ASP.NET website:

    1.         Create a Silverlight project. If you want to use VS 2005, you can use the hack above, but you should use a class library project instead of ASP.NET website project.

    2.         Build your Silverlight project.

    3.         Create an ASP.NET website project.

    4.         Create a folder named “ClientBin” in your ASP.NET website.

    5.         Copy the output of your Silverlight project (the dll) to the ClientBin folder in your ASP.NET website.

    6.         Copy the main XAML file and Silverlight.js to the root folder of your ASP.NET website. If you want to use other folders, make sure ClientBin is a direct sub folder of the folder you put the XAML file.

    7.         Add the necessary JavaScript to create the Silverlight plugin in one of the aspx files.

    8.         If you modified the Silverlight project, make sure to copy the dll and XAML file again.

     

    Actually if you have VS 2008 and Silverlight tools, you should be able to use “Add Silverlight Reference” to add a Silverlight project in the ASP.NET website. But currently the public tool has some problems against this feature…

     

    Tuesday, December 04, 2007 12:56 AM
  • Hi Yi-Lun Luo

    I know this is bit late joining this thread...   :)

    but i would like to know can we deploy silverlight control like we do with flash components.i mean we sipmly add object tag and flash

    component in html page to use flash.can we do same thing with .xap??

    I build a photoviewer in silverlight 2.0; it works perfactly when i run this from visual studio or from localhost.

    now i want to use this control in other ASP.Net websites so i copy the .xap and put that on webserver that host the website

    then in a html page i put that xap in an object tag.

    when i run the application i got this exception

    throw new Error("Silverlight 2 Application Exception: An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()\n at System.Net.OpenReadCompletedEventArgs.get_Result()\n at mpost.SilverlightMultiFileUpload.photoviewer.wc_OpenReadCompleted(Object sender, OpenReadCompletedEventArgs e)\n at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)\n at System.Net.WebClient.OpenReadOperationCompleted(Object arg)");

     what is going wrong ??am i missing something??

     I would appreciate your help.....Thank you

    Friday, January 30, 2009 8:55 AM
  • Yes, you can add a Silverlight app to an existing Web page just by adding the object element to the HTML (for more information, see How to: Add Silverlight to a Web Page by Using HTML) and putting the .xap file and all necessary resources in the correct location on the server.

    The exception you are getting implies that there is some issue with your application trying to retrieve something from the server (photos, perhaps). Be sure that all the server resources that your application requires are present in the location that it expects. If your application is trying to access resources from a different domain from the HTML and .xap file, be sure you have a cross-domain policy file in place. (For more information, see Network Security Access Restrictions in Silverlight 2.)

    Monday, February 02, 2009 3:25 PM
  • Thanks Karl; I made that page working, i published the silverlight project and placed all xap and "DLLs"( which were missing earlier) in website .this worked for me.

    but i am stuck at another point , How can i maintain login sessions in silverlight i mean i can maintain it using isolated storage and i am able to pass information between pages but as soon as i hit F5 everything got lost and i find myself on login screen.is there any way to handle this or i have to live with this??

    Thanks for your help

     Regards

    Akhilesh Bhale

    Tuesday, February 03, 2009 1:43 AM
  • I'm guessing that you are using ASP.NET authentication to manage access to a page that hosts Silverlight. Silverlight should not interfere with ASP.NET authentication, unless maybe there is an issue with the access configuration for the folders that contain the xap file or DLLs. However, this is just a guess - unfortunately I am not familiar enough with ASP.NET authentication to make an informed assessment. I recommend that you ask your question in the ASP.NET forums.

    Wednesday, February 04, 2009 12:32 PM
  • Thanks Karl.as you suggested i put my question on ASP.Net forum.lets see if i get any clue from there.

    once again thank you

    Regards

    Akhilesh bhale

    Thursday, February 05, 2009 12:16 AM