This blog has, IMO, some great resources. Unfortunately, some of those resources are becoming less relevant. I'm still blogging, learning tech and helping others...please find me at my new home on http://www.jameschambers.com/.
Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Monday, February 28, 2011

Fixing “Unrecognized configuration section userSetting” Errors

Though I have not seen the error “Unrecognized configuration section userSetting” as a standalone exception, it has come up a number of times for me and surfaces as the inner exception on a “Configuration system failed to initialize” exception.

If you’re running into this error and following along, I’m currently using Visual Studio 2010, mostly on .NET 4.0 and I program in c#.  If you’re using a different environment some of the file names or UI might be a bit different, so you’ll have to adjust accordingly.

The exception will be raised in Settings.Designer.cs, on the first attempt to read a value from the application’s configuration.

You can fix the error by navigating to the current directory where the user settings are being saved for your app.  This will be in %system%\users\your_user\AppData\Local\Microsoft\YourApp.vshost.######\version

Delete the user.config file, clean your solution and rebuild all.  This should fix the problem.

If that doesn’t work, you may need to go so far as to shut down Visual Studio, clean out all the %system%\users\your_user\AppData\Local\Microsoft\YourApp directories of any config files and then follow the above steps.

What’s Happening?

When you first add a setting to the application through the UI, the default is to create a user-scoped setting.

image

User settings and Application settings are primarily different on two fronts:

  1. Storage location
  2. Run-time accessibility

User settings are read/write and can be altered at run-time. These are perfect to save things like favorites, window layout, user-specific options, color preferences and the like. These files are stored in a directory created for the application, basically sand-boxed from system-wide access and the only place your app can read/write from for free (elevated privileges aside).

Application settings are read only at run-time and can only be altered by changing the XML file and relaunching the application, or by some creative XML file management (and then a reload on your configuration data).  These files are stored in the app directory in app.config and also contain the default settings for users who have not yet launched the app (these are the settings that will be defaulted in for the new users).

I have hit the “Configuration system failed to initialize”Configuration system failed to initialize error a couple of times, and it always seems to be the User scope default biting me in the arse.

Basically, I create a setting, plug along for a while, then go back to add another setting and realize that I had left it in user scope.  I switch the first setting to application scope and keep plugging away.  Somewhere between then and the next time the application tries to access that property, the exception is thrown and doesn’t give you much detail at the surface level.

Figuring out the Files You Need to Delete

I said you can likely delete the user.config files without much regard.  Truth is if you’re into testing something settings-related that can be a real inconvenience.

I will drill into the inner exception to find the problem file; it’s only two deep, so it’s easy to find the path of the file in question if you’re willing to dig. 

Trust me, folks, your debugger is your best friend.

Monday, November 23, 2009

Sorting Out Entities with Multiple Relationships in LINQ to SQL

There is a very common scenario in data design where you define a table as having two relationships with a single (other) table.  This especially comes into play if you have anything in your model with an “assignment” where someone assigns something to someone else.

In this case, We are tracking work tickets that are created by someone for someone else.  Both are stored in the ticket table.

image

Above is a snip from the DBML designer for LINQ to SQL. The two arrows represent the relationships between Person and Ticket, namely, that CreatedFor and CreatedBy are Person references.  If you have set up the foreign keys in the database, these associations are created for you automatically.

Convenient, yes, but code-revealing, no.  Here’s the result of the default naming as a result of the relationship being automagically created:

image

Now, which is which?  Are you looking for Tickets or Tickets1?  The default method for selecting a name is pretty ambiguous.

Directing LINQ to SQL Naming

Thankfully, the designer gives us a way to control the code generation tool and its naming conventions.  Click on one of the association lines on the DBML canvas and look at your properties windows.  Verify the members that are in use in the “Participating Properties” property, then drill into the Child Property detail.

There, you can set the name of the Child property to something more meaningful to developers using your code down the road.  Or, for yourself six months from now.

image You also have a chance to disambiguate the Parent property.  And, as a result, you have more readable syntax working from the child and walking to the parent record.

Friday, November 6, 2009

Installation of TFS 2010

If you’re installing Team Foundation Server 2010 and you run into error TF255352 you might have a problem with your firewall.

Here’s the text of the message:

Permissions could not be verified because an error occurred while communicating with the following report server: [my server] 

And also, in a second warning:

The server returned the following error: The report server cannot open a connection to the report server database. A connection to the database is required for all requests and processing.

I missed a step in the install guide (how can you not…it’s just under four billion pages hehehe) and didn’t configure my firewall.  After adding the required port exceptions, I reran the pre-check, got all green lights, and installation continued as planned.

Wednesday, October 28, 2009

Badass Box Selection

Brittany Behrens on Monday re-introduced the much-improved version of Box Selection that came out with the Visual Studio 2010 Beta 2 bits.  I was stoked about this earlier in the year.

I’m continually surprised when I see how many of my friends aren’t aware of so many of the time-saving tools that exist inside Visual Studio.  It feels more and more like you can “run” when you code and less and less like you have to push through it.

I found a neat little compound trick using a couple of the features that I routinely exploit.  Starting from essentially the same place as Brittany, I copied and pasted a list of variables into some multiline Console.WriteLine statements.  That was pretty cool.  Like Brittany, I was left with a series of semi-colons that I wanted to remove. 

To get rid of the punctuation, I simply redo the box selection and then invoke the Find and Replace dialog with Ctrl-H:

image

From there, I can employ a simple matching technique and scrub the semi-colons.  Just make sure you have Look in: Selection selected and hit Replace All.

If it were a more complex scenario, I could have also used regular expressions in Find and Replace (located in “Find Options”) to be more discerning on the text I was replacing. 

I Like Pushing Arrows

There is something else in here of a hidden gem that wasn’t fully revealed in the video but that I picked up on (I heard Brittany tapping on the keyboard and had to try it out): using the cursor keys while holding down Shift allows you to “walk the box” and change the shape of the selection.

After using Alt+Mouse or Shift+Alt+Arrows to box-select, use Shift+Arrows to alter the target of the selection. 

Let me Choose!

One thing that I liked in the video was that the white space was copied as well.  This left the pasted text block-aligned and ready to go.  The video obviously pre-dates the version of box selection in Beta 2, however, because as you can see from my above image, there is no whitespace after my variable names (watch the video to see the difference).

I think it would be good to have some optional, intermediary dialog box that you could call up (perhaps a la Office-Ctrl tapping) that would allow you to preserve or remove whitespace, punctuation, etc. 

I suspect that the visibility of the selection is made available to any plug-ins, but I also hope there is something by way of box selection events so that context menus can leverage this.  Not having worked with the extensibility bits around selection in the editor, I’m not sure if you can distinguish between box selection and stream selection when creating something to extend the IDE.

Monday, September 14, 2009

Have to admit…

…I’m getting tired of seeing this five times a day:

image

Looks like it’s time for the Windows 7 upgrade.  I’ll start that tonight after work.

This is totally related to me forcing 32bit drivers on a 64bit OS, so, in that I’m not changing hardware, I’ll likely install Win7 32bit.

The biggest part of my day is spent in Visual Studio, for which there is no 64bit version (yet) so I’ll just hang back in the world of 32bittedness for the time being.

Monday, August 24, 2009

Visual Studio 2010 Toolbox

I’ve been flipping through Visual Studio 2010 for the last little while and I think I’ve come across something that would be really useful.  This isn’t an original idea, by far, but one that would bring a more modern take to the good old toolbox.

Here’s what you might see when you start up a new project in 2010:

toolbox selections in Visual Studio 2010

Pay no mind to the drawing errors on those expanders; I think this is a display bug in Visual Studio 2010 when you’re using a bigger font in your visual settings in Windows 7.

Beyond the stretchy plus sign, there is a fairly good categorical breakdown of all the controls types in Visual Studio.

What’s missing?  Search. Check out what they’ve been doing in Adobe After Effects for eons. 

With the contains filter up at the top, you are easily able to narrow down to effects (in this window), project items or elements on a composition timeline.

Take that one step further, now: what if I could type in “panel”, and any control that had “panel” in the name or the description tags would appear.  This would certainly helpful, especially if there was a “related items” filtered list as well.  So, I search for panel and see FlowLayoutPanel and Panel, but I would also see – under ‘related items’ – SplitContainer, TabControl etc.

Friday, June 5, 2009

Can’t Add New Items to WPF ModelView Application Projects from MVVM Template

I am running into a problem under certain circumstances with projects created by the WPF Model-View template for WPF applications in Visual Studio 2008.

When I try to add a new class to a project through the Visual Studio 2008 IDE I receive the following error message when I try to add a new class (or icon, LINQ to SQL file, etc):

image

I can reproduce this easily:

  1. Open Visual Studio 2008 (with the WPF Model-View-ViewModel Toolkit installed, download here).
  2. Create a new c# project with the new template.
  3. Accept the default and have it add a test project as well.
  4. Right-click on the Models folder, then Add->Class.
  5. Choose your name and click Add.  The error above is displayed.

I am running Vista 64, Visual Studio 2008 SP1 with .Net 3.5SP1. There are no add-ins loaded except the debugger. I do not (typically) run as Admin, but this makes no difference in this case as the same behaviour is observed either way.

I do not see this problem if I do not add the test project.

Thursday, May 28, 2009

Visual Studio 2010 – WPF Designer

The new WPF designer is quite exciting, as are many of the features that are coming down the pike for us developers in Visual Studio 2010.

Karl Shifflett posted a link to the new designer intro videos on WindowsClient.net last night and I had a dive into them.  The coolest-ever-IT-d00d at my office is in the process of building me a Win7+VS2010 virtual machine as I write this. Yum.

Of note for me are the following:

  • The visual appeal isn’t quite my thing, but I’m getting to be an old guy and am actually a fan of the existing environment.  On the other hand, I love Expression Blend and its apparent ‘awareness’ of certain things, so I’m encouraged that Visual Studio 2010 seems to be moving in that direction.
  • The Data Source tool window has had some long-overdue features added to it, such as awareness of foreign-key relationships.
  • The draggy-droppability of the designer from the highly-aware Data Source tool window is ridiculous.  Before you get too critical of using tools to do those kinds of things (I have some buddies who just hate using code-generation tools and are hesitant to switch to .Net because of it), be sure you check out what’s really going on.  All of the binding you would do by hand is being done – elegantly, I might add – behind the scenes for you.  There is no locked-in overly-cumbersome data binding through properties that makes you rip out what little hair you have left…uh…oops.  Flashback to WinForms…
  • The WPF designer has had some really nice updates to it to handle things like layout for grids.  Again, this is a vehicle for code-generation of sorts, but the extra design-time help is great for keeping you in one place.  I am not a fan of having to ride three different work areas to accomplish a task, that being the designer, the properties tool window and the Xaml editor. This is a welcome change. You can now switch between column sizing modes on-the-fly from the editor, as an example, giving you richer control over the layout.
  • There are improvements as well to the workflow of adding and displaying images in projects.  While this wasn’t terrible before, how and where it handles and stores images is more streamlined and path syntax is created dynamically (as it was in 2008, but there is a UI for this now).
  •  imageMuch like the WPF designer in Visual Studio 2008, we have search functionality in the Properties/Events tool window.  This is especially important with the emerging model of binding, preview events and the like.  If you aren’t already using this, give it a try.  The screenie to the right is from 2k8.  The Properties tool window is quite enriched and better reveals data binding status and options.
  • The search functionality has been applied to the new resource selector, as well, allowing us to quickly filter through the dozens of brushes, paths, etc. that we may have in our project.  I have to admit that this is a little bit of validation for me.  My resource libraries have grown significantly over the last little while; that they have implemented search capabilities indicates that the way I style my app is common to the community ;o)
  • It seems that the Properties tool window is getting some much-needed love.  The in-line editors for properties are not so shallow.  A control’s font, for example, has a more Word-like property editor streamlined into the property editor.
  • Data binding during the design story has been quite enhanced.  Drilling into a composite type that the designer has bound for you allows you to drill into that type, select an appropriate converter and get away from MyObject.ThisNameSpace.TheClassIWrote being displayed in your label, for example.  This is part of that “awareness” I was talking about that makes the experience more fluid.
  • The tab page for the IDE is now akin to IE’s tabbing functionality.  While I do prefer this to the style of Visual Studio 2008, I am a greater fan of the Google Chrome approach, where hovering over a tab allows me to close it without having to bring the tab to the foreground.

There was a mention in one of the videos that multi-control selection and property setting would be in the release version of Visual Studio 2010 (so, you’d be able to select four controls and set a brush for the background).  I also hope that they consider a resource palette, so that I don’t have to drill into the properties window and a popup box to achieve the same result.

I’ve also wondered why there isn’t more made of the mouse.  We aren’t too low on the experience level here, as developers, so I think that more encompassing experiences should be worked into the developer experience through that simple rodent we keep on our desk.  Middle-click, anyone?  If I were working on Visual Studio 2010, I would have tried to create accelerators with the mouse.  For example, if I highlight a block of code and middle-click, bring up the refactor menu (instead of going through the right-click submenu).  Similarly, if I’m in the designer and right-click on a control, give me the context menu related to styling and applying resources.  Again, I like to stay in one place and have the in-context toolset at my fingertips.  Especially my middle finger.  Always proves handy.

I will come back with more when I get my hands a little more dirty with the 2010 beta.

Tuesday, May 19, 2009

Because I Always Keep Digging…

I just realized that I like to make things harder than they need to be. ;o)

If you want to paste files into Visual Studio, you don’t need to go the add to project route I just wrote about, you can just navigate to the source directory (as in my previous post), copy the files and then return to your target solution (in Visual Studio) and paste the files into the desired folder.

This not only pastes a copy of them into the right directory, but it also adds them properly to the project without having to do the “Show all files” thing.

Copying Files from Solution to Solution

(…or from project to project in another solution!)

I do a fair bit of spiking before I get into the thick of things with code (anyone who’s worked closely with me has seen my endless projects in my Spike directory). 

It can be frustrating if you’ve got a collection of small classes that you’d like to copy from one of your spikes to a new project/solution to start unit testing.  Visual Studio does not allow you to copy from the solution explorer, switch to the other Visual Studio instance, and then paste the files.  Instead, you get the following error:

The source files for this operation cannot be found in this solution.

While it’s a bit of a pain-in-the-arse, there is a fairly simple workaround to this.  image

Start in the solution with the files you want to copy.  Right-click on the containing folder (or the project) and click Open Folder in Windows Explorer.

Next, using Windows Explorer, select the files that you want to copy and put them on the clipboard.

Flip over to your target solution, and find the project or folder that you want to put the files into.  Use the same right-click trick to open the folder location on the hard drive.  Now, paste the files into this directory in Windows Explorer.

Lastly, return to your target solution; here, we have to let Visual Studio know that these files are part of your project.  Even though they are in the project folder, they won’t be included and can’t be image referenced until you express your interest in doing so.  Select the target directory and click on the Show All Files icon in the toolbar for Solution Explorer.  Your new files will now appear in the project, but they will have a different icon.  Select them all (use shift-selecting or ctrl-selecting if you need to) and right-click to reveal this menu:

image

Click on Include in Project and you’re set.  Now you can move classes and resources from one project to another using Visual Studio (and Windows Explorer).

Thursday, May 14, 2009

Open a Project in Expression Blend from Visual Studio

If you work in both Blend and Visual Studio you will notice that there are significant gaps in functionality between the two.  In Blend you get a rich design and animation interface (and it looks way cooler, too) but don’t get some of the much-needed development tools.  In Visual Studio, you get productivity-focused tools like intellisense but lose out on easy storyboard manipulation and the like.

Basically, if you do at least a little of design and a little of development, you need to be running both Expression Blend and Visual Studio.

From within Blend there are a number of actions that will result directly in Visual Studio opening (such as drilling into a click event on a button) if you have Visual Studio installed.  However, Visual Studio doesn’t reciprocate the favour when you’re looking for something more design-friendly.

To open your project in Blend directly from Visual Studio, you’ll need to hack together an external tool link.

image

Go to Tools –> External Tools in Visual Studio and add a new entry to the menu contents.  You can set your title to whatever you like (I used Send to &Blend).  Your Command should be set to the path for the EXE where you have Blend installed.  Lastly, set the Arguments property to the following:

$(ProjectDir)$(ProjectFileName)

…which will tell Visual Studio to pass the current project path and name to Blend as it opens the project.

Happy Blending!