WPF problem in visual studio generated file g.vb “Namespace or type..

 

This warning was in the Visual Studio generated file. Warning is:

Namespace or type specified in the Imports ‘SRS.WpfControlLibrary1’ doesn’t contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn’t use any aliases. …SRS.WPF.Controls\obj\Debug\ucDataDrivenDGButton.g.vb 15 9 SRS.WPF.Controls

I had renamed the project and the Assembly name and the root namespace.

I did a search for the “SRS.WpfControlLibrary1” and found some required fixes/changes. Although I do not remember its creation this project used a Themes\Generic.xaml with an incorrect namespace, so I changed that.

The Generic.xaml seems to be special and in the AssemblyInfo.vb there was an attribute

<Assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)>

I also cleaned and built the project after the Generic.xaml update and now all ok

 

Similar Error

With VB Project Namespace change the .g.vb file references the old namespace.

Solution

The xaml had

xmlns:my1=”clr-namespace: … old namespace

Updated this and saved (possibly build also) and the project and the problem went away

 

End.

 

WPF datagrid takes a long time to load

Scenario

myDataGrid is in a simple WPF Grid control where a RowDefinition has a Height=”*”

<Grid >
   <Grid.RowDefinitions>
   <RowDefinition Height=”*” />
</Grid.RowDefinitions>

And if myDataTable has a large row count then the following may ‘hang’ or take a long time to load on following code:

myDataGrid.ItemsSource = myDataTable.DefaultView

The issue is that if the DataGrid is in a control that has unlimited height then it will render the whole DataGrid.

 

Solution

Options to resolve this include:

  1. Changing the RowDefinition Height
  2. Add MaxHeight to the DataGrid, so <DataGrid x:Name=”myDataGrid” MaxHeight=”1000″ />

Performance is then fine.

With thanks to: http://stackoverflow.com/questions/3336921/unreasonable-wpf-datagrid-loading-time

End.

Use Microsoft.Data.DataConnectionDialog in your projects to retrieve connection string

This is the use of the Visual Studio connection dialog in your own projects, for instance tool kits to inspect databases. Steps are:

  1. NuGet
  2. Search and add Data Connection (Windows Forms)
  3. Add code, sample is in VB, but C# is similar

 


Imports Microsoft.Data.ConnectionUI

    Private Sub GetDataConnection()

        Dim dcd As New DataConnectionDialog
        DataSource.AddStandardDataSources(dcd)
        dcd.SelectedDataSource = DataSource.SqlDataSource

        If DataConnectionDialog.Show(dcd) = Windows.Forms.DialogResult.OK Then
            Select Case dcd.SelectedDataProvider.Name
                Case DataProvider.SqlDataProvider.Name
                    Dim cn As New SqlClient.SqlConnection(dcd.ConnectionString)
                    DataSourceToolStripTextBox.Text = cn.DataSource
                    DatabaseDefaultToolStripTextBox.Text = cn.Database
                    'MessageBox.Show(String.Concat("Found SQL: ", cn.ConnectionString))

                Case Else
                    MessageBox.Show(dcd.ConnectionString)
            End Select
        End If

    End Sub

See also
http://wildermuth.com/2007/1/29/Using_the_Visual_Studio_Connection_String_Dialog

Change Team Foundation Server – The solution is in a directory mapped to team server …

Scenario

Project was on one TFS Server and you want to move it to another. In this case to visualstudio.com

How did I move the code to a different TFS Server

  1. First unbind the solution projects from the current TFS Server – TODO method
  2. Connected to the new TFS Server
  3. Right-click on Solution – Add solution to source control
    This returned message:
    “Change Team Foundation Server – The solution is in a directory mapped to team server …<the old server>
    Continuing will close the existing team server <the new desired server> and open team server <the old server>. Continue ?
  4. To resolve see steps in: http://support.microsoft.com/kb/957110. I did not do exactly as stated and instead backed up and then edited the VersionConfig.config:
    Note to self: If I get further problems then delete all the files and folders in the Cache as suggested in this web page
  5. Navigate to %userprofile%\AppData\Local\Microsoft\Team Foundation\3.0\Cache\VersionConfig.config
  6. I removed the whole related <ServerInfo> section, which in my case only had one mapped path.
  7. Appears to have resolved the matter

End.

WPF List Box

ItemTemplate – DataTemplate

            <ListBox ItemsSource="{Binding}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <StackPanel.Resources>
                                    <Style TargetType="TextBlock">
                                        <Setter Property="Margin" Value="0, 0, 5, 0" />
                                    </Style>
                                </StackPanel.Resources>
                                <TextBlock Text="{Binding Path=ID}" />
                                <TextBlock Text="{Binding Path=Task1}" />
                                <TextBlock Text="{Binding Path=PercentComplete}" />
                            </StackPanel>
                            <TextBlock Text="Resource names here" Margin="50, 0, 0, 0" />
                            <!--<TextBlock Text="{Binding Path=ResourceName}" Margin="50, 0, 0, 0" />-->
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

Sorting

        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"

        <CollectionViewSource x:Key="taskViewSource" d:DesignSource="{d:DesignInstance my:Task, CreateList=True}">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="CompleteFlag"
                                     Direction="Descending" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

 

Style DataTrigger

            <ListBox ItemsSource="{Binding}">
                <ListBox.Resources>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=CompleteFlag}"
                                         Value="True">
                                <Setter Property="Background"
                                        Value="Yellow" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ListBox.Resources>
...
            </ListBox>

Visual Studio 2013 and MSDN – a justification list

A location for me to add justification notes for upgrade to VS 2013 and MSDN Subscription

Visual Studio 2013

  1. WPF improvements
  2. Entity data model wizard – code first from database

MSDN Subscription

  1. Visual Studio online has more facilities including:
    Test cases

 

Learning WCF

With help from book “Learning WCF” by Michele Leroux Bustamante

Notes from working through samples:

Note 1:

Surprisingly it is possible/advisable to host the service from a different project or projects. This gives the possibility of one service to have different types of host running

Error 1:  System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://.. Your process does not have access rights to this namespace

Solution 1:

Run Visual Studio as an administrator

Error 2: App.Config does not have context menu option “Edit WCF configuration”

Solution 2:

Use Tools > WCF Service Configuration Editor then close it

Then right-click on App.Config and the “Edit WCF configuration” will be there

 

Error 3: ASP.Net HTTP Error 403.14 – Forbidden – The Web server is configured to not list the contents of this directory

Solution 3:

  1. IIS
  2. Select the web site
  3. Double-click Directory Browsing
  4. Enable

(Nice to have an easy problem)

 

Error 4: IIS – Web site – Configuration Editor – system.web/compilation – Bug Unrecognized element folderlevelbuildproviders

Solution 4

With thanks to:

http://forums.iis.net/t/1180915.aspx which led to

http://www.hanselman.com/blog/ASPNET4BreakingChangesAndStuffToBeAwareOf.aspx

If you install ASP.Net 4 and then install IIS then you need to make sure IIS is configured to know about ASP.Net 4 otherwise IIS will have no idea how to run ASP.Net 4 applications.

There’s a simple workaround:

  • If you are already in this state, drop to the command line and navigate to the FX install directory.  Then run “aspnet_regiis –iru“.
    • Note if you are on a 64-bit machine, run this command from the 64-bit FX install directory – not the 32-bit installation directory.

or for future reference, try to enable IIS and the ASP.NET extensibility option *first* when your are building machines or VMs.  That way when VS 2010 or .NET are subsequently installed, the installation will automatically detect the presence of IIS and will auto-register with it.

 

 

How to host a service in a solution and have the client add service reference

Run without debugging – to do this use Ctrl + F5 or use the Debug menu, but the option may not be there, if you start with a VB IDE. If it is not there then you may add it using customise.

If you run with debugging as usual you will not be able to edit the client.

Hosting the service in IIS

Error no website with code 500

Not surprised that I had issues with hosting here. I had a WSS Windows SharePoint Services and SharePoint Central Administration using my IIS. Took a while to sort, what follows is not comprehensive, but a guide to what I did. I took the view that I have not used SharePoint Central Administration and so was prepared to sacrifice it. Some steps included:

IIS > Sites > Default Web Site > Right-Click > Edit Bindings.

Remove all bindings except http

Then under Default Web Site I had a folder wss -> Virtual Directories -> 80 -> my sample application landed here. Not sure why.

I removed all SharePoint (80) web sites, hope that is ok. And archived the wss folder in its entirety.

Everything started working again.

 

WCF Test Client executable

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\WcfTestClient.exe

Useful quick test.

 

 

 

 

 

Common method for outputting arrays and lists of any type

In unit tests I might want to output the results of a returned list of any type. Instead of writing a new method for each type, here are some techniques with thanks to:

http://stackoverflow.com/questions/9655262/common-method-for-printing-arrays-and-lists-of-any-types

Using Join

Split is a useful function, here is the reverse Join

int[] actual = new int[] {1,2,3}

string actual = new string[] {“one”, “two”, “three”}

TestContext.WriteLine(string.Join(“, “, actual));

 

Using Generics

public void PrintCollection<T>(IEnumerable<T> col)
{
foreach (var item in col) TestContext.WriteLine(item);
}

 

Using ForEach(Action a)

http://msdn.microsoft.com/en-us/library/bwabdf9z(v=vs.110).aspx

[TestMethod()]
publicvoid AListTest()
{
List<string> target = newList<string>();
target.ForEach(PrintCollection2);
}

privatevoid PrintCollection2(string s)
{
TestContext.WriteLine(s);
}

 

 

 

How to build help documentation using Sandcastle – XML comments

After building XML Comments / Documentation and viewing these in a browser it may be useful to create documentation. Microsoft no longer develop a tool, but a tool Sandcastle they initially developed has continued.

This is some of my experience:

In addition to the normal Sandcastle, I installed the Sandcastle Visual Studio integration package.

Sandcastle have large documentation, but I found the basic steps were:

  1. Open Visual Studio
  2. Add New Project > Documentation > Sandcastle Help File Builder Project
  3. Add Documentation Sources – Reference to the project you want to document
  4. Build the project
  5. To view your new help file
    1. Use Menu > View > View Help File
    2. Or Open the Folder Location and open the Help folder
  6. Find the file ContentLayout.content
    1. Change the title from [TODO]
  7. You may get a lot of warnings and lots of ‘Red’ ‘missing documentation’
    1. To suppress these use Properties > Missing Tags and uncheck warning
    2. Or to use it to find missing documentation, uncheck
  8. All seems good so far.

See also

Sandcastle

XML Documentation

MSDN

ASP.Net How do I call a code behind method from an image

Following was html

<a href="CatalogueByList.aspx?VehicleTypeID=3" target="_self">
<img id="CatalogueCVImage" style="border-style: none; height: 94px; width: 172px; margin: 20px;" alt="Automotive Catalogue" src="Resources/ebc-catcommercial-button.jpg" />
</a>

Following is code behind call to a method from an image

<asp:ImageButton
runat="server"
id="CatalogueCar"
ImageUrl="Resources/home-auto.jpg"
AlternateText="Automotive Catalogue"
CssClass="myImage"
style="border-style:none; height: 94px; width: 172px;margin: 20px"
OnClick="OpenCatalogueAutomotive"
/>

Then code behind as:

Protected Sub OpenCatalogueAutomotive(ByVal sender As Object, ByVal e As EventArgs)
ViewState("VehicleTypeID") = 1
Response.Redirect("CatalogueByList.aspx?VehicleTypeID=1")
End Sub

End