Posts tagged: visual-studio-2010

May 03 2012

How do I troubleshoot Visual Studio which is hanging when loading ASP.NET MVC project?

        <p>Yesterday I worked on an MVC 3 project in Visual Studio 2010 and then shut down Visual Studio before leaving work.</p>

This morning when I try to load the same project in Visual Studio the project hangs. I have restarted my computer, disabled all add-ons and extensions that I could. Still no banana.

I have no idea how to troubleshoot this. I would try to clean the solution if I could get it to load but I can't. (Can I clean the solution from the VS command window?).

Any help would be greatly appreciated. How do I troubleshoot this?

Seth

May 20 2011

How do you get a WCF proxy to ctor a child collection?

Hello,

I am studying today and I did my very first very simple WCF Service. I created a couple of very simple classes as follows (this is simplified a bit) ...

//contact class  
public class Contact
{
    public int Id { get; set; }


    private ObservableCollection<Phone> _contactPhones = new ObservableCollection<Phone>();
    public ObservableCollection<Phone> ContactPhones
    {
        get { return _contactPhones; }
        set { _contactPhones = value; }
    }

    public string FirstName { get; set; }

    public string LastName { get; set; }
}
// phone class  
public class Phone
{
    public string PhoneNumber { get; set; }
    public PhoneTypes PhoneType { get; set; }
}

I have a mock repository class that returns a collection of the contact class

class ContactRepositoryMock : IContactRepository
{
    private readonly ObservableCollection<Contact> _contactList;

    public ContactRepositoryMock()
    {
        _contactList = new ObservableCollection<Contact>();

        Contact contact = this.Create();
        contact.Id = 1;
        contact.FirstName = "Seth";
        contact.LastName = "Spearman";
        contact.ContactPhones.Add(new Phone(){PhoneNumber = "864-555-1111",PhoneType = PhoneTypes.Mobile});
        contact.ContactPhones.Add(new Phone(){PhoneNumber = "864-555-2222",PhoneType = PhoneTypes.Home});

        this.Save(contact);

    }
    public ObservableCollection<Contact> GetContacts()
    {
        return _contactList;
    }

}

The Save and Create methods are not shown but Save adds to the _contactList collection and Create creates a new instance of contact (notice that the Contact ctor is using eager loading to init the phone _contactPhones collection)

Finally I created a WCF Service wrapper around the ContactRepositoryMock.GetContacts method as follows...

[ServiceContract(Namespace = "")]
[SilverlightFaultBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ContactsService
{
    private ContactRepositoryMock _contactRepository = new ContactRepositoryMock();

    [OperationContract]
    public ObservableCollection<Contact> GetContacts()
    {
        return _contactRepository.GetContacts();
    }
}

The other project is a Silverlight project (which is really what I am s'posed to be studying today.)

In that project I added a Web Reference to my WCF Class and Visual Studio added the proxy class as usual.

I have added a MainPageViewModel in the project as follows:

public class MainPageViewModel : ViewModelBase
{
    public MainPageViewModel()
    {
        if (!IsDesignTime)
        {
            //GetContacts();   //not shown               
        }
        else
        {
            var contactList = new ObservableCollection<Contact>();

            var contact = new Contact {Id = 1, FirstName = "Seth", LastName = "Spearman"};
            contact.ContactPhones.Add(new Phone() { PhoneNumber = "864-555-1111", PhoneType = PhoneTypes.Mobile });
            contact.ContactPhones.Add(new Phone() { PhoneNumber = "864-555-2222", PhoneType = PhoneTypes.Home }); 
            contactList.Add(contact);

            Contacts= contactList;
        }
    }

    private ObservableCollection<Contact> _contacts;
    public ObservableCollection<Contact> Contacts
    {
        get { return _contacts; }
        set
        {
            if (value!=_contacts)
            {
                _contacts = value;
                OnPropertyChanged("Contacts");
            }
        }
    }
}

AND the following XAML

<UserControl x:Class="MVVMDemo.MainPage"
    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:viewModels="clr-namespace:MVVMDemo.ViewModels"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <viewModels:MainPageViewModel x:Key="ViewModels" />
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" 
          DataContext="{Binding Source={StaticResource ViewModels}}"
          Background="White">
    </Grid>
</UserControl>

That is a lot of background to get to the error and ultimately what is probably a simple explanation.

The XAML line <viewModels:MainPageViewModel x:Key="ViewModels" /> has a squiggly under it and is returning the error "Cannot create and instance of MainPageViewModel".

I even know the CAUSE of that error. If I disable the contact.ContactPhones.Add ... lines that are in the MainPageViewModel ctor then the error goes away.

Finally, I even know why the error goes away. It is because the Reference file that creates the WCF Proxy class is not initializing the ContactPhones collection.

In other words, in the generated class Reference.cs in the proxy if I change the line that reads...

private System.Collections.ObjectModel.ObservableCollection<MVVMDemo.WSProxy.Phone> ContactPhonesField;

to

private System.Collections.ObjectModel.ObservableCollection<MVVMDemo.WSProxy.Phone> ContactPhonesField = new ObservableCollection<Phone>();

then I can re-enable the contact.ContactPhones.Add... lines and the error goes away. The project compiles and runs.

SO...all that to simply ask...how do I get Visual Studio to generate a proxy class that will init my collection. Or is there a flaw in the way I am doing this? What am I missing?

Sorry for all the detail but I was not sure where in the call chain there might be a failure. I am also going to use all of this detail to ask a few more questions after this one gets answered.

Seth

May 20 2011

How do you get a WCF proxy to ctor a child collection?

Hello,

I am studying today and I did my very first very simple WCF Service. I created a couple of very simple classes as follows (this is simplified a bit) ...

//contact class  
public class Contact
{
    public int Id { get; set; }


    private ObservableCollection<Phone> _contactPhones = new ObservableCollection<Phone>();
    public ObservableCollection<Phone> ContactPhones
    {
        get { return _contactPhones; }
        set { _contactPhones = value; }
    }

    public string FirstName { get; set; }

    public string LastName { get; set; }
}
// phone class  
public class Phone
{
    public string PhoneNumber { get; set; }
    public PhoneTypes PhoneType { get; set; }
}

I have a mock repository class that returns a collection of the contact class

class ContactRepositoryMock : IContactRepository
{
    private readonly ObservableCollection<Contact> _contactList;

    public ContactRepositoryMock()
    {
        _contactList = new ObservableCollection<Contact>();

        Contact contact = this.Create();
        contact.Id = 1;
        contact.FirstName = "Seth";
        contact.LastName = "Spearman";
        contact.ContactPhones.Add(new Phone(){PhoneNumber = "864-555-1111",PhoneType = PhoneTypes.Mobile});
        contact.ContactPhones.Add(new Phone(){PhoneNumber = "864-555-2222",PhoneType = PhoneTypes.Home});

        this.Save(contact);

    }
    public ObservableCollection<Contact> GetContacts()
    {
        return _contactList;
    }

}

The Save and Create methods are not shown but Save adds to the _contactList collection and Create creates a new instance of contact (notice that the Contact ctor is using eager loading to init the phone _contactPhones collection)

Finally I created a WCF Service wrapper around the ContactRepositoryMock.GetContacts method as follows...

[ServiceContract(Namespace = "")]
[SilverlightFaultBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ContactsService
{
    private ContactRepositoryMock _contactRepository = new ContactRepositoryMock();

    [OperationContract]
    public ObservableCollection<Contact> GetContacts()
    {
        return _contactRepository.GetContacts();
    }
}

The other project is a Silverlight project (which is really what I am s'posed to be studying today.)

In that project I added a Web Reference to my WCF Class and Visual Studio added the proxy class as usual.

I have added a MainPageViewModel in the project as follows:

public class MainPageViewModel : ViewModelBase
{
    public MainPageViewModel()
    {
        if (!IsDesignTime)
        {
            //GetContacts();   //not shown               
        }
        else
        {
            var contactList = new ObservableCollection<Contact>();

            var contact = new Contact {Id = 1, FirstName = "Seth", LastName = "Spearman"};
            contact.ContactPhones.Add(new Phone() { PhoneNumber = "864-555-1111", PhoneType = PhoneTypes.Mobile });
            contact.ContactPhones.Add(new Phone() { PhoneNumber = "864-555-2222", PhoneType = PhoneTypes.Home }); 
            contactList.Add(contact);

            Contacts= contactList;
        }
    }

    private ObservableCollection<Contact> _contacts;
    public ObservableCollection<Contact> Contacts
    {
        get { return _contacts; }
        set
        {
            if (value!=_contacts)
            {
                _contacts = value;
                OnPropertyChanged("Contacts");
            }
        }
    }
}

AND the following XAML

<UserControl x:Class="MVVMDemo.MainPage"
    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:viewModels="clr-namespace:MVVMDemo.ViewModels"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <viewModels:MainPageViewModel x:Key="ViewModels" />
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" 
          DataContext="{Binding Source={StaticResource ViewModels}}"
          Background="White">
    </Grid>
</UserControl>

That is a lot of background to get to the error and ultimately what is probably a simple explanation.

The XAML line <viewModels:MainPageViewModel x:Key="ViewModels" /> has a squiggly under it and is returning the error "Cannot create and instance of MainPageViewModel".

I even know the CAUSE of that error. If I disable the contact.ContactPhones.Add ... lines that are in the MainPageViewModel ctor then the error goes away.

Finally, I even know why the error goes away. It is because the Reference file that creates the WCF Proxy class is not initializing the ContactPhones collection.

In other words, in the generated class Reference.cs in the proxy if I change the line that reads...

private System.Collections.ObjectModel.ObservableCollection<MVVMDemo.WSProxy.Phone> ContactPhonesField;

to

private System.Collections.ObjectModel.ObservableCollection<MVVMDemo.WSProxy.Phone> ContactPhonesField = new ObservableCollection<Phone>();

then I can re-enable the contact.ContactPhones.Add... lines and the error goes away. The project compiles and runs.

SO...all that to simply ask...how do I get Visual Studio to generate a proxy class that will init my collection. Or is there a flaw in the way I am doing this? What am I missing?

Sorry for all the detail but I was not sure where in the call chain there might be a failure. I am also going to use all of this detail to ask a few more questions after this one gets answered.

Seth

May 20 2011

How do you get a WCF proxy to ctor a child collection?

I am studying today and I did my very first very simple WCF Service. I created a couple of very simple classes as follows (this is simplified a bit) ...

//contact class  
public class Contact
{
    public int Id { get; set; }


    private ObservableCollection<Phone> _contactPhones = new ObservableCollection<Phone>();
    public ObservableCollection<Phone> ContactPhones
    {
        get { return _contactPhones; }
        set { _contactPhones = value; }
    }

    public string FirstName { get; set; }

    public string LastName { get; set; }
}
// phone class  
public class Phone
{
    public string PhoneNumber { get; set; }
    public PhoneTypes PhoneType { get; set; }
}

I have a mock repository class that returns a collection of the contact class

class ContactRepositoryMock : IContactRepository
{
    private readonly ObservableCollection<Contact> _contactList;

    public ContactRepositoryMock()
    {
        _contactList = new ObservableCollection<Contact>();

        Contact contact = this.Create();
        contact.Id = 1;
        contact.FirstName = "Seth";
        contact.LastName = "Spearman";
        contact.ContactPhones.Add(new Phone(){PhoneNumber = "864-555-1111",PhoneType = PhoneTypes.Mobile});
        contact.ContactPhones.Add(new Phone(){PhoneNumber = "864-555-2222",PhoneType = PhoneTypes.Home});

        this.Save(contact);

    }
    public ObservableCollection<Contact> GetContacts()
    {
        return _contactList;
    }

}

The Save and Create methods are not shown but Save adds to the _contactList collection and Create creates a new instance of contact (notice that the Contact ctor is using eager loading to init the phone _contactPhones collection)

Finally I created a WCF Service wrapper around the ContactRepositoryMock.GetContacts method as follows...

[ServiceContract(Namespace = "")]
[SilverlightFaultBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ContactsService
{
    private ContactRepositoryMock _contactRepository = new ContactRepositoryMock();

    [OperationContract]
    public ObservableCollection<Contact> GetContacts()
    {
        return _contactRepository.GetContacts();
    }
}

The other project is a Silverlight project (which is really what I am s'posed to be studying today.)

In that project I added a Web Reference to my WCF Class and Visual Studio added the proxy class as usual.

I have added a MainPageViewModel in the project as follows:

public class MainPageViewModel : ViewModelBase
{
    public MainPageViewModel()
    {
        if (!IsDesignTime)
        {
            //GetContacts();   //not shown               
        }
        else
        {
            var contactList = new ObservableCollection<Contact>();

            var contact = new Contact {Id = 1, FirstName = "Seth", LastName = "Spearman"};
            contact.ContactPhones.Add(new Phone() { PhoneNumber = "864-555-1111", PhoneType = PhoneTypes.Mobile });
            contact.ContactPhones.Add(new Phone() { PhoneNumber = "864-555-2222", PhoneType = PhoneTypes.Home }); 
            contactList.Add(contact);

            Contacts= contactList;
        }
    }

    private ObservableCollection<Contact> _contacts;
    public ObservableCollection<Contact> Contacts
    {
        get { return _contacts; }
        set
        {
            if (value!=_contacts)
            {
                _contacts = value;
                OnPropertyChanged("Contacts");
            }
        }
    }
}

AND the following XAML

<UserControl x:Class="MVVMDemo.MainPage"
    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:viewModels="clr-namespace:MVVMDemo.ViewModels"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <viewModels:MainPageViewModel x:Key="ViewModels" />
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" 
          DataContext="{Binding Source={StaticResource ViewModels}}"
          Background="White">
    </Grid>
</UserControl>

That is a lot of background to get to the error and ultimately what is probably a simple explanation.

The XAML line <viewModels:MainPageViewModel x:Key="ViewModels" /> has a squiggly under it and is returning the error "Cannot create and instance of MainPageViewModel".

I even know the CAUSE of that error. If I disable the contact.ContactPhones.Add ... lines that are in the MainPageViewModel ctor then the error goes away.

Finally, I even know why the error goes away. It is because the Reference file that creates the WCF Proxy class is not initializing the ContactPhones collection.

In other words, in the generated class Reference.cs in the proxy if I change the line that reads...

private System.Collections.ObjectModel.ObservableCollection<MVVMDemo.WSProxy.Phone> ContactPhonesField;

to

private System.Collections.ObjectModel.ObservableCollection<MVVMDemo.WSProxy.Phone> ContactPhonesField = new ObservableCollection<Phone>();

then I can re-enable the contact.ContactPhones.Add... lines and the error goes away. The project compiles and runs.

SO...all that to simply ask...how do I get Visual Studio to generate a proxy class that will init my collection. Or is there a flaw in the way I am doing this? What am I missing?

Sorry for all the detail but I was not sure where in the call chain there might be a failure. I am also going to use all of this detail to ask a few more questions after this one gets answered.

Seth

Jan 27 2011

For a .NET winforms datagridview I would like a combobox column to have a different set of values for each row

I have a DataGridView that I am binding to a POCO. I have the databinding working fine. However, I have added a combobox column that I want to be different for each row. Specifically, I have a grid of purchased items, some of which have sizes (like Adult XL, Adult L) and other items are not sized (like Car Magnet.)

So essentially what I want to change is the DATA SOURCE for a combobox column in the data grid. Can that be done?

What event can I hook into that would allow me to change properties of certain columns FOR EACH ROW? An acceptable alternative is to change a property when the user clicks or tabs into the row. What event is that?

Seth

EDIT
I need more help with this question. With Triduses help I am SO close but I need a bit more information.

First, per the question, is the CellFormatting event really the best/only event for changing the DataSource for a combo box column. I ask because I am doing something rather resource/data intensive, not merely formatting the cell.

Second, the cellformatting event is being called just by having the mouse hover over the cell. I tried to set the FormattingApplied property inside my if-block and then I check for it in the if- test but that is returning a weird error message. My ideal situation is that I would apply change the data source for the combo box once for each row and then be done with it.

Finally, in order to set the data source of the combobox colunm I have to be able to cast the Cell inside my if block to a type of DataGridViewComboBoxColumn so that I can fill it with rows or set the datasource or something. Here is the code I have right now.

Private Sub ProductsDataGrid_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles ProductsDataGrid.CellFormatting

    If e.ColumnIndex = ProductsDataGrid.Columns("SizeDGColumn").Index Then ' AndAlso Not e.FormattingApplied Then
        Dim product As LeagueOrderProductInfo = DirectCast(ProductsDataGrid.Rows(e.RowIndex).DataBoundItem, LeagueOrderProductInfo)
        Dim sizes As LeagueOrderProductSizeList = product.ProductSizes
        sizes.RemoveSizeFromList(_parentOrderDetail.SizeID)

        'WHAT DO I DO HERE TO FILL THE COMBOBOX COLUMN WITH THE sizes collection.

    End If

End Sub

Please help. I am completely stuck and this task item should have taken an hour and I am 4+ hours in now. BTW, I am also open to resolving this by taking a completely different direction with it (as long as I can be done quickly.)

Seth

Jan 27 2011

How do you create Winform user control that supports multiple items like a listbox.

Hello,

I think I understand the basics of create winforms user control. I can do Add New and select user control and that will give me a design surface and designer file and code-behind file etc. And then I could change it to inherit from something other than UserControl (like listbox or text box).

The thing that is different for me this time is the user control needs to be a list control (like a list box) that can be data-bound and with two data-bindable controls in it (two combo boxes).

I am not sure where to start? Can anybody reference a document or some obvious bit in the tooling that I am missing that will make it quick and easy? Any approaches I can take like extending an existing control. Any gotchas I need to be aware of?

Thanks.

Seth

Jan 27 2011

How do you create Winform user control that supports multiple items like a listbox

I think I understand the basics of create winforms user control. I can do Add New and select user control and that will give me a design surface and designer file and code-behind file etc. And then I could change it to inherit from something other than UserControl (like listbox or text box).

The thing that is different for me this time is the user control needs to be a list control (like a list box) that can be data-bound and with two data-bindable controls in it (two combo boxes).

I am not sure where to start? Can anybody reference a document or some obvious bit in the tooling that I am missing that will make it quick and easy? Any approaches I can take like extending an existing control. Any gotchas I need to be aware of?

Thanks.

Seth

EDIT
I have decided to take a different approach. I am leaving the question up, though. This is clearly difficulty than I had guessed. WPF is not an option for me unfortunately. Just gonna use a data grid.

Dec 17 2010

I am setting up a SharePoint Development environment. Can I setup Sharepoint on a VM and Visual Studio on my production computer?

I am going to be learning how to do SharePoint 2010 development and as such I am setting up my environment? I have a couple of questions about that.

First, I am following a couple of helpful articles on how to do it as follows...

http://geekswithblogs.net/manesh/archive/2010/05/28/building-the-ultimate-sharepoint-2010-development-environment.aspx

and

http://msdn.microsoft.com/en-us/library/ee554869%28office.14%29.aspx

Both of these article recommend setting up Sharepoint on a server environment or VM and THEN setup Visual Studio on that same environment.

I was wondering if it will work to setup Sharepoint on a VM Guest and use my existing installation of Visual Studio (my VM host) to do the work. To do Sharepoint development do you HAVE to install Visual Studio on the VM Guest with Sharepoint? What do I lose if I just use my production install of Visual Studio (or will it just plain not work?).

It just seems counter-productive to have two development environments (and I refuse to install Sharepoint on my production machine...at least right now.)

Also, will SharePoint Foundation edition (rather than full server version) function just fine for learning and development or will I find that I am eventually going to hit barriers and limitations with it.

Thanks in advance for your help.

Seth

Dec 17 2010

I am setting up a SharePoint Development environment. Can I setup Sharepoint on a VM and Visual Studio on my production computer?

Hello,

I am going to be learning how to do SharePoint 2010 development and as such I am setting up my environment? I have a couple of questions about that.

First, I am following a couple of helpful articles on how to do it as follows...

http://geekswithblogs.net/manesh/archive/2010/05/28/building-the-ultimate-sharepoint-2010-development-environment.aspx

and

http://msdn.microsoft.com/en-us/library/ee554869%28office.14%29.aspx

Both of these article recommend setting up Sharepoint on a server environment or VM and THEN setup Visual Studio on that same environment.

I was wondering if it will work to setup Sharepoint on a VM Guest and use my existing installation of Visual Studio (my VM host) to do the work. To do Sharepoint development do you HAVE to install Visual Studio on the VM Guest with Sharepoint? What do I lose if I just use my production install of Visual Studio (or will it just plain not work?).

It just seems counter-productive to have two development environments (and I refuse to install Sharepoint on my production machine...at least right now.)

Also, will SharePoint Foundation edition (rather than full server version) function just fine for learning and development or will I find that I am eventually going to hit barriers and limitations with it.

Thanks for your help.

Seth

Sep 22 2010

Visual Studio – how do you use it without touching your mouse?

I am going to be doing the codekata defined on Roy Osherove's blog HERE.

One of the rules is that you cannot use the mouse while doing the kata.

Today, my first attempt at doing the kata I have spent the whole time trying to better understand how to use VS without the mouse. I have learned that CTL-ALT-A will be my friend because I can type commands there.

Does somebody have a pointer to a complete reference to the VS Commmands. I want the command name (Edit.ToggleBookmark), command keystroke (like Ctl-K,K), and any arguments required by the command.

Some specific questons I have.

  • Does someone know a keystroke for pinning the active window without using the mouse.
  • Also, I cannot figure out how to add a reference without using the keyboard.

If you can help with those two then I will be significantly farther along.

Thanks.

Seth

edit

Just figured out how to add references. I was working on a project that was not saved and Add References command (Project.AddReference) was returning an error...and I thought it was because I was using the command...but it was actually because I had not saved the project yet.

SO.... if you could help me with the window pinning that would be great.

Seth

EVEN WITH ALL THE HELPS FIGURING OUT COMMANDS...I still cannot figure out how to
- pin a Visual Studio window so it stays open.
- And how do you trigger the context menu any a window. For example, solution explorer?
- How do you delete or remove a file?

EDIT

This StackOverflow question answers the context menu question.

Now...if someone can tell me how to pin a window. That would be awesome.

Seth