Showing posts with label Silverlight. Show all posts
Showing posts with label Silverlight. Show all posts

Tuesday, June 19, 2012

Blank Page when Publishing a Silverlight App

I just deployed a new Silverlight application to a Windows Server 2003 box as a new website and was surprised with a blank page when I launched the application. No error messages or warnings, just a completely blank page.

A quick web search and I realized I had been here before. You have to register the MIME types, .xaml and .xap, in IIS for the website. I added them for a previous website, but I didn’t add them at the server root.

Simple instructions to add the MIME types to IIS can be found on Jacqui’s Dev Blog under Deploying Silverlight Application - Why Blank?! Note the first blog post comment that suggests adding the additional .xap application/x-silverlight-app and .xbap application/x-ms-xbap MIME types. I didn’t need to add the .xbap to get my application working, but I did need the .xap.

Tuesday, May 29, 2012

Sterling Serialization issue - Object of type 'System.Int32' cannot be converted to type 'System.DateTime'

sterling forksI created a new data model class to store in a Sterling NoSQL database. On the first and all subsequent attempts to save or retrieve data of this type, I received the error message at the bottom of this post. A number of other people reported similar issues. Apparently it is some type of serialization/deserialization issue. I didn’t find a suggested resolution, but on a whim, moved the AssessmentDate DateTime property from the top of the list of properties in the class to the bottom and that seemed to resolve the issue.

class definition

Object of type 'System.Int32' cannot be converted to type 'System.DateTime'.

   at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
   at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
   at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Wintellect.Sterling.Serialization.PropertyOrField.<get_Setter>b__0(Object obj, Object prop)
   at Wintellect.Sterling.Serialization.SerializationHelper.<>c__DisplayClassd.<_CacheProperties>b__5(Object parent, Object property)
   at Wintellect.Sterling.Serialization.SerializationHelper.Load(Type type, Object key, BinaryReader br, CycleCache cache)
   at Wintellect.Sterling.Database.BaseDatabaseInstance.Load(Type type, Object key, CycleCache cache)
   at Wintellect.Sterling.Database.BaseDatabaseInstance.Load(Type type, Object key)
   at Wintellect.Sterling.Database.BaseDatabaseInstance.Load[T,TKey](TKey key)
   at Wintellect.Sterling.Keys.TableKey`2.<.ctor>b__0()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at LeanAssessmentNav.Views.Register.<BindLists>b__6(TableKey`2 a)
   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at LeanAssessmentNav.Views.Register.BindLists()
   at LeanAssessmentNav.Views.Register..ctor()

 

photo credit: Le Petit Poulailler / CC BY 2.0

Why isn’t my Sterling database persisting between application loads?

Sterling repository (silver bowl)I’m using Sterling, a NoSQL database for .Net, Silverlight, and Windows Phone, to persist some data in a Silverlight 4 application. The intent is to persist it using Isolated Storage. It was obvious that the data was temporarily persisting because the stored data was available on multiple different views in the application. The trouble showed up when I stopped debugging and later started debugging again, the application re-launched and none of the previously persisted data was available.

Initially I was thinking that using the Visual Studio ASP.Net Development server was not maintaining Isolated Storage between application launches. It was far more simple than that. By default, Sterling uses an in-memory driver. If you want to persist using Isolated storage, you must pass an instance of the IsolatatedStorageDriver as an argument when Registering the Database. Note the difference in the samples below.

In Memory

Database = _engine.SterlingDatabase.RegisterDatabase<YourSterlingDatabase>();

Isolated Storage

Database = _engine.SterlingDatabase.RegisterDatabase<YourSterlingDatabase>(new Wintellect.Sterling.IsolatedStorage.IsolatedStorageDriver());

 

photo credit: Neil Noland / CC BY-SA 2.0

Tuesday, November 22, 2011

Troubleshooting Relative URI’s in Silverlight Projects

My Visual Studio Solution contains a minimum of a project for the Silverlight application and a project for the web page that hosts the Silverlight application. The Silverlight application reads and rights files to the local file system.

The solution is structured similar to this:

mySolution (has a minimum of the following two projects)

  • MyApplication.Web - the project that hosts the Silverlight xap file (could be a simple index.html page and Silverlight.js javascript page)
  • MyApplication - the Silverlight application project

When debugging in Visual Studio, the files that the Silverlight application is trying to read from are not necessarily available to the application depending on how you structure the application and which project you put the data files into initially.

While under development, intuition may lead you to believe that if it is the Silverlight application that is actually reading the files, the Data folder should be placed in the Silverlight application project root, not the web project. That would be incorrect.

Example 1

new Uri("/Data/ReadThisFile.xml", UriKind.Relative)

UriKind.Relative with a leading slash (/) in front of the Data folder is relative to the page that is hosting the XAP file. In my solution this is the project root of the web application, not the Silverlight project. The data file would be located at f:\mySolution\myApplication.Web\Data\ReadThisFile.xml


Example 2



new Uri("Data/ReadThisFile.xml", UriKind.Relative)
Without the leading slash in front of the Data folder as in this example, the file is expected to be relative to the Silverlight xap file. In my solution the xap file is in the default location, the ClientBin folder, which is a sub folder of the project root of the web application. The data file in this case would be located at f:\mySolution\myApplication.Web\ClientBin\Data\ReadThisFile.xml


Troubleshooting with Process Monitor


If you are getting File not found exceptions, the file isn’t where your application thought it was supposed to be. A relatively easy way to find out where the application is looking for the file is to use SysInternals Process Monitor.


Once you install and run the Process Monitor, you can set the filters to narrow down the captured events to locate the path to the file. The primary filters I used were “Result is not SUCCESS” and “Path contains ReadThisFile.xml”


 image


The filtered results would look similar to the following, if the the application throws a File not found type of error. (click to enlarge)


image

Monday, November 21, 2011

Could not load file or assembly System.IdentityModel

I added functionality to a Silverlight application I created several months ago and when I attempted to run it in debug mode, I received this error:

Could not load file or assembly 'System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

I found very little evidence of why I was getting this error now. My search results did not turn up much useful information either. I did find this link on Stack Overflow, so on a whim I revised the web.config of the web project that hosts the Silverlight application to a add a clear statement to the assemblies node.

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.0" >
        <assemblies>
          <clear/>
        </assemblies>
      </compilation>
    </system.web>
</configuration>

After making that change, the assembly loads without errors. This was on my development workstation. The application did not throw any errors on the production server after publishing it without the clear statement in the web.config.

Wednesday, June 8, 2011

Circumventing the uriMappings in Silverlight

Redirection chaosI created a Silverlight application with the Silverlight Navigation project template that needed to open a link to a PDF file located in a subfolder of the host web application directory. The  project has a convenient uriMapping process defined in the MainPage.xaml XAML to provide search engine friendly links to the various Silverlight pages. It is located in the Windows.System.Navigation namespace. It looks something like this:

<uriMapper:UriMapper>
   <uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
   <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
</uriMapper:UriMapper>

 

I needed to link to an absolute Url, not a uri relative to the Silverlight app, like http://www.deanwillson.com/downloads/Continuous-Improvement-professional-Org-1st-Edition.pdf, but if the uriMapper catches that link it attempts to re-map it to a resource that doesn’t exist which generates the following error:


“Content for the URI cannot be loaded. The URI may be Invalid”


Solution


In order to accomplish linking outside of the defined uriMappings, I added the link in the XAML of the HyperlinkButton NavigateUri.



<HyperlinkButton Name="lnkReport" NavigateUri="http://www.deanwillson.com/downloads/Continuous-Improvement-professional-Org-1st-Edition.pdf" Content="Click here to open your document" TargetName="_blank" Margin="116,11,184,10" Width="200" />

All this probably looks pretty obvious, but it started with me trying to open the pdf report using code-behind in the clicked event handler for the button, which kept throwing the Invalid Uri exception. I even added a special uriMapping that mapped to the same link, which also did not work.


photo credit: eirikref / CC BY 2.0

Wednesday, May 25, 2011

Creating a Windows Phone 7 app using WCF, and SQL Azure

Last night I gave a presentation with demos for fwPASS creating a Windows 7 app displaying a list of gymnasts from a SQL Azure database using WCF (Windows Communication Foundation). The WCF service used the Entity Framework and the .Net Membership provider.

The application was surprisingly easy to create despite the fact that were a lot of moving pieces with integration between all the different components.

The presentation covered the following tools:

 

All that in 70 minutes. Yes, I talk fast. This was a first time presentation. Below is the demo script I used:

Marketplace

1. Preview App Hub http://create.msdn.com

· Show app details text, iconography

Database

1. SSMS – show local ChalkChimp database

· Show script for creating additional users?

2. http://windows.azure.com SQL management interface

· No query designer

3. SQL Azure Migration tool

· Scripts out db

· Shows unsupported features

· deploys

4. Azure limitations in SSMS

· No query designer

· Admin account (other users don’t have access to the master database)

WCF

1. Create new project WCF Application

· Highlight Framework version 3.5

· Change binding to basicHTTPBinding

2. New Item à ADO.Net Entity

· Azure connection

3. Switch to finished project

4. Modify Iservice.cs, modify Service.cs implementation

5. Show .Net membership bits in web.config

6. View in browser (copy url)

WP7 client

1. Open Visual Studio (another)

2. New Project à Windows Phone 7 application

3. New item à Phone portrait page

4. Add Service reference

· Show service methods

· Advanced show generate async methods

5. Switch to finished project

· Show xaml bindings

· Show async methods and completed event handlers

· switch device to emulator

6. Run it

Optional

· Show property pages and iconography

 

Tuesday, May 17, 2011

Submitting an AppMakr app to the Windows Phone 7 Marketplace

I made a Windows Phone 7 app using AppMakr for reading Lean-related content from prominent Lean bloggers. That was easy, but there didn’t appear to be any instructions for how to get the app added to the App Hub. So here they are.

Log into your AppMakr account. There are a number of ways to get to your build. Either click the “App Builds” link in the top navigation or click the “Builds” button on one of your applications (as shown in the image below).

image

Pick the latest build that you want to submit to the marketplace and click the Download App button.

image

You will be presented with a dialog to open or save the zip file. Choose to save it to a location on your PC.

image

Important: Rename the file extension from .zip to .xap (which is the Silverlight application package deployment file). You will have to create the necessary Windows Phone 7 iconography (icons and screenshots needed for submitting to the app hub). You may be able to use some of the ones you used to create the application in AppMakr.

You will need an App Hub Developer account to submit applications to the Windows Marketplace ($99/year). After you have that, log in and from the “my dashboard” navigation link, select “Windows Phone”.

Click the “submit new app” button.

image

Fill out the form fields. Click inside the Application package box with the Plus (+) sign. A file open dialog will appear. Select the .xap file that you renamed after downloading from AppMakr earlier.

image

Continue through the process of providing an application description and uploading the necessary icon images. After you finish, sit back and wait for your app to go through the testing and certification process.

 

Technorati Tags: ,,

Monday, May 9, 2011

Switching to C#

neon sign - foreign language bookstoreAfter more than 7 years of VB.Net development, I have made the conscious decision to split my development into primarily VB.Net for most of my ASP.Net projects and C# for my Windows Phone 7, Silverlight, and WPF work. This transition was due to three primary driving forces:

  • Early Windows Phone 7 development (pre-RTM) was limited to C# due to the lack of availability for VB.Net support on the WP7 platform.
  • There appears to be a larger codebase of Silverlight and WP7 utilities, samples, and tutorials in C# to learn from.
  • I have had an easier time finding advanced Linq syntax examples in C#.

The syntax differences are not much different. I was already used to the most common syntactic differences, such as parenthesis, squiggly brackets, and semi-colons from my earlier work in PHP and Java. I would have started in C# if it were not for the Classic ASP and VB.Net applications I was supporting years ago in my .Net 1.1 beginnings.

Of course, the language selection is always trumped by complying with my clients’ corporate development standards and selecting the appropriate language for the job where the differences are relevant.

photo credit: avlxyz / CC BY-SA 2.0

Thursday, April 7, 2011

IIS is Missing XAP Mime Type for Silverlight Application

lego mimeUpon navigating to the web page hosting a newly deployed Silverlight application, I received the following error:

Error: Unhandled Error in Silverlight Application
Code: 2104   
Category: InitializeError      
Message: Could not download the Silverlight application. Check web server settings  

Thanks, but which server settings? In my case the MIME type for the .xap extension was missing in IIS7. I’m not sure why it was missing since .xaml and .xbap were already defined. I simply added the “.xap” extension and it’s corresponding MIME Type “application/x-silverlight-app” and all was well.
Xap Missing Mime Type In IIS

photo credit: e v a . p é b a r / CC BY 2.0

File URI invalid for WCF HTTP Endpoint

System.ArgumentException: The provided URI scheme 'file' is invalid; expected 'http'.

disconnectedThe error occurred when debugging a Silverlight app that uses Windows Communication Foundation (WCF). When running the debugger, the IDE was launching the html file hosting the Silverlight application, but it was launching it in the browser using a file path, F:\Projects\MyLOBApp\Bin\Debug\TestPage.html, not through IIS as http://localhost/MyLOBApp/TestPage.html. The application was using the following code in a global application class to set the URL to the WCF service.

public static string WebServiceUrlPath
{
    get
    {
        Uri uri = new Uri(Application.Current.Host.Source, "../AppDataService.svc");
        return uri.AbsolutePath.ToString(); 
    }
} 

My solution consists of two projects:


  1. The Silverlight application project
  2. The WCF service project

Upon closer inspection of the file path, Visual Studio was launching the test page from the Silverlight project when it should have been launching the test html page from the WCF project. The simple solution was to set the WCF project as the StartUp Project. That should have been more obvious especially in light of the following message box that popped up before the debugger started, but it was initially overlooked because of the similar project names and html page filenames in the two projects.


image


photo credit: satemkemet / CC BY-SA 2.0

Thursday, March 10, 2011

Windows Phone 7 Testing a Date Change in the Emulator

imageI wrote a WP7 application that stores a bit of data based on today’s date. Tomorrow when the date changes, yesterday’s data gets cleared out to start fresh. Before submitting the app to the App Hub I needed to test whether it would work as expected when the date changes. At the time, I didn’t have an actual Windows Phone 7 for testing so I used the Emulator. The testing process didn’t work out quite as I expected.

Happy Path

  1. Load Emulator
  2. Deploy app to the emulator
  3. Run app
  4. Click some buttons that store today’s data
  5. Change the date on the development box (assuming that is where the emulator gets its current date)
  6. Click the windows key to unload the app
  7. Return to app (which should have a different date since I changed the date on the development box)
  8. The app data should be empty because it is a new day

Fail

There were a few misconception to the above.

  • It appears that the emulator loads today’s date when the emulator starts up, because it didn’t change when I changed the date in my development environment.
  • When you click the back button it unloads the application and you lose the data stored in Isolated Storage.

Fix

imageReplace steps 5 & 6 in the above “Happy Path” with the following steps to effectively test the date change:

  1. Click to the System Settings page in the Emulator
  2. Click “date & time”
  3. Toggle the “set automatically” slider to Off
  4. Click on the date in the date field
  5. Change the date to a different day
  6. Click the windows key and left arrow icon image to see the app in the menu.

Tuesday, June 1, 2010

IndyTechFest 2010

I am a Windows 7 phone programmer. At least that’s what Dave Bost, Bill Steele, and Jesse Liberty told me. That makes me feel pretty trendy.

With eight tracks of sessions I found myself wanting to attend two or three presentations simultaneously every hour. Unfortunately I had to choose just one.

Sessions I attended

A. Keynote with Jesse Liberty.

1. Windows Presentation Foundation for Developers

2. Introducing Windows Phone 7 Series

B. Lunch: Networking. It’s pretty fun to go to a regional event with over 400 attendees and realize that you know about 10% of the people there. I wanted to attend the Building a Company and Operating a Consultancy lunch and learn, but the room was packed full by the time I got my lunch.

3. Building Applications on Windows Phone 7 with Silverlight

4. Building a Data Mart 101

5. Application Development with Silverlight 4. Jesse mentioned Adam Kinney’s name in this session. That always makes me think I know a celebrity.

Thank you!

A big thanks goes out to the organizers, speakers, sponsors, volunteers, attendees, and anyone else that had their hand in the event! Thank you to my buddy Dave Fancher for giving me a ride from the Marriott North to the Marriot East.

The logistics, food, venue, prizes, etc. get better every time they hold the IndyTechFest. There were so many prizes from the sponsors it literally took an hour to raffle them all off – and they were even doing it quickly and efficiently.

Monday, March 1, 2010

Edit Expression Encoder Job Output Templates in Blend

If you are like me and like Expression Encoder, you have probably already found the functionality that allows you to automatically create a web-based Silverlight player and html page wrapper to show off your fancy video editing prowess. Encoder comes with several Silverlight templates for audio only, video, and galleries of video. But what if the functionality they provide doesn’t suit your needs? Almost no problem, you can create a copy of the template and open it in Expression Blend in a few clicks, then customize the player as you see fit.

Click the Output tab in Encoder and select the template you wish to edit from the drop-down list. Click the tiny dot immediately to the right of the Template drop-down list.

Edit-Encoder-template-in-Blendjpg 

You will be presented options for editing the template or a copy of it in Expression Blend or Visual Studio. Depending on the template you choose and what specifically you want to change in the template, the customization can range from relatively simple to “WOW, maybe I’m being too picky about what I don’t like about the built-in template.”