Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Saturday, 15 January 2011

Windows Phone Development and Designer Exceptions

I've been building a few Windows Phone applications recently and have been learning lot's along the way and am hopefully releasing a couple of these in the near future. However on my current project I have been constantly hounded by the designer view of my xaml pages throwing exceptions.


Tonight I decided to finally look into why these occur, I have managed to ignore them previously due to the weird nature of them. My exception scenario consists of a page that contains a pivot control and inside one of the pivot items there is a user control. The user control contains a simple list view which has some data bound to it

Now I have always got past the exceptions as if you use the designer view for the user control it works fine, however as soon as I put it into a page or a pivot the designer starts kicking off.


The actual exception is as follows:

Could not load type 'System.Net.HttpUtility' from assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
It then goes on to tell me the line number and location etc of this. At first glance this exception looks a bit weird as in the code view and if you run the application the exception is never thrown.

The first thing I did to try and resolve this issue was to find where System.Net.HttpUtility lives, in the desktop version of Silverlight it lives in System.Windows.Browser But as the Windows Phone version of Silverlight doesn't include System.Windows.Browser the development team moved the httputility type into the System.Net namespace and put it into the System.Windows assembly, http://msdn.microsoft.com/en-us/library/dd470087(v=vs.95).aspx#Assemblies. This explains why the project builds and runs etc, however it doesn't explain why the designer has such a bad time with it.


Sadly I couldn't find a source or information on this exception, my guess is the designer is loading an older version of the assembly, a missing designer tool update from the RTM or something similar {Edit see my update below}. However what I have found is that Silverlight does have another way of encoding and decoding URL strings. System.Uri.EscapeUriString, if you use this the phone and the designer all work happily. A minor change and a headache eased :) I'm hoping the next tools update fixes the issue but until then this seems the safest method of escaping url strings.

Update

As I oddly found this issue intriguing I decided to investigate further. I opened another Visual Studio attached it to the Visual Studio process I had my project in and turned on catch all exceptions. Then when the exception was thrown I looked at the AppDomains assembly list, System.AppDomain.CurrentDomain.GetAssemblies(), 55 in all were loaded. I then looked through this list for the assembly referenced in the exception. This assembly then had the following location value: Location "c:\\Program Files (x86)\\Microsoft Silverlight\\4.0.51204.0\\System.Windows.dll". This is the main Silverlight 4 runtime, NOT the Windows Phone version which is 3.7.x, to be certain I then opened the assembly in Reflector to be sure the System.Net.HttpUtility was missing and it was.

So as suspected the designer is loading the wrong assembly thus the error, the assembly it should be loading is in the referenced assemblies folder, C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone\System.Windows.dll , hopefully reporting this on Connect will result in a hotfix / update.

Thursday, 16 December 2010

MVC 3 RC2 Install Error (0x80070643)

This evening I came to installing MVC3 RC2 on both my desktop and laptop. The laptop installed first time, however I found that on my desktop it refused to install. Citing the following error in its install log: Installation failed with error code: (0x80070643)


After poking around in the log file I found that the VS10-KB2465236-x86.exe patch was where it was falling over. To try and get more information I found the temp directory with this file in and ran the installer manually. This also as expected errored, however this time when I looked in the log file I found a slightly different error: Install failed on product (Microsoft Visual Studio 2010 Express for Windows Phone - ENU)


The next obvious place for me to go next was to uninstall the Windows Phone Developer Tools, I figured I can always reinstall them. Upon removing this I then tried to install MVC3 RC2 again. This time it still failed, with the same error I had previously but this time for Visual Studio 2010.


As a final shot I wondered if the Visual Studio 2010 SP1 beta may have had the patch in and was causing some sort of a conflict. As such if I skipped the KB2465236 patch and simply installed the rest of MVC3 seeing if it would work OK.


It turns out I did manage to get it all installed, I had to grab the MSI Installers out of the temp directory that the main MVC installer creates and then run the installers in the following order: aspnetwebpages.msi, aspnetwebpagesvs2010tools.msi, aspnetmvc3.msi, aspnetmvc3vs2010tools.msi and finally nuget.msi
VS2010 now has the new templates and so far everything looks in order. This is a bit of a risky way of installing MVC3 RC2 but for me it works, if you have this issue and want to try bypassing the KB patch then I hope this has helped

Wednesday, 21 January 2009

Visual Studio Welcome Screen

Today a colleague noticed that whilst he was debugging his web application random requests were being made to Microsoft, these requests were also returning a HTTP/1.1 301 Moved Permanently header, and apart from being annoying was causing him a few issues.


From experience I soon realised that these requests were being made by the Visual Studio Welcome Screen. By default even if you don't use the welcome screen, Visual Studio keeps the Start Page News Channel RSS Feed up to date, the default in every 60 minutes. If you aren't using the welcome screen then its probably worth disabling the RSS feeds auto download content functionality, not only will this stop you seeing random requests, if you even notice them, but if you are working on a mobile and pay per KB save you some bandwidth.


To disable the auto content update simply: goto Tools > Options, click the Show All Settings checkbox, then under the Environment leaf find Startup. Once here simply untick the "download content every" check box. You can also configure it to update less frequently, alter the news channel location, for example you may prefer to use the DotNetShoutOut RSS Feed.

Monday, 19 January 2009

Syntax Highlighting and Intellisense for WSC Files in Visual Studio 2008

Recently I've been working on a system that makes use of custom WSC components. These components contain the usual XML Wrappings and then a large CDATA area containing the VBScript code.


What's really been bugging me is that Visual Studio was treating all the code within the CData XML Area as XML and I really want the VBScript to be all nice and highlighted and for VBScript intellisense to kick in, it really does save time. Now luckily making this happen was remarkably easy.


First within Visual Studio go to tools and options, click Show All Settings. Then open the Text Editor leaf and click on File Extension. Next add a new option for wsc files and specify that you wish it to use the Web Form Editor as it's editor. Click Add and then OK. You should now find when you next open a wsc file the XML has syntax highlighting as well as the VBScript, and intellisense works!


I hope this helps you, it certainly did me!

Friday, 25 July 2008

LinqDataSource and Could not find a row that matches the given keys in the original values stored in ViewState.

Today I was working on something quickly where I used a LinqDataSource, to keep things simple I attached a simple list view to it and had insert, update and delete operations.


Insert operations seemed to work OK however when I came to do an update to an existing item it crashed out

   Could not find a row that matches the given keys in the original values stored in ViewState.

Initially I thought that maybe some databinding had gone astray but this wasn't the issue. As I hadn't used design view but source view to create the ListView had missed off the DataKeyNames attribute, this meant that upon update the LinqDataSource was trying to match all my values against the database, of course it couldnt do this. By specifying the DataKeyName to match against, usually your Primary Key if using LinqtoSql, not only do you limit how much matching and work your LinqDataSource has to do, but also you'll find you can update :D


So quick tip, if you get "Could not find a row that matches the given keys in the original values stored in ViewState." double check your ListView, FormView, GridView etc has the DataKeyNames set.

Monday, 14 July 2008

Build failed due to validation errors in. dbml

OK so I got in today to find that I was unable to build my current project, I got the following

Error 1 Build failed due to validation errors in C:\xxx\DB.dbml. Open the file and resolve the issues in the Error List, then try rebuilding the project. C:\xxx\DB.dbml 2

I opened the projects dbml files to find that these files were fine, no errors or typos, the project was just dead. a little bit of Googling lead me to find that its a problem with Visual Studio 2008 not loading an assembly correctly, in particular the one with a GUID of 8D8529D3-625D-4496-8354-3DAD630ECC1B

In order to load the assembly correctly you need to get Visual Studio to reset it's packages, to do this:

  1. Open a new command prompt
  2. Navigate to C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE
  3. Run Visual Sudio with the /resetskippkgs argument: devenv /resetskippkgs

You should now find that your project opens and builds correctly! I'm hoping that maybe SP1 of Visual Studio will correct this, if not SP2 maybe...

Update: SP1 Didn't fix this :( Also worth noting if you are running a 64 bit OS then the visual studio folder path is C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE

Tuesday, 19 February 2008

So What is it Code Behind or Code File??

Recently I have been working on a web project in VS2005. All has been going well, several class files, several pages, and a few web controls all make for a project of fun.


I came back to work on the project, and I happily added a few more web controls, compiled the site etc and got some work done.


Now here's where things began to go wrong, after some lunch I reopened my project, but this time I opened the projects solution properly. Did some work, then went to build the solution and..... It broke. :( Now a project not compiling occurs frequently, ie rubbish code, but this time it started winging on how all my controls in the custom web controls that I built before lunch were now out of scope.


Frustrating. I started poking around and tried to find the issue, and I couldn't find anything. It was at this point that I looked at my .ascx file and not the .ascx.cs


With ASP.Net you can have code seperation. Content in one file, .ascx if a control and logic in another.ascx.cs. This is called code behind, and in the content .ascx file you normally have a reference that links the logic file, .ascx.cs to the content control.


This is where my issue was. ASP.Net 1.1 used the syntax CodeBehind, and the code in the file was classed as a seperate class. .Net 2.0 however introduced partial classes and as a result Microsoft added the CodeFile syntax. This syntax CodeFile doesn't include the full code-behind class declaration, instead this is generated on page compilation. The page compilation step automatically generates members for each control and these are then fused with the CodeFile's partial class.


My issue was that my file was using the CodeBehind syntax. Although this is still supported in .Net 2.0, during the page compilation step of the build the generation of the members partial class is missed out. .Net 2 assumes that the codebehind file is a full class, not a partial class.


Now this is ok, as long as your code behind file contains a full class and not a partial class .Net 2 will compile the code using the old method. But somehow, and I'm still not sure how my Content file, had changed to using CodeBehind instead of CodeFile. Initially I missed this as CodeBehind isn't necessarily wrong, in the correct context.


Changing codebehind back to codefile corrected the issue and the partial classes were generated and fused properly.


After searching the net I also found that this can occur after upgrading a vs 2003 .net 1.1 project to vs 2005 .net 2.0 Web Application project and seems to cause a few people headaches.


So there you have it, if you find your code won't compile suddenly or after converting a 1.1 project to a 2.0 Web Application project, with your controls being out of scope, check whether you're using codebehind with partial classes and if so change to CodeFile.

Thursday, 24 May 2007

More Vista Tips - IIS 7 and Visual Studio 2005

IIS 7 Woes

Tonight I decided to carry on with Old Roan's site, I havn't touched it since I reinstalled Vista on the weekend. Everything is running pretty sweet now, even got my "New Day" office 2007 installed. All was grand. Until I resetup the old roan site in IIS7. When I tried to view the site: oldroan.mjjamesdev.mj for example I got a nice: HTTP Error 500.19 - Internal Server Error Yummy, after about 10 mins of faffing I realised that the security permissions on the folder were set to, Administrators, Creator Owner and my user only. When copying the data back to my main drive off my backup the Users group got lost. So a quick add user group with read and execute permission solved everything.

Visual Web Developer Express 2005 Woes

By default, the VS 2005 range including the express editions don't like IIS7. When you try to open a site that you have running in IIS7 its says the product is not compatable. I was gutted to hear this but for the past month I have been using Vista I never really thought much about it as I know 'Orcas ' is only around the corner. However stumbled upon Scott Gu's Blog article detailing how to get it all working. Needless to say this is great and really does help :D

Monday, 19 March 2007

Orcas

This is the first of a couple posts I'm hoping to get finished tonight, the other two are in progress but I don't want to post them until I finish some other bits and pieces. Back to this post though. Saturday I was finally able to get all the Visual Studio Orcas downloads, and I got myself Virtual PC 2007, uncompressed the base and orcas files to give it a whirl. Now i know its CTF so you have to be patient however what I experienced yesterday was far from good :( Upon creating my new virtual machine as per the site's instructions I was presented with an error. Instead of being able to update and choose the location of my base image for the orcas machine i get the browse file window, find my file, and then click open . . . . and that's it nothign happens, you can click open as much as you want but nothing happens :( Bit of a major error as Orcas won't work without it. I then tried to load the base image. This loads up fine but could I login with the login details provided by Microsoft, hell I couldn't :( After a few searches on le Google I found that the password is actuall P@ssw0rd, not P2ssw0rd. Error 2 for Microsoft. (Error 1 was my image not wanting to update) So of course I'm now confident I can load up my virtual image just to play with Windows Server 2003 at least. Well not quite, P@ssw0rd wouldn't work either. By this point I'm pondering if I continue this venture or just give up. However not being a quitter, well often, I decided to Google my new problem. Low and behold the answer came quite quickly. Basically the Base PC image its expecting by default a US keyboard, so to get an @ you do shift + 2, I had naturally assumed that Virtual PC made this conversion for you, as that's the logical thing to do. Keyboard Mappign can't be that hard, especially as it was a Microsoft OS I was virtualizing, now armed with the solution I tried logging in again P"ssw0rd. As you can imagine I was quite happy when it logged in, however I was surprised by the fact you have to activate your windows :( very odd in my books, especially as I had disabled the network card emulation as I didn't really want Server 2003 on my network. Any how after activating the network and rebooting Windows booted fine and activated. However I still can't run orcas as the stupid orcas image wouldn't update. When I find out why I will post my solution here so other people can not be bogged down by these issues. I'm hoping to see how good orcas is one day. Probably not today though :(

Thursday, 8 March 2007

Learning ASP.Net 2 Part 1

I started this Blog so that I could document my experiences of Web Technology and how I have found using them etc. One of my keen areas of interest was going to be learning .Net 2. Sadly this has yet to happen as I have been busy with work and some old PHP stuff. However I have been given a project by my church to build them a new website that will allow an editor to maintain it but also to have an events calendar and to provide podcast feeds. I was thinking to either use an old basic CMS system I had made in PHP or to use a free open source CMS system. But after some thought I came to the conclusion that this would be a great project to learn .Net with. So this evening while the wife's away I started. Yesterday evening I messed around with some tutorial videos on .net and Ajax but tonight I started writing my own code. I won't bore you with all the details but tonight I got a rough db design together, made a basic page that currently lists the page table and allows you to sort these as well as feature paging. I also started the add/edit page and got it inserting data into the database. What I have noticed so far is how easy it is to use controls, tonight I have used grid view and form view and tailored them as needed. This makes such a change from PHP and ASP where everything is so manual and lengthy. I also got FCKeditor working in .Net and as a control in Visual Studio Express. This was easier than in ASP or PHP and having IntelliType while setting it up made a huge difference. One thing I didn't sort tonight was default values for my form inputs, this frustrated me as I could bind the fields to the db or have a value, sorting this will tomorrow night's first task. So far I'm liking .Net, C# is quite natural as I have used C++, Java and PHP in the past and Visual Studio Express is a great tool, so hopefully tomorrow things will go onwards and upwards :D.