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

Thursday, 29 May 2014

Visual Studio 2013 Update 2 – Navigation Bar Dropdowns not working

Seems as though the VS team introduced a bug in Update 2 for Visual Studio 2013, where the Navigation Bar Dropdowns don’t work if you are using VS on a screen which is to the left of your “Main Screen”;

image

When you have VS running on your second (or third) monitor, clicking on the Navigation Drop Downs has no effect;

image

In order to workaround the problem, you either need to set the screen you have VS running in as your main screen, using your graphics properties, or alternatively move VS to your main screen……

Frustrating…

Hopefully this will be cured in a future update..

Wednesday, 26 June 2013

Knockout (or any javascript) Intellisense not working if move script file locations

I found while playing around with Knockout.js, that my Visual Studio Intellisense wasn’t working. This turned out to be because I had formatted my Scripts folder, and moved standard Javascript libraries into another folder.

This meant that Visual Studio couldn’t find my _references.js file.

At first I added the following to the @Scripts Section in my .vbhtml file;

   1: @Code 
   2:  
   3:        If (False) Then
   4:  
   5:            @<script src="/Scripts/lib/knockout-2.2.1.debug.js" type="text/javascript"></script>
   6:                
   7:        End If
   8:              
   9: End Code
Where the If (False) code forces the compiler to ignore the file when publishing.


But this would end up being silly if I had lots of files. So, I had a quick look around and found a couple of useful answers on Stack Overflow;


http://stackoverflow.com/a/12016530/1305169 and
http://stackoverflow.com/a/12628049/1305169


Where, basically, you need to add a reference to your new _references.js file to the Intellisense list options in Visual Studio;



  • In Visual Studio, go to Tools > Options > Text Editor > Javascript > Intellisense > References
  • In the “Add a reference to current group”, type in the relative path to your _references.js file (for me this was “~/Scripts/lib/_references.js”

Hey presto, you should now have working intellisense!

Friday, 7 June 2013

SGEN: Mixed mode assembly is built against version 'v2.0.50727'…

I found while building an VB application in Visual Studio 2012, in release mode for the first time, that I was confronted with cryptic build error;
SGEN: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
After trawling through some Google results, I found the following post by Microsoft;

http://social.msdn.microsoft.com/Forums/en-US/clr/thread/2a5bf31e-df96-4bf1-a846-699da46b62fb

And also a couple of forums;

http://stackoverflow.com/questions/3749368/team-build-sgen-mixed-mode-assembly
http://social.msdn.microsoft.com/Forums/en-US/clr/thread/2a5bf31e-df96-4bf1-a846-699da46b62fb

Which suggests adding (or creating if it it doesn’t exist already) the following XML to the sgen.exe.config file;
<?xml version ="1.0"?>

<configuration>

    <startup useLegacyV2RuntimeActivationPolicy="true">

                <supportedRuntime version="v4.0" />

    </startup>   

</configuration>
For .Net 4.0 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools  (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools (for x64 systems)
For .Net 4.5 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools (for x64 systems)
Edit - 03-06-14:

For .Net 4.5.1 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.5.1 Tools (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.5.1 Tools (for x64 systems)
Once I’d added the xml, the application built just fine.

The other alternative was to disable the option to Generate Serialization Assemblies in the offending project;

  • Project Settings for the offending Project
  • Compile Tab
  • Advance Compile Options Button
  • Set “Generate Serialization Assemblies” from “Auto” to “Off”

However, I recommend that you go with the XML option as suggested by Microsoft.

Tuesday, 4 June 2013

Adding EF POCO Classes to TFS Source Control

I have various projects which included Entity Framework POCO (Plain Old CLR Object) Classes. By default, these are not automatically included in TFS Source Control.

To add these classes in VS2012;

  1. Open the Team Explorer Window using View>Team Explorer
  2. You will see a list of shortcuts... My Work, Pending Changes and so on;
  3. Under "Pending Changes" is a link to "Source Control Explorer"
  4. Click this link, to open the Source Control Explorer Window
  5. Navigate through your solution to the Project containing your edmx file
  6. Above the "Source Location" will be a toolbar
  7. The fourth icon from the left is "Add Items To Folder"
  8. Clicking this icon will bring up the "Add to Source Control" Dialog, showing all the files in this project which aren't currently under Source Control.
  9. Select all the files you wish to now include under Source Control
  10. Press Next, then Finish

Now Check In your Solution again, and your POCO's should now be included.

Visual Studio – Solutions not configured for Integrated Source Control

I recently ran into an issue where, when I opened up one of my Solutions which were under TFS Source Control, I was presented with a message box which showed;

The solution you have opened is under source control but not currently configured for integrated source control in Visual Studio. Would you like to bind this solution to source control now?

Turns out that this is Visual Studio’s way of telling me that parts or all of my solution isn’t bound correctly to the source control provider.

To rectify this issue I needed to;

  1. Open the Project directly using Visual Studio, rather than with the Source Control Explorer
  2. Goto File ->Source Control –>Advanced –> Change Source Control

This will open up the “Change Source Control” dialog, which shows which items in your solution are bound and which aren’t.

From here you simply need to select which Items need to rebound and hit the “Bind” button.

Visual Studio will then checkout the unbound items, and you then need to check them back in, and your done.

Tuesday, 21 May 2013

Binding the WPF WebBrowser Source Property

In an MVVM application I am currently creating, I had the need to embed the WPF WebBrowser control and quickly discovered that the Source Property is not a dependancy object, and so cannot be bound.

I quickly search around on StackOverflow.com and found a neat solution in c#;

http://stackoverflow.com/a/265648/1305169

The VB Version of which is;

   1: Namespace Helpers
   2:  
   3:     ''' <summary>
   4:     ''' Allows for the Source Property of the WebBrowser to be Bindable to the DataContext
   5:     ''' </summary>
   6:     ''' <remarks></remarks>
   7:     Public Class WebBrowserUtility
   8:         Private Sub New()
   9:         End Sub
  10:         Public Shared ReadOnly BindableSourceProperty As DependencyProperty = DependencyProperty.RegisterAttached("BindableSource", GetType(String), GetType(WebBrowserUtility), New UIPropertyMetadata(Nothing, AddressOf BindableSourcePropertyChanged))
  11:  
  12:         Public Shared Function GetBindableSource(obj As DependencyObject) As String
  13:             Return DirectCast(obj.GetValue(BindableSourceProperty), String)
  14:         End Function
  15:  
  16:         Public Shared Sub SetBindableSource(obj As DependencyObject, value As String)
  17:             obj.SetValue(BindableSourceProperty, value)
  18:         End Sub
  19:  
  20:         Public Shared Sub BindableSourcePropertyChanged(o As DependencyObject, e As DependencyPropertyChangedEventArgs)
  21:             Dim browser As WebBrowser = TryCast(o, WebBrowser)
  22:             If browser IsNot Nothing Then
  23:                 Dim uri As String = TryCast(e.NewValue, String)
  24:                 browser.Source = If(uri IsNot Nothing, New Uri(uri), Nothing)
  25:             End If
  26:         End Sub
  27:     End Class
  28:  
  29: End Namespace

You then use your new Bindable Property in the XAML as;



<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
    xmlns:Helpers="clr-namespace:FrontEnd.Helpers"
    x:Class="frmKiosk"
    x:Name="Window"
    
    Width="1920" Height="1080" WindowStyle="None" WindowStartupLocation="CenterScreen" WindowState="Maximized" Background="#FF1327D0" Cursor="None">
 
    <WebBrowser x:Name="wbMain" Helpers:WebBrowserUtility.BindableSource="{Binding KioskWebAddress}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
 
</Window>

Then simply creating a Property in the DataContext, and setting the source like;



KioskWebAddress = "c:/HTML/index.html"

Wednesday, 8 May 2013

Unable to open Database .SQL Files in Visual Studio 2012 Update 1 and onwards

This morning I attempted to open a .SQL file in my Visual Studio 2012 Update 2 installation, and was faced with the following Message Box;

enter image description here

Clicking the “Learn more…” link took me to a “Page Not Found” page, which wasn’t very handy.

A quick search on StackOverflow and I found;

http://stackoverflow.com/questions/15798422/what-about-sql-server-data-tools-for-vs2012-being-incompatible-with-sql-server-2

With a helpful answer by JorgenH directing me to update the SQL Server Data Tools found at this page;

http://msdn.microsoft.com/en-us/jj650015

I downloaded and installed the SQL Server Data Tools, shown at Step 2, from;

http://go.microsoft.com/fwlink/?LinkID=274984

Hey presto, problem sorted!

Wednesday, 2 January 2013

Adding EF5 POCO’s to TFS Source Control

While attempting to build my TFS based solution, the build failed reporting that it couldn’t find my EF5 POCO Classes.

After some digging around it seems that these files aren’t automatically included under TFS Source Control.

In order to enable this (For VS 21012), we must perform the following actions;

1. Open the Team Explorer Window using View>Team Explorer
2. You will see a list of shortcuts... My Work, Pending Changes and so on;
3. Under "Pending Changes" is a link to "Source Control Explorer"
4. Click this link, to open the Source Control Explorer Window
5. Navigate through your solution to the Project containing your edmx file
6. Above the "Source Location" will be a toolbar
7. The fourth icon from the left is "Add Items To Folder"
8. Clicking this icon will bring up the "Add to Source Control" Dialog, showing all the files in this project which aren't currently under Source Control.
9. Select all the files you wish to now include under Source Control
10. Press Next, then Finish

Now Check In your Solution again, and your POCO's should now be included.

As a word of warning, I have read that it’s possible to get Read / Write issues when performing this action. Allegedly, checking out the problem items will overcome this issue.

Tuesday, 1 January 2013

Setting Control Focus… The MVVM Way…

I needed to be able to set the Focus of a control, using MVVM. This means of course, that we can’t interact directly with the View, but instead must rely on Binding.

I found a very helpful post by Khalid Rafique which allows exactly this;

http://codenicely.blogspot.co.uk/2012/01/how-to-set-textbox-focus-in-silverlight.html

By making use of attached Interactivity Behaviours, we can Bind an IsFocused Property, allowing the focus of the selected control to be set..Very handy indeed.

The VB.net code is shown below;

Behaviour Class:

Imports System.Windows.Interactivity
 
Namespace Behaviours
 
    Public Class clsFocusBehavior
        Inherits Behavior(Of Control)
 
#Region "Properties"
 
        ''' <summary>
        ''' The IsFocused Property, which is a backing for the IsFocusedProperty Dependancy Property
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property IsFocused() As Boolean
            Get
                Return CBool(GetValue(IsFocusedProperty))
            End Get
            Set(value As Boolean)
                SetValue(IsFocusedProperty, value)
            End Set
        End Property
 
        ''' <summary>
        ''' The Has Initial Focus Property, which is a backing for the HasInitialFocusProperty Dependancy Property
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property HasInitialFocus() As Boolean
            Get
                Return CBool(GetValue(HasInitialFocusProperty))
            End Get
            Set(value As Boolean)
                SetValue(HasInitialFocusProperty, value)
            End Set
        End Property
 
#End Region
 
#Region "Dependancy Properties"
 
        ''' <summary>
        ''' Expose an IsFocused Dependancy Property to allow Binding
        ''' </summary>
        ''' <remarks></remarks>
        Public Shared ReadOnly IsFocusedProperty As DependencyProperty = DependencyProperty.Register("IsFocused", GetType(Boolean), GetType(clsFocusBehavior), New PropertyMetadata(False, Sub(d, e)
                                                                                                                                                                                               If CBool(e.NewValue) Then
                                                                                                                                                                                                   DirectCast(d, clsFocusBehavior).AssociatedObject.Focus()
                                                                                                                                                                                               End If
                                                                                                                                                                                           End Sub))
 
        ''' <summary>
        ''' Expose a HasInitialFocus Property, which allows Binaind dicating if the Control should be focuses Initially
        ''' </summary>
        ''' <remarks></remarks>
        Public Shared ReadOnly HasInitialFocusProperty As DependencyProperty = DependencyProperty.Register("HasInitialFocus", GetType(Boolean), GetType(clsFocusBehavior), New PropertyMetadata(False, Nothing))
 
#End Region
 
#Region "Helper Subs"
 
        ''' <summary>
        ''' Override the OnAttached Sub... Add Event Handlers
        ''' </summary>
        ''' <remarks></remarks>
        Protected Overrides Sub OnAttached()
 
            AddHandler AssociatedObject.GotFocus, Function(sender, args) InlineAssignHelper(IsFocused, True)
            AddHandler AssociatedObject.LostFocus, Function(sender, a) InlineAssignHelper(IsFocused, False)
            AddHandler AssociatedObject.Loaded, Sub(o, a)
                                                    If HasInitialFocus OrElse IsFocused Then
                                                        AssociatedObject.Focus()
                                                    End If
                                                End Sub
            MyBase.OnAttached()
        End Sub
 
        ''' <summary>
        ''' Used to simplify assigning the Target Vaues of Control Events
        ''' </summary>
        ''' <typeparam name="T"></typeparam>
        ''' <param name="target"></param>
        ''' <param name="value"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, value As T) As T
            target = value
            Return value
        End Function
 
#End Region
 
    End Class
 
End Namespace

XAML to add to View Header Namepaces:



xmlns:Behaviors="clr-namespace:CriticalPath_WPF_MVVM_EF.Behaviours"
             

XAML to add to control:




<i:Interaction.Behaviors>
    <Behaviors:clsFocusBehavior HasInitialFocus="False" IsFocused="{Binding DataContext.OrderNumberFocus, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"/>
</i:Interaction.Behaviors>

Code to add to ViewModel:



Private _OrderNumberFocus As Boolean
 
''' <summary>
''' The Order Number Focus
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property OrderNumberFocus As Boolean
    Get
        Return _OrderNumberFocus
    End Get
    Set(value As Boolean)
        _OrderNumberFocus = value
        OnPropertyChanged("OrderNumberFocus")
    End Set
End Property


Set the Focus using;



OrderNumberFocus = True