VS 2010 native code static linking

by APIJunkie 18. May 2011 06:36

This is a heads up for any one that is used to auto link static libraries using project dependencies.

VS 2010 changed the game by adding a new step that is necessary in order to auto link static libraries.

It is not enough to specify project dependencies as we used to do in older versions of Visual Studio.

To setup auto linking go to Project/Properties/Common Properties/Framework and References/Add new reference.

Tags:

C | C++ | Static | Tips and Tricks | Troubleshoot | Visual Studio

Silverlight update KB982926 failure and solution

by APIJunkie 4. June 2010 23:29

I was doing the rounds and updating 2 machines, running XP Pro and 2003 Server, with Silverlight 3 run time pre installed on them. When the update was complete I couldn’t view any Silverlight based web sites with IE 8 on both machines.

 

I would only receive an install Silverlight message. It was as if Silverlight was not installed on the machines any more.

 

A quick check in the IE installed component list (Tools/Internet Options/Programs/Manage add-ons/Show all add-ons) showed me I was automatically upgraded to Silverlight 4 (Version 4.0.50524.0) which seems fine.

 

To solve the problem I did the following:

 

1. Went to http://www.microsoft.com/silverlight/.

 

2. Pressed the install Silverlight button which crashed the installer (on npctrl.dll).

 

3. Restarted the browser at which point I got a message telling me I need to restart the browser again.

 

4. Restarted the browser for the second time which made Silverlight runtime and IE happy and willing to play together again.

Tags:

KB | Silverlight | Troubleshoot

Fix for ObjectDataSource delete method - object value passed to the delete method is null

by APIJunkie 3. September 2009 19:54

I recently stumbled upon a not very well documented "design feature" that took me a couple of hours to track down.

If you are defining a custom delete function for an ObjectDataSource you must also remember to define the DataKeyNames property of the GridView you are working with. If you do not remember to do this, the object’s value passed to your delete function will be null.

You can read more about the ObjectDataSource delete issue here.

Hope this helps!

Tags:

ASP.NET | PRB | Troubleshoot

ASP.NET cookie expiration date not saved

by APIJunkie 1. March 2009 22:40

When reading/reusing a cookie sent from the client do not expect the expiration date to be valid.

The following excerpt is taken from MSDN regarding cookies:

"To be clear, you can read the Expires property of a cookie that you have set in the Response object, before the cookie has been sent to the browser. However, you cannot get the expiration back in the Request object."

Here are 2 things to remember:

1. If you need to save the cookie expiration date, save it in another place besides the Expires property.

2. Remember to always set the expiration date before sending a cookie back to the client.

 

Tags:

.NET | Troubleshoot | Web Development

Url Rewrite ASP.NET 2.0 and HttpUnhandledException or Cannot use a leading .. to exit above the top directory

by APIJunkie 23. December 2008 09:21

I was really surprised to discover this bug a couple of days back while working on an ASP.Net 2.0 web site.

I spent several hours barking up the wrong code tree since I was convinced it had to do with some recent code changes I made.

But as it turns out this problem is as old as the server itself and for some reason has not been fixed by any .Net patches.

The jist of it is that if you encounter .net exceptions that only happen on your server with certain types of traffic ( examples: google bot, yahoo bot and some other esteemed visitors), you might be the victim of an annoying bug that has existed, as far as I could tell, for a couple of years and has not been fixed till date.

The telltale signs would be server exceptions that look like ->

Exception of type 'System.Web.HttpUnhandledException' was thrown.
Stack trace: at System.Web.UI.Page.HandleError(Exception e)

And inner exception type ->

System.Web.HttpException: Cannot use a leading .. to exit above the top directory. at System.Web.Util.UrlPath.ReduceVirtualPath(String path)

---------------

As it turns out this bug has to do with .Net 2.0 browser detection bug and can be fixed by adding a browser definition file to correct the problem.

You can also reproduce and test the browser detection bug here.

Note that this bug often occurs when you use url rewriting on your server.

 

Tags:

IIS | ASP.NET | PRB | Troubleshoot | Web Development

Fix for invalid XAML error - the member is not recognized or accessible when using ControlTemplate

by APIJunkie 16. December 2008 05:26

I've recently encountered an error that only appears when working on XAML in blend and not when working on XAML in VS.

Blend is apparently more sensitive then Visual studio 2008 when it comes to type checking templates.

If you forget to set the TargetType in a ControlTemplate and access certain properties in the content presenter, Blend will report an error and you will not be able to edit the XAML in design mode.

Note that this error only effects design mode in blend, the XAML still compiles and works perfectly (assuming we apply the template to the correct type).

Example:

Ok on blend, ok on VS 2008 ->

<ControlTemplate x:Key="MyXTemplate" TargetType="MyClassType">

Invalid XAML error on blend, ok on VS 2008 ->

<ControlTemplate x:Key="MyXTemplate">

For the error to appear you will also have to access non globally shared properties in the content presenter.

In the example below we try to set a content property which is not guaranteed to exist in the type we apply the template to.

Example:

<ContentPresenter Content="{TemplateBinding Content}" />

 

Tags:

Silverlight | PRB | Troubleshoot | Blend

Fix for Could not download the Silverlight application error

by APIJunkie 2. August 2008 10:08

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!

Tags:

IIS | Silverlight | Troubleshoot

Upgrading existing Silverlight 2 beta 1 code to beta 2

by APIJunkie 12. June 2008 05:59

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
 

 

Tags:

Silverlight | Troubleshoot

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

by APIJunkie 10. June 2008 07:27

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

Tags:

Silverlight | PRB | Troubleshoot | How To

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

by APIJunkie 27. April 2008 08:25

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...

 

 

Tags:

Silverlight | PRB | Troubleshoot

About the author

Name of author

I was first wounded by x86 assembly, recovered and moved on to C. Following a long addiction to C++ and a short stint at rehab I decided to switch to a healthier addiction so I am now happily sniffing .NET and getting hooked on Silverlight.

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.

  James Bacon