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, October 26, 2011

10 Reasons to Join a PASS or .Net User Group

user groupI am a member and leader at multiple chapters of technology-based international professional associations, like PASS (Professional Association for SQL Server) and INETA. Through that affiliation, I have experienced many, many benefits that such a small percentage of our industry takes advantage of.

  1. Great people – Attendees, speakers, organizers, volunteers, sponsors, and venue hosts. Attend regularly and I promise you will make life long friends.
  2. A place to talk shop with peers, learn about other organizations and practices, scope out job opportunities, help others with their challenges, and mentor people new to the field.
  3. Great content – free training, new technology previews, and deep dives into specific topics.
  4. Access to experts – speakers almost always provide their contact info and give you permission to ask questions outside of the presentation. Get help on your challenges from other attendees during the social networking time. Sometimes you even get to meet Industry celebrities and national conference presenters, such as Brent Ozar, Brad McGehee, and Scott Guthrie.
  5. Food and beverage
  6. Free swag – books, software (Development software, Operating Systems, 3rd party tools, Xbox games, and more), hardware (keyboards, mice, web cams, etc.), training vouchers, discount coupons, quirky and unusual items (such as Bucky Balls),  travel mugs, tote bags, back packs, and the list goes on.
  7. News and announcements about other events and happenings in the industry – training conferences like the PASS Summit and SQL Cruise, all day training opportunities, such as Day of .Net, Codemash, SQL Saturday, virtual training events, contests, free eBooks promotions, Job opportunities.
  8. Save money travelling to regional training or events by carpooling with your fellow user group friends.
  9. Opportunities to present – show off your own proficiency in your craft, get experience to prepare you to speak on regional or national level, establish credibility as a teacher/communicator.
  10. Opportunities to be a board member or volunteer to hone your leadership and logistical skills enhances your career marketability. Also, volunteering or leading a local chapter or regional event is great way to prepare you to become a board member on a national scale, if that is of interest to you.

Really there are few reasons not to attend, join, volunteer, or lead a professional organization. If you’re interested in professional organizations in general, read my popular post about 10 reasons to join a professional association.

What have I missed?

Thursday, October 13, 2011

SQL Server Compatibility Level Testing

upgrading technologyI stumbled on interesting version compatibility issues while working with a database in SQL Server 2008R2. The database was originally developed in SQL Server 2000. It was upgraded to MSSQL 2008R2 as a part of a virtualization initiative, however, the Compatibility Level was still set to 80 (MSSQL 2000).

After seeing columns of type VARCHAR(MAX), it got me wondering about compatibility issues since there was no VARCHAR(MAX) in 2000.

Anomaly #1

Doing some research I found this post with a script for Testing all procs before upgrading to Compatibility Level 90. I ran it on the database (while still set to Compatibility Level 80) and it reported a stored procedure that had a syntax error that was not caught by the syntax checker in MSSQL 2000, 2005, or 2008R2. The SQL is below:

SELECT     ChangeLogID
    , CourseID
    , RecordID
    , RecordTable
    , ChangeType
    , ModifiedDateTime
    , ModifiedByEmpNo
    , CASE RecordTable 
        WHEN 'Course' THEN
        ( SELECT CourseName 
          FROM Course 
          WHERE CourseID = cl.CourseID)
        WHEN 'Lesson' THEN
        ( SELECT LessonName 
          FROM Lesson 
          WHERE LessonID = cl.LessonID)
         WHEN 'Content' THEN
        ( SELECT ContentName 
          FROM Content 
          WHERE ContentID = cl.ContentID)
        ELSE "None"
    END AS RecordName
FROM         ChangeLog cl
WHERE     (CourseID = @CourseID)

The error message was: Invalid column name 'None'. Note the quotation marks around “None” after the ELSE. Strangely, the stored procedure executes without error. It only detects the syntax error on CREATE, not when I ALTER the stored procedure.


Anomaly #2


Using the same database described above, the compatibility error detection script I used (while still having a Compatibility Level of 80) did not detect the error:


Msg 8127, Level 16, State 1, Procedure GetNextLessonForLessonNo, Line 49
Column "Lesson.LessonNo" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.


The SQL generating this error is:


SELECT     TOP 1 MIN(L.LessonNo) AS LessonNo
    , L.LessonID
    , L.CourseID
    , L.LessonName
    , L.LessonDesc
    , COUNT(Content.ContentID) AS NContentPages
FROM     Course C 
         INNER JOIN Lesson L 
            ON C.CourseID = L.CourseID
         LEFT OUTER JOIN Content 
            ON L.LessonID = Content.LessonID
WHERE     (L.LessonNo > @LessonNo 
       AND L.CourseID = @CourseID)
GROUP BY L.LessonID
    , L.CourseID
    , L.LessonName
    , L.LessonDesc
ORDER BY L.LessonNo


This error is not detected in SSMS (in a query window, or by running the detection script) until the Database Compatibility Level is changed from 80 (MSSQL 2000) to 100 (MSSQL 2008). The issue can be resolved in SQL Server 2008 by adding L.LessonNo to the GROUP BY clause.


photo credit: somegeekintn / CC BY 2.0 

Tuesday, September 27, 2011

Image button link options in ASP.Net MVC3

There are several ways to skin this cat, but below are a couple options for using an image, in lieu of text, as a link to content. There are other overloads for the Url.Action and the Html.ActionLink, but in this example I was linking to a different controller passing in the integer id of the item to display a list of child records. The "STEPS” image is displayed if the parent record has child records.

image

Url.Action method

<a href='@Url.Action("ActionName", "ControllerName", new {Id = item.ID}) '><img src='@Url.Content("~/Content/Images/buttonimage.gif") ' alt="View Detail" border="0"  /></a> 

Html.ActionLink method



@Html.ActionLink(" ", "ActionName", "ControllerName", new { Id = item.ID }, new { @class = "steps-button", alt = "View Detail", title = "View Detail" })

Note that the first parameter in the action link is a space (because I didn’t want any text to show over the button background image) and the first argument cannot be null or empty.


In the site CSS layout I added the following steps-button class that adds the image to the link as a background image.



a.steps-button      
{
    background: url(../Content/Images/buttonimage.gif) no-repeat top left; 
    width: 14px;
    height: 44px; 
    display: block;
}

Wednesday, September 14, 2011

Using jQuery datepicker with MVC3 textboxes

Pick a dateThis post addresses two issues:

  1. Using the built-in ASP.NET Development Server vs. IIS to render the datepicker. If you are using IIS, skip to the second section.
  2. Dependencies necessary to get the jquery ui datepicker to work in an MVC3 project.

ASP.NET Development Server

I repeatedly have issues with AJAX controls (like the ModalPopup control) rendering with the correct styles using the ASP.NET Development Server vs. IIS. The jquery datepicker is no exception, but this time it surfaces as the following error “Microsoft JScript runtime error: Object doesn't support this property or method” in the jquery-1.5.1.min.js, which isn’t very helpful for troubleshooting.

image

On a hunch, I decided to configure the project as an application in IIS and access it via localhost/appname instead of the dynamically addressed port of the ASP.NET Development Server - giving me a more meaningful error to troubleshoot.

jQuery UI dependencies

Using the IIS served application, I received the tiny warning triangle in the lower left corner of IE that indicates a javascript error, “Message: Object doesn't support this property or method”. The offending line of code was $("#EstDateStarted").datepicker();.

My project was based on the standard Visual Studio 2010 MVC3 project template which included only the jquery-1.5.1.min.js in the _Layout.cshtml file using the Razor rendering engine. The .datepicker function is not located in that javascript file it is in the jquery-ui-1.8.11.min.js file. All I needed do to enable that functionality and resolve the error was to add the following reference to the head of the _Layout.cshtml file, which includes it on all the pages of the app:

<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript">

jquery ui datepicker

photo credit: augapfel / CC BY-SA 2.0

Thursday, July 28, 2011

New App Hub Features Still Need Work

LeanBites200The July 18 Marketplace updates look like they still need some tweaking. I updated one of my apps and set the publish status to “hide” after certification. After app certification approval, for  some reason, it showed an update to the app on my phone (doesn’t seem hidden to me). I updated the app to the new version, and the splash screen was updated, but the icons were not updated and the application just showed a “My Application” header at the top of the page with no app content at all.

I thought maybe that was the result of the “Hide” status. So I un-hid the app in the marketplace. It didn’t prompt another update so I uninstalled the app from my phone. When I searched in the marketplace for my app to reinstall, it could not be found.

In order to reinstall the app, I had to navigate to my Lean Bites website on my phone and click the Zune Marketplace deep link in the right column of the website. After following that procedure, the app installed and is working correctly again with the new updated version.

I hope Microsoft gets these issues worked out before the consumer frustration gets to a new high and it doesn’t make my app look like it’s the problem. With so much riding on the new Windows Phone platform, it is unfortunate to see them stumbling over issues that probably should have surfaced in beta testing.