Monday, March 29, 2010

Silverlight ag_e_network_error Code: 4001

I faced this error when running silverlight app. The UI team gave me the XAML files in a solution which was working perfectly fine.

ag_e_network_error.. errorCode: 4001

I knew that silverlight is not able to load the image file rather locate the image file. I did some google search and tried out the said solutions but none of them worked.

Image format could be an issue.. but not in my case as it was working with the solution provided by UI team.

Next thing was to do some trial and error. I hate doing this but this was the only way out as what happens within silverlight is a black box.

1. I tried different path combinations "/" vs "\".
2. Direct path "my dirve:\path...\*.png"
Solution:
3. Then I tried to other way of looking this problem. Since, I was running in debug mode, it struck me that silverlight run time is looking for the images at \Bin\Debug.
Thats it copying the images here worked like a charm.

Also, I copied the images to web folder\ClientBin where my xap will be hosted. It depends whether you want to test when in debug mode from VS or releasing it for users.

I hope this saves some of your time.

Thursday, March 25, 2010

PRISM Framework - Silverlight Data binding problem

PRISM Framework - Silverlight Data binding problem.

I faced the following problem with my Silverlight code...
1. Simple data binding to the silverlight control in the XAML file does not work.
2. Same code when used outside the ZFS app works fine (local project on my machine).

Binding method:
XAML way...

Back end code (Data context)
{
MyTextBlock.DataContext = new TextBindData() { TextValue = "Onewireless-ZFS program" };
}
Public class TextBindData
{
public string TextValue {get; set;}
}

3. The above code doesn’t throw any error but the binding just doesn’t work. This may be due to the PRISM framework usage.

4. If the control is created at run time and binded then it works.
Fix: Create the user control at run time….
...
TextBlock MyTextBlock = new TextBlock();
… // Add the control to Layout root

Now the binding should work just fine.

If you find a better fix for this problem; please let me know.

Wednesday, March 10, 2010

Silverlight Error: The name ‘InitializeComponent’ does not exist in the current context

I faced problem after conversion silverlight 2.0 app to silverlight 3.0 (VS 2008). After searching on net, I found the problem and the following change fixed my problem

Step1 : Right click on project folder -> unload the project
Step2: Right click on the project and click "Edit the Project.csproj"
Step3: Make the following change. Change "SilverlightPage" tag to "ApplicationDefinition" tag name.

Before Change:


After change:

Step4: Save the changes
Step5: Reload the project (Right click & reload)

This must fix the problem.