Fix for Could not download the Silverlight application error

by APIJunkie 8/2/2008 10:08:00 AM

If you receive the following error:  Could not download the Silverlight application. Check web server settings.

The problem might be the fact that the .xap mime type is not registered on the IIS server you are using.

If you have control over your server then you can just register the missing mime type.

If you are not that lucky you might need to find a workaround like the one below.

The idea is based on an older solution for Silverlight 1.0 and xaml files.

Since the problem is do to the fact that xap is not a registered mime type, we can cheat a little by creating an http handler that will handle requests for xap files.

The http handler will deliver the content of the xap file using a mime type that is known to the server. 

Since a xap file is actually a zip file we can use that mime type as the delivery content type.

Example:

Create a new class file called HttpXapHandler.cs.

Copy the following code to the file and add the file to your App_Code directory.

/// <summary>

/// HttpXapHandler class - handle requests to xap file through a back door nick named x-zip-compressed.

/// </summary>

public class HttpXapHandler : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

// get file name from request query string

string fileName = context.Request["fileName"];

// check if the file is valid -> its up to you to validate in a way that makes sense to you...

if (!validateFile(fileName))

{

context.Response.Write(
"<br>Bad file request<br>");

context.Response.End();

}

// set mime type to zip file because a xap file is actually a zip file

context.Response.ContentType = "application/x-zip-compressed";

context.Response.TransmitFile(context.Server.MapPath(fileName));

context.Response.End();

}

// naive test for valid xap file -> just test if the file requested is actualy a .xap file

public bool validateFile(string fileName)

{

fileName = fileName.ToUpper();

if ((fileName.Length > 4) &&(fileName.Substring(fileName.Length - 4).CompareTo(".XAP") == 0)

)

return true;

else

return false;

}

public bool IsReusable

{

get

{

return false;

}

}

}

// EOF HttpXapHandler

After you created the http handler add the following line to your web.config file inside the httpHandlers section(note the bold part):

<httpHandlers> <add verb="*" path="GetXapFile.ashx" type="HttpXapHandler" validate="false"/>

</httpHandlers>

Now that we have an http xap handler our web site should be able to accept requests like this:

http://www.MySiteNameGoesHere.com/getXapFile.ashx?fileName=Silverlight2.xap

To actually use this inside a web page take a look at the next example.

Usage example:

To access the .xap files in your web pages you will need to replace each occurrence of the source=[xap file name] with source=getXapFile.ashx?fileName=[xap file name].

In your html page this will look something like the following (note the bold part):

<div id="silverlightControlHost">

<object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%">

<param name="source" value="getXapFile.ashx?fileName=mySilverlight2file.xap"/>

<param name="onerror" value="onSilverlightError" />

<param name="background" value="white" />

 

<a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;">

<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>

</a>

</object>

<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>

</div>

good luck!

Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

IIS | Silverlight | Troubleshoot

Upgrading existing Silverlight 2 beta 1 code to beta 2

by APIJunkie 6/12/2008 5:59:00 AM

Silverlight girl and I recently upgraded Bumble Beegger to work with Silverlight 2 beta 2.

Some things were easier then others all in all it took a few hours to finish and was not a big ordeal.

If you are planning on upgrading your code you can find official Microsoft documentation about breaking changes between beta 1 and beta 2 here. Also note that the last minute correction and additions can be found here.

Below are some of the coding issues we encountered and how we solved them in the hope that this will save someone else some time:

1. FrameworkElement.Resources is a ResourceDictionary

Trying to a use Add without a key fails.

Example:

canvas.Resources.Add(value); // compilation error on beta 2

canvas.Resources.Add("key",value); // o.k. on beta 2
 

2. WebClient reference change

To use web client you will need to add a reference to System.net.
 

3. ApplicationSettings.Default was changed

ApplicationSettings.Default is not accessible you can use IsolatedStorageSettings.ApplicationSettings instead.


4. The type or namespace name 'DataGrid' does not exist in the namespace

You can find more info about this problem and the solution here


5. DataGrid syntax changes.

Example:

DataGridTextBoxColumn was changed to DataGridTextColumn

You can find more info about it here.
 

6. SetValue needs explicit cast to double.

Example:

item.SetValue(Canvas.LeftProperty, value); // compilation error on beta 2

item.SetValue(Canvas.LeftProperty, (double)value); // o.k. on beta 2
 

 

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Silverlight | Troubleshoot

Fix for the DataGrid does not exist in the namespace error in Silverlight 2 beta 2

by APIJunkie 6/10/2008 7:27:00 AM

When upgrading an existing Silverlight project to silverlight 2 beta 2 you might encounter the following error:

"The type or namespace name 'DataGrid' does not exist in the namespace 'System.Windows.Controls' (are you missing an assembly reference?)"

To solve the problem:

1. First go to your project references (Expand your project references sub tree in the Visual Studio IDE) and  look for System.Windows.Controls.Data in the reference list.

(If it does not exist in the list then you probably had the problem before the upgrade and you need to add a reference to System.Windows.Controls.Data by going to Project/Add Reference/.Net and choosing it from the list)

2. Press the right button on the System.Windows.Controls.Data reference and choose properties.

3. If the "Specific Version" property is set to true, change the "Specific Version" property to False.

4. Rebuild the project/solution.

This solved the problem for us on several Silverlight projects using a DataGrid.

Cheers

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Silverlight | PRB | Troubleshoot | How To

The type name X does not exist in the type Y error in a Silverlight project

by APIJunkie 4/27/2008 8:25:00 AM

If you run into this message when building a Silverlight project and have a class name and a namespace name that are identical you might be suffering from some kind of naming problem in the Silverlight development environment.

I found another reference to the problem in an MSDN forum.

To solve the problem I renamed the class name to a different name (one that is not identical to the namespace name).

Hope this helps...

 

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Silverlight | PRB | Troubleshoot

Avoiding some common errors when consuming web services and calling page methods using ASP.NET AJAX extensions

by APIJunkie 2/13/2008 10:14:00 AM
I have compiled a small list of things to remember in order to avoid some common errors when using ASP.NET AJAX extensions.

1. Remember to declare your web services using the ScriptService attribute.

Why bother?

If you forget to do that you will not be able to easily access the web service from the client side script. You will be missing the automatically generated client script that will allow you to call the web service from your client script code.

Example:

namespace MyNameSpace

 {

[System.Web.Script.Services.ScriptService]
public class MyService : System.Web.Services.WebService
{
   ...

}

}

More Info:

http://www.asp.net/AJAX/Documentation/Live/mref/T_System_Web_Script_Services_ScriptServiceAttribute.aspx


2. If you wish to access session state in your web service functions remember to set the EnableSession attribute to true in your web method declaration.

Why bother?

If you forget to do this you will not be able to access session variables inside your web service methods.

Example:

namespace MyNameSpace

 {

[System.Web.Script.Services.ScriptService]
public class MyService : System.Web.Services.WebService
{
    [System.Web.Services.WebMethod(EnableSession=true)]

    public void myFunc()
    {
       Session["XVAR"] = 1;
    }

}

}

More Info:

http://msdn2.microsoft.com/en-us/library/system.web.services.webmethodattribute.enablesession.aspx

 

3. If you wish to call static page methods from client script remember to set the EnablePageMethods property of the script manager to true.
 

Why ?

If you forget to do that you will not be able to access the static page methods from the client side script.

Example:

<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">

 

More Info:

http://www.asp.net/AJAX/Documentation/Live/mref/P_System_Web_UI_ScriptManager_EnablePageMethods.aspx

 

4. If you wish to mix json.js client side script with the AJAX .NET client side script, use the script manager/script manager proxy Scripts property.

Why ?

You might receive a client side script error.

Example:

ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">

<Scripts>

   <asp:ScriptReference Path="json.js" />

</Scripts>

</ajaxToolkit:ToolkitScriptManager>

For more info you can read my previous post on the subject -> How to use json.js client side JavaScript file inside an AJAX.NET project

 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET | AJAX | Troubleshoot | JSON | JavaScript

How to help a sleep deprived Vista based computer when the Wake Source Device is a USB Root Hub

by APIJunkie 1/22/2008 7:48:00 AM

Recently One of my Vista machines started suffering from insomnia.
 
Every time Vista would go into sleep mode it will power down but will immediately wake up after a couple of seconds.
 
A little search in the windows system event log produced the following event: EventID 1, Wake Source: Device -USB Root Hub.
 
A little further search on Google landed me in a Microsoft KB that might help some one else but did not solve my problem:
 
A computer that is running Windows Vista appears to sleep and then immediately wake.
 
Although the above KB did not solve my problem, it came pretty close.
 
As it turns out some devices do not behave very well with power management turned on.
 
In my case it was a USB mouse.
 
To solve my problem I had to disable the mouse ability to wake up the computer from sleep mode.
 
In your case it might be another connected device.

If you want to disable a device's ability to wake your computer from sleep mode follow the steps below:
 
 1. Click Start, right-click Computer, and then click Manage.
 
 2. In the User Account Control dialog box, click Continue.
 
 3. Click Device Manager, expand the device family in question (in my case it was "Mice and Other Pointing Devices").
 
 4. Right-click the device, and then click Properties.
 
 4. Click the Power Management tab, uncheck the "Allow this device to wake the computer" check box, and then click OK. 
 
Hope this helps some one else...
 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

KB | PRB | Troubleshoot | Vista | Sleep Mode

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Name of author

My name is Bacon…James Bacon.

I am an API wars veteran I was wounded by x86 assembly, recovered and moved on to C. I am currently stuck in C++ and sniffing .NET.

I am mainly here to ramble about coding, various API’s, Junkies(me especially) and everything else that happens between coders and their significant other.

E-mail me Send mail


Calendar

<<  November 2008  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

View posts in large calendar

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in