Bryant Likes's Blog

It's all about WebData

Recent Posts

Tags

News


  • Windows Live Alerts
    View Bryant Likes's profile on LinkedIn

    Me

    The posts on this weblog are provided "as is" with no warranties and confer no rights. The opinions expressed herin are the personal opinions of the individual authors and do not represent the views of Avanade in any way.

Community

Email Notifications

Archives

Silverlight Hello World in C# from VS 2005

Well I've been downloading the VS Orcas for a few days and it still isn't done. I really wanted to try out the .NET support in Silverlight 1.1 and so I asked if this could be done with VS 2005 and Scott Louvau replied:

Well, in VS2005 you can create a class library which will build against the Silverlight runtime, but it's a little work.

1. Create a Class Library.
2. Remove all references from it.
3. Right-click on the Project and pick Properties.
4. On the Build tab, click Advanced and check 'Do not reference mscorlib.dll'
5. Manually add references to mscorlib, agclr, System, System.Core, System.Silverlight, and System.Xml.Core from the Silverlight install folder (\Program Files\Microsoft Silverlight\)

At this point your build outputs should be Silverlight consumable binaries. It looks like the equivalent command line call to csc.exe (the C# compiler) should include the references to the mentioned binaries and the /nostdlib option but may require others as well.

 -Scott

I tried it out and it work pretty well. If you're interested I've uploaded my project so that you can download it and try it out. You will need Silverlight 1.1 installed and VS studio 2005.

Download the sample code here

I've also posted the code to my server but I couldn't figure out how to setup IIS to allow DLL files to be downloaded. Maybe tomorrow.

Comments

Community Silverlight content said:

Well I've been downloading the VS Orcas for a few days and it still isn't done. I really wanted

# May 2, 2007 8:36 AM

Luis Abreu said:

Hello.

I've noticed that on win xp pro (IIS5) the dll and xaml extensions aren't mapped on the MIME type list. On IIS 7, i have the following:

dll application/x-msdownload

xaml application/xaml+xml

i tried hosting a demo site built from the quickstarts and it run, so I'm assuming that at least these 2 extensions must be inserted on the MIME type list...

# May 2, 2007 11:02 AM

bituman said:

Dont you happen to know how to switch to fullscreen in c#?

# May 2, 2007 4:35 PM

BonGeek's Blog said:

Check this out fellas! Rightnow I am running Orcas using my VPC and tell you the truth, I really don

# May 2, 2007 9:57 PM

Philip said:

Great post!

All the .NET part works just fine. The problem is I don't feel like editing all the xaml by hand so I have downloaded Expression Blend to edit the xaml. Now when I try to edit the page.xaml file in Blend I get an error saying that page.xaml contains invalid XAML. I assume this is because I don't have that extension for Orcas to enable Silverlight app creation. I have noticed that Blend and Orcas seem to be really tightly coupled... Anyways, question is can I still use Blend with VS2005.

Thanx

# May 3, 2007 7:45 AM

Scott said:

Phillip,

Are you using Expression Blend 2? I got the same error when I tried using Expression Blend instead of EB 2.

# May 3, 2007 10:09 AM

John Lam said:

You can download Expression Blend 2 May CTP here:

http://www.microsoft.com/expression/products/download.aspx?key=blend2maypreview

I use an old version (internal drop from a friend) to do most of my XAML exploration and it works great.

# May 3, 2007 4:08 PM

Philip said:

Scott,

Thanks for pointing out the version issue. This is probably what my problem is. I have noticed that I run version 1.0 Blend (I got it from a friend who claimed this was the latest one). I am getting a May preview now. Hopefully it will work.

# May 4, 2007 1:27 AM

Philip said:

Bryant,

I have seen your posts on migrating from SL 1.0 to 1.1 where you mentioned the difference in usage of CreateFromXaml method. I am having problems figuring out how to use that method in my .NET code. I have posted my question on the SilverLight forum but haven't got an answer yet... Any ideas?

http://silverlight.net/forums/t/694.aspx

# May 4, 2007 10:49 AM

Joycode@Ab110.com said:

如果你想尝试开发 Silverlight 1.1 应用,又对下载/安装推荐的Visual Studio Orcas Beta 1有点怕怕的话,你可以使用Visual Studio 2005和 Expression

# May 5, 2007 11:17 PM

Lawrence McAlpin said:

So, I was trying to play around with Silverlight and my anti-virus program starts freaking out saying I have a trojan horse. Apparently, it doesn't like some of the file names (like Default.html.js), claiming that the files have a hidden file extension

# May 6, 2007 8:42 PM

Victor said:

I downloaded the new VS Codename Orcas Beta 1 but when it tries to install .NET3.5 it gives me "Setup Failed" Error.  Anyone have a fix for this?  Please email me at victor@rezn8.com

Thanks, Victor

# May 7, 2007 1:46 PM

ASP.NET Chinese Blogs said:

如果你想尝试开发 Silverlight 1.1 应用,又对下载/安装推荐的Visual Studio Orcas Beta 1有点怕怕的话,你可以使用Visual Studio 2005和 Expression

# May 9, 2007 8:44 AM

Dinesh Chaudhari said:

Hi Scott,

I created a class library as you said in above . But how i used this class library in creating SilverLight Application ,Can you explain the steps in after creating library what to do for creating silver Light hello World application.

Thanks

# May 11, 2007 4:48 AM

Michael's Blog said:

Could Silverlight 1.1 assemblies be generated with Visual Studio .NET 2005? Well, if you read the GetStarted

# June 5, 2007 9:17 AM

abot said:

I have posted the same code in vb. The challenge was to trick the vb compiler not to reference the default Microsoft.VisualBasic.dll. The post is in http://botsikas.blogspot.com/2007/06/silverlight-with-visual-studio-net-2005.html

PS: I added a contribution to you if you don’t mind…

# June 15, 2007 6:29 AM

East said:

之前发过一篇《 使用Visual Studio 2005开发Silverlight 》的文章,主要讲述的是如何配置VS2005开发Silverlight1.0的应用。之后有很多朋友问到如何能够在VS2005中开发Silverlight1.1的应用得问题,下面做一个详细的介绍。

# June 18, 2007 12:24 PM

Jeff Wilcox's Blog on Microsoft UIFx said:

As the Silverlight tools story is still young (Visual Studio 2008 really is looking amazing though),

# June 18, 2007 6:44 PM

deedee.brainstream.net said:

# June 22, 2007 4:21 AM

A said:

Hello :

I got a problem , when I run this project as your said, a error message popup

"ErrorCode: 2252

ErrorType: ParserError

Message: AG_E_RUNTIME_MANAGED_ASSEMBLY_DOWNLOAD

XamlFile: Page.xmal

Line: 7

Position: 9"

How to do?

Thanks.

# June 28, 2007 12:27 AM

MomOn said:

i got this error message too

"ErrorCode: 2252

ErrorType: ParserError

Message: AG_E_RUNTIME_MANAGED_ASSEMBLY_DOWNLOAD

XamlFile: Page.xmal

Line: 7

Position: 9"

# July 3, 2007 1:57 AM

steve said:

same error

"ErrorCode: 2252

ErrorType: ParserError

Message: AG_E_RUNTIME_MANAGED_ASSEMBLY_DOWNLOAD

XamlFile: Page.xmal

Line: 7

Position: 9"

# July 4, 2007 2:58 AM

Michael said:

I got almost exactly the same error as the last three people, only difference is mine has Page.xaml instead of Page.xmal.

Has anyone found a solution?

# July 12, 2007 5:25 AM

Mike Mattox said:

In regards to the error of:

"ErrorCode: 2252

ErrorType: ParserError

Message: AG_E_RUNTIME_MANAGED_ASSEMBLY_DOWNLOAD

XamlFile: Page.xmal

Line: 7

Position: 9"

I believe that for one, the mime types of .dll and .xaml will have to be entered into IIS if they are not, and with this 1.1 version of Silverlight, the x:Class attribute has to have the assembly mapped in relation to the page that is serving the control.  In my case, I mapped the mime types and then changed it in the Page.xaml file from

 x:Class="HelloSilverlight.Page;assembly=HelloSilverlight.dll"

to

 x:Class="HelloSilverlight.Page;assembly=bin/debug/HelloSilverlight.dll"

and that seemed to serve this sample fine from my xp sp2 machine running VS2005 and IIS 5.1.

# July 16, 2007 12:40 PM

singlewind said:

I have the same problem too when I use a silverlight user control in a silverlight page.

And I think the reference in page.xaml is correct.

# July 19, 2007 11:27 PM

beatniks said:

I don't understand what to do after I've followed steps 1-5

# July 27, 2007 2:54 PM

Amitava Shee said:

It really means that the browser failed to download the managed assembly "HelloSilverlight.dll" referenced in page.xaml.

Here's the resolution

1. Add a "File Type" of .dll -> application/ms-download. Go to inetmgr-><app>->Properties->HTTP Headers->File Types->New Type.

2. Map .dll files to asp.net. inetmgr-><app>->Properties->Virtual Directory->Configuration->Add. Add "c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll" to ".dll".

Please note that I am using IIS 5 in XP sp2.

# August 2, 2007 7:35 AM

dotnetuncle said:

It works for me. Just a few changes I made.

# August 21, 2007 2:34 AM

Rahul vyas said:

please tell me step by step configuration of IIS

i am having vs 2005 with sp1,Win XP pro sp2,Silverlight 1.1 alpha refresh.

now how do i run your "HELLO WORLD" sample code.

and also tell me that how u create this hello world application.

# August 24, 2007 12:32 AM

Atiq said:

Hi, Any way of getting the Silverlight tools in Visual Studio 2005 ... i downloaded the SDK but it says Visual Studio 2008 required

# September 19, 2007 11:24 PM

Xeenix said:

Check out http://ox.no/posts/silverlight-project-template-for-visual-studio-2005 for a template for creating Silverlight 1.0/1.1 projects under VS2005.

# October 9, 2007 7:11 AM

Liu Xudong said:

I have the same question about err 2252

First you should confirm your dll path is right.

eg: x:Class="SilverlightCSApplication3.Page;assembly=clientbin/SilverlightCSApplication3.dll"

you must have SilverlightCSApplication3.dll in clientbin fold.

if you didn't have dll file ,you could build solution, VS 2005 will build a dll file named SilverlightCSApplication3.dll.

After these step above,SilverLight will work.

I have make a solution.

# October 15, 2007 10:25 PM

debug1984 said:

XP pro+sp2

vs 2005+sp1

iis 5.1

the SL seems doesn't work well on this platform.

I've downloaded lots of source code,some of the JS project works well,But none of the C# projects works.

perfect? could you tell us about your platform?

I am suffering silverlight...

# October 19, 2007 2:44 AM

Shan said:

Hi,

I've only vs 2005 and .net 3.0 in my pc.

I'm getting following error.

Error 2 The type or namespace name 'Canvas' could not be found (are you missing a using directive or an assembly reference?) C:\Download\SilverLight\HelloSilverlight\HelloSilverlight\Page.xaml.cs 8 33 HelloSilverlight

# November 2, 2007 7:48 AM

oasisfleeting said:

I get the same error Shan.

using System.Windows.Controls

        (namespace could not be found)

public partial class Page : Canvas

        (namespace could not be found)

I recently reformated and reinstalled Visual Studio 05. I really hope to get this working. I'm someone who cant afford a copy of Visual Studio 08 after the beta runs out.

# November 17, 2007 11:20 AM

Regan said:

To fix the 'Canvas' could not be found error:

Right-click on your xaml file in Solution Explorer -> Open With -> select XML Editor (Default).

# December 20, 2007 2:04 PM

r2r said:

have the same error 2252.

i have created a usercontrol project(silverlight) and tried to link it in my existing aspnet project(2008-orca)

envoking my control to a xmal file in aspx;

syntax;

xmlns:LightControl="clr-namespace:LightControl;assembly=ClientBin/IXSLightControl.dll"

I add it using the silverlight link way...

then error 2252!!!!!!.

then i tried to reference it directly to my project

still the same error..

im i missing something???????

# December 27, 2007 1:43 AM

BladeMaster said:

首先介绍silverlight中文社区的网址:http://silverlight.cn,里面还挺好的。

# January 1, 2008 7:14 PM

paan said:

Hi Scott,

I created a class library as you said in above . But how i used this class library in creating SilverLight Application ,Can you explain the steps in after creating library what to do for creating silver Light hello World application.

Thanks

# January 10, 2008 3:00 AM

Silverlight北京开发团队 said:

一位热忠于Microsoft Silverlight的外国朋友BLOG: http://blogs.sqlxml.org/bryantlikes/archive/2007/05/02/silverlight-hello-world-in-c-from-vs-2005.aspx 有入门的Hello的download下载,大家有时间可以去看看,挻有意思:)

# February 2, 2008 11:25 PM

marjoan de guzman said:

hi,

i already installed silverlight 1.1 as well as the SDK but i do not have the following in (\Program Files\Microsoft Silverlight):

agclr.dll

System.Silver.dll

System.Xml.Core.dll

Can you help me with this? thanks!

my email is: marjiepie@gmail.com

# March 14, 2008 12:51 AM

salman said:

please Help ? how to use Silver Light 2 Beta in vs 2005????

Please answer

# May 15, 2008 12:30 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)