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

Fix for SQL Server SSL Security error ConnectionOpen (SECDoClientHandshake())

by APIJunkie 7/31/2008 12:45:00 AM

Having an SSL certificate that does not match the server name or expired or is invalid for any other reason can cause this error.

You will receive the above error message when connecting to your SQL server.

Very annoying and hard to find especially if the server hasn't been started for a few weeks since the certificate was installed  ( it seems like the certificate usage is refreshed only when the SQL server service is restarted).

After a little searching, I found an article about this SQL error and how to solve it.

In our case we used a SelfSSL generated certificate.

Note that to fix the problem we had to delete certificates from:

Certificates (local computer)
  Personal
     Certificates

After deleting the certificate you need to stop and start the SQL server service.

Currently rated 4.0 by 1 people

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

Tags:

Microsoft

Rewrite URL and HttpHandler problems on IIS with certain character types

by APIJunkie 7/30/2008 12:01:00 AM

Trying to rewrite URL's or custom handle URL's on IIS 6/7 can lead to HTTP errors on the IIS level.

The problem is that some characters like a question mark (?) are considered illegal by IIS when they are a part of a URL file name or path.

Example:

http://www.mydomain.com/MyUrlWithQMark?.ashx

Will produce: HTTP Error 404 - File or directory not found, even if there is an HTTP handler defined for that file type.

Since those characters are not allowed by IIS, requests containing those characters are blocked on the Http.sys level before they ever reach the appropriate HttpHandler.

Unfortunately this means that ASP.Net code does not get a chance to handle URL's that contain characters dimmed illegal by IIS.

Currently the only solution is to change IIS registry settings that effect the way Http.sys handles those types of characters.

Specifically you will need to change the AllowRestrictedChars setting from 0 to 1.

The main problem with this solution is that if you don't have access to those registry settings you have a problem!

For example people using shared hosting solutions or shared servers where some sites want to allow this option and some don't will not be able to use this solution.

I hope this will change in future versions of IIS. in my opinion the AllowRestrictedChars option should be configurable per site through an ASP.NET configuration option.

 

Be the first to rate this post

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

Tags:

IIS | .NET | Web Development

Using Silverlight for efficient low level communications (UDP socket usage and port restrictions)

by APIJunkie 6/23/2008 10:04:00 PM

For all of you guys that were hoping to use Silverlight for advanced low-level communications note the following excerpt

from the MSDN website about Working with sockets in Silverlight 2  beta 2:

"Currently, the only supported ProtocolType on Silverlight 2 is the TCP protocol.

One restriction on using sockets in Silverlight 2 is that the port range that a network application is allowed to connect to must be within the range of 4502-4534. These are the only ports allowed for connection using sockets from Silverlight 2 applications. If a connection is to a port is not within this port range, the connection attempt will fail."

This means that any UDP communication is banned and port number access is highly limited.

I for one hope this is only a temporary thing that would change in the final version 2 release.

The reason be is that there is a whole range of communication applications ranging from networking tools to multiplayer games that will never be implemented in Silverlight.

If Silverlight is to take its place as a true robust platform for RIA applications it should at the very least allow UDP access and a very wide range of port access.

Security concerns are important they should be addressed and dealt with but they should not cause this promising platform to become crippled.

JB

 

Currently rated 4.5 by 4 people

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

Tags:

Silverlight | Communications

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

Getting around Silverlight 2 beta 1 error 4002 while changing visibility of a control on mouse click event

by APIJunkie 5/27/2008 11:27:00 PM

While working on  Bumble Beegger we came across a daunting problem that only seemed to happen under certain conditions.

Silverlight error message
ErrorCode: 4002
ErrorType: ManagedRuntimeError
Message: System.Exception: Error HRESULT E_FAIL has been returned from a call to a COM component.
at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
at System.Windows.DependencyObject.MethodEx(String methodName, CValue[] cvData)
at System.Windows.UIElement.ReleaseMouseCapture()
at System.Windows.Controls.Primitives.ButtonBase.ReleaseMouseCaptureInternal()
at System.Windows.Controls.Primitives.ButtonBase.OnLostFocus(RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnLostFocus(Object sender, RoutedEventArgs e)
at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName) 

After a few hours of debugging, experimenting and googling I came across a discussion on Silverlight.net that shed some light on the problem.

As it turns out there is bug in Silverlight 2 beta 1 that can cause a crash when changing the visibility of a button control inside a mouse event handler.

The recommended workarounds around this problem were to change the size to 0,0 or change the opacity to 1.

Another option is to use the Canvas.ZIndexProperty and set it to a number that is smaller then your foreground elements.

The problem is that those does not always produce a similar enough effect in other elements.

If you still want to use visibility where possible, you can check the type of control and choose to modify visibility, size, opacity or Z Index according to the type.

Granted this is a horrible hack but it gets the job done until we can get our hands on beta 2...

Example:

// assume uiElement points to some valid UIElement

UIElement uiElement;

// check element type, if its not a button set visibility to collapsed else use ZIndex for a similar effect

if (uiElement.GetType() != typeof(Button)) 

   uiElement.Visibility = Visibility.Collapsed;

else

   ((Button)uiElement).SetValue(Canvas.ZIndexProperty, -1);

Currently rated 5.0 by 1 people

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

Tags:

Silverlight | PRB | How To | Debug

A new Silverlight web based game showing the potential of this new and exciting technology

by APIJunkie 5/21/2008 12:15:00 AM

Mashooo.com released a new Silverlight web based game today.

For those of you who have been sleep walking for the past few month. Silverlight is a new and exciting technology that looks like a promising candidate for next generation development of RIA applications.

The game is called Bumble Beegger and was built as a proof of concept for the usability of this new technology.

The game uses the Farseer Physics Engine that was developed by Jeff Weber of Farseer Games for gravity, movement and collision detection.

You can play Bumble Beegger for free with your web browser on Mashooo.com

Have fun and remember that it is a beta version and that any comments would be welcome...

Be the first to rate this post

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

Tags:

Silverlight | Games

Cannot access localhost on Vista when debugging local ASP.NET Applications

by APIJunkie 5/6/2008 5:31:00 PM

If you are trying to debug ASP.NET applications on Vista you might run into the following problem:

localhost is not accessible through your browser and the error that is displayed is "Internet Explorer cannot display the webpage".

After some googling I ran across a reference to the same problem.

The problem has to do with the fact that there are 2 entries for local host in the hosts file ([Windows directory]\System32\drivers\etc\hosts).

One for ipv4 and one for ipv6.

Example:

127.0.0.1 localhost
::1 localhost

To solve the problem you can remark one of them. The example below remarks the ipv6 entry.

127.0.0.1 localhost
# Causes problems when using localhost ->
#::1 localhost

Note that you might not be able to modify the hosts file even if you are running as an administrator.

The following Microsoft KB explains how to change the hosts file:

http://support.microsoft.com/default.aspx?scid=kb;en-us;923947

Hope this helps...
 

Be the first to rate this post

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

Tags:

ASP.NET | PRB | Vista | How To | Debug

How to configure sourcesafe for internet access

by APIJunkie 5/2/2008 7:17:00 AM

I was looking for a good source on setting up sourcesafe access over HTTP/HTTPS.

Unfortunately MSDN help on this subject is a little scarce.

I found this great guide for setting up sourcesafe over an internet connection

It is a very detailed step by step guide that can get you up and running very fast.

Kudos to Alin Constantin for the great guide :)

 

Be the first to rate this post

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

Tags:

IIS | How To | sourcesafe

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

<<  September 2008  >>
MoTuWeThFrSaSu
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

View posts in large calendar

Pages

    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