find a location for property in a new city

Thursday 29 April 2010

Error in Silverlight application code: 2104 Could not download the Silverlight application. Check web server settings

Setting up a Silverlight application for the first time I got a JavaScript error of "Unhandled Error in Silverlight Application Code: 2104" with an accompanying message "Could not download the Silverlight application. Check web server settings"

Being new to this and largely just experimenting with Silverlight for the first time wasn't 100% what to do. At least it pointed me in the right direction with its "Check web server settings" comment at the end.

I checked the MIME types for my site. Sure enough there was no mention of the .xap extension. Yes, that would be the problem.

Solution

I added a MIME type with extension ".xap" and MIME type of "application/x-silverlight-app" and it all worked pleasantly.

I thought this was a bit weird that it didn't come pre-registered but oh well, hope you find this useful.

Follow britishdev on Twitter

Tuesday 27 April 2010

Multi line box selection editting is actually pretty useful in Visual Studio 2010

I thought this new multi line box select and edit ability was a bit gimicy and pointless. I never thought I'd ever use it. I found I needed it today and it is actually really useful!

I needed a load of bullet points hardcoded so I did the usual and wrote one out and copy and pasted the line several times then filled in the specific bit. Here it is:

WHOOPS! I got it wrong and need to make the ID more specific. I wanted to change li01 to liGuide01 and so on. Easy now though: Alt+Select the box you want to edit (little note - it's more start selecting and then hold down Alt):

I was so happy when I did this and found myself doing it all over the place, e.g. I need to add another class to all these or I could have even written them all out like this in the beginning rather than copy+pasting.

Also, this works on all code inside VS2010 just remember to keep all your code nice and aligned!

Follow britishdev on Twitter

Wednesday 21 April 2010

LINQ to SQL - Null value cannot be assigned to a member with type System.Int64 which is a non-nullable value type

I am attempting an InsertOnSubmit and it is failing since "The null value cannot be assigned to a member with type System.Int64 which is a non-nullable value type" This LINQ to SQL is driving me crazy. Please help.

The table in the SQL database has a MessageID column which is a BigInt with primary key (NOT NULL IDENTITY 1 1) no Default.

The field looks like this in the designer file to the dbml:
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_MessageId", AutoSync=AutoSync.OnInsert, DbType="BigInt NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)] 
public long MessageId 
{ 
    get 
    { 
        return this._MessageId; 
    } 
    set 
    { 
        if ((this._MessageId != value)) 
        { 
            this.OnMessageIdChanging(value); 
            this.SendPropertyChanging(); 
            this._MessageId = value; 
            this.SendPropertyChanged("MessageId"); 
            this.OnMessageIdChanged(); 
        } 
    } 
}

So the problem is that null cannot be assigned... right. But I'm not passing null! How can I be? I'm using a long (a value type so can't be null by nature).

One workaround I found was making this field nullable but this feels like a hack since it should never be null. Anyway this just moves the problem to the ID not AutoSyncing OnInsert. (AutoSync=OnInsert is set).

Update and solution

Well it took me a while, I even posted on stackoverflow to no avail but finally worked out the problem and wrote about it in this post about optimistic concurrency exceptions on insert although by this time it has manifested itself in a new way since I'm using Entity Framework.

Follow britishdev on Twitter

Thursday 15 April 2010

The type name 'MembershipProvider' could not be found in the namespace 'System.Web.Security' Upgrade to ASP.NET4

I received this error after upgrading to ASP.NET 4, "The type name 'MembershipProvider' could not be found in the namespace 'System.Web.Security'. This type has been forwarded to assembly 'System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' Consider adding a reference to that assembly. ASP.NET4."

You wont believe what I did to fix it... I added the reference that it asked for, System.Web.ApplicationServices.

This has happened since MembershipUser and Other Types in the System.Web.Security Namespace Have Been Moved

Follow britishdev on Twitter

Wednesday 14 April 2010

Potentially dangerous request .NET4 upgrade

I encountered an error after upgrading to ASP.NET 4 from 3.5 whereby my page was throwing an HttpRequestValidationException error. With error message "A potentially dangerous Request.Form value was detected from the client". This problem DID NOT occur before on this page that uses a TinyMCE rich text editor.

This page is sending dangerous requests since it is using a rich text editor that post HTML. This was worked around before by putting ValidateRequest="false" in the page declaration.

This seems to be ignored now in .NET4! Really I should be changing TinyMCE to be posting BBCode and replacing it with proper HTML on the server... but... I'm not since this is only for trusted internal users... and I can't be bothered ;)

Workaround

requestValidationMode="2.0" needs to be added to the httpRuntime element of the <system.web> section of the web.config.

Follow britishdev on Twitter

Tuesday 13 April 2010

Cannot change the specified .NET framework version or profile for a test project

I received the error message "attempted re-targeting of the project has been canceled. You cannot change the specified .NET framework version or profile for a test project" when trying to target the ASP.NET 3.5 framework after upgrading to Visual Studio 2010.

I loaded my VS2008 solution into the new VS2010 and asked to target ASP.NET 3.5 to begin with. This worked on all project except for my one MS unit test project. The class library for my RhinoMock tests are fine.

I couldn't Google the specific error but I did get this following helpful info from Microsoft: "It's not a bug - you just can't do it" ... Thanks!

Workaround - AKA cop out

Fortunately, for me, there aren't many tests in this project and targeting ASP.NET 3.5 is only very temporary so I have excluded this test project for now and all builds fine.

So BEWARE if you are planning on upgrading to VS2010 AND currently using MS's test library AND targeting the ASP.NET 3.5 framework! Because you can't and it doesn't look like there is a fix in sight. Disappointing!

Follow britishdev on Twitter

Monday 12 April 2010

Visual Studio 2010 release date is here. Get the link!

Been waiting and waiting for VS2010? Want to use ASP.NET 4 and C# 4? Well here is a link that will make you happy:

GET VISUAL STUDIO 2010 NOW! Or through MSDN subscription here.

You can expect more posts on the benefits of ASP.NET v4, some of the niceties of C# 4 and probably some bits about Visual Studio 2010 now that I can actually use these tools for production work rather than dodgy RC experiments.

Follow britishdev on Twitter

VS2010 Release date - exact time!

Here I am waiting patiently on the day of Visual Studio 2010 release and being rejected AGAIN. This happened to me last time the release was delayed on 22nd March and now it is happening again today.

This is because it is supposed to be launched at 10am Pacific time 12th April 2010 (because the launch is in Las Vegas). Which over here in London will be 6pm.

Update: It is out now so get Visual Studio 2010 here

As a side note - it is interesting how they have a code fail on their site I assume they are using local time for the countdown which in London has lead to the following countdown fail:

Follow britishdev on Twitter

Wednesday 7 April 2010

Could not load file or assembly 'MyHttpModules' or one of its dependencies. The system cannot find the file specified. Web.config inheritance

I made a new Virtual Application in my current IIS site to my brand new web application and I get this filthy error. So I'm thinking, "Of course you cannot load the file or assembly because it isn't in this web application but then I didn't ask you to." So where is it coming from? This is what is happening and how to solve it.

The "problem" is to do with web.config inheritance. Your new virtual application is still inheriting from the site's root web.config despite being physically separated and so it is finding this reference to a resource that doesn't exist in the new application.

Solution

Let me introduce a little known attribute of the location element in configuration files. It is called inheritInChildApplications, which can be set to false and will do what is says on the tin. Simply place them around the settings you do not want inherited by your child app. Unfortunately you can only use it in quite a blanket fashion, i.e. you can put it around <system.web> but if you think you're putting it around individual settings then you must be crazy!

So for my problem with a nonexistent HttpModule I will need to stop the system.web and system.webServer inheriting in my child app:
<location inheritInChildApplications="false">
  <system.web>
    <!-- various web things -->
  </system.web>
  <system.webServer>
    <!-- various web server things -->
  </system.webServer>
</location>

Unfortunately, this is so unknown that apparently not even Visual Studio knows about it so you can bask in the glory of your handy work with a squiggly blue line! (I think a squiggly blue line must indicate good code!)

Follow britishdev on Twitter

Saturday 3 April 2010

Colouring code with Syntax Highlighter

I need to colour my code samples to make it more readable and more like your IDE. I have been putting spans around each key word to colour manually and being a developer I know there must be an easier way! So I did some research and found that it is all about SyntaxHighlighter! Here is how to use Syntax Highlighter to colour your code.

  1. So first up you need to put this in the page head just before the </head> tag:
    <link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
    <link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'></script>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'></script> 
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'></script>
    
    <script language='javascript'> 
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
    SyntaxHighlighter.all();
    </script>
  2. Then you simply surround any code in these tags:
    <pre class="brush: csharp"></pre>
I have used C# for my example but there are many more languages that can be specified. I only import the C# and SQL but you can get more if needed.

Follow britishdev on Twitter