none
Unable to create WPF Application but everything else works.

    Question

  • I was training myself to learn C# with console application projects and everything was fine. And I thought it was time for me to step it up and try learning WPF Applications since I've heard they're more updated than a Windows Forms applications. However whenever I try to I always get the this error below.

    I tried finding fix and tried reinstall but it gaves me even more problems like corrupted and all, now I got back to the place where I started which is able to create any projects but WPF Applications.

    I even tried disabling 3.5 .net framwork and have 4.5 enabled however there's no fix I can find for this.

    An Unhandled Exception has occured.

    System.ArgumentException

    An item with the same key has already been added.

    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) at Microsoft.VisualStudio.DesignTools.Utility.Telemetry.VsTelemetryService.RegisterDesignerProcessSession(Int32 pid) at Microsoft.VisualStudio.DesignTools.Utility.Feedback.WatsonTracker.RegisterSession(Int32 processID) at Microsoft.VisualStudio.DesignTools.Utility.DesignerSessionTracker.RecordDesignerStart(Int32 processID, String isolationTargetIdentifier, Boolean mockCustomTypes, String buildConfiguration) at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Primitives.ProcessDomainFactory.ProcessIsolationDomain..ctor(ProcessDomainFactory factory, IIsolationBoundary boundary, AppDomainSetup appDomainInfo, IIsolationTarget isolationTarget, String baseDirectory) at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Primitives.ProcessDomainFactory.CreateIsolationDomain(IIsolationBoundary boundary) at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Primitives.IsolationBoundary.Initialize() at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Primitives.IsolationBoundary.CreateInstance[T](Type type) at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.IsolatedObjectFactory.Initialize() at Microsoft.VisualStudio.DesignTools.DesignerHost.Services.VSIsolationService.CreateObjectFactory(IIsolationTarget isolationTarget, IObjectCatalog catalog) at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.IsolationService.CreateLease(IIsolationTarget isolationTarget) at Microsoft.VisualStudio.DesignTools.DesignerContract.IsolatedDesignerService.CreateLease(IIsolationTarget isolationTarget, CancellationToken cancelToken, DesignerServiceEntry& entry, IServiceProvider serviceOverrides) at Microsoft.VisualStudio.DesignTools.DesignerContract.IsolatedDesignerService.IsolatedDesignerView.CreateDesignerViewInfo(CancellationToken cancelToken) at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.IsolatedTaskScheduler.InvokeWithCulture[T](CultureInfo culture, Func`2 func, CancellationToken cancelToken) at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.IsolatedTaskScheduler.<>c__DisplayClass10_0`1.<starttask>b__0() at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.Tasks.Task.Execute() </starttask>

    Sunday, May 08, 2016 8:52 AM

All replies

  • WPF is the more modern technology and undoubtedly the better. But also the significantly harder to learn. Ideally you should learn something like the MVVM pattern from the get go, as WPF was designed with it in mind:
    Let's talk about MVVM

    The exception indicates that your code (or designer code) tries to add a value to a collection, under the same key for the 2nd time. I would guess on some double-entry in the XAML part. It is always the harder part to debug and make sense off.

    Sunday, May 08, 2016 9:22 AM
  • Looks like you've got an unhandled exception. It may be a technical issue with VS, my best suggestion is you install another version.
    Sunday, May 08, 2016 11:16 AM
  • Try this:

    Login as another user in your computer and see whether this same WPF problem still exist.

    If it is still exist then uninstall and reinstall the Visual Studio make sure is the only way.

    chanmm


    chanmm

    Sunday, May 08, 2016 11:29 AM
  • Thanks all for the feedback!

    @christopher84 yeah, WPF seems harder I'm learning windows form right now and I'm sure it's more than enough for personal use however I'm afraid it might happen the same as WPF error right now in the future thats why I'm trying to fix it in case of such cases happening to my Windows form, but again I might be wrong because I'm still amatuerish if you guys tell me that windows form would not happen the same thing as WPF I'm pretty sure I won't be touching WPF at all since I'm creating applications for personal use.

    I notice the error crashes and restart visual studio even if I'm not touching it, as long as it's open.

    The error only occurs in Mainwindow.xaml but not app.xaml. Should I be renaming the mainwindow.xaml or anything ?

    This is the code inside there:

    <Window x:Class="WpfApplication2.MainWindow"
            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"
            xmlns:local="clr-namespace:WpfApplication2"
            mc:Ignorable="d"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            
        </Grid>
    </Window>

    @Aravind, you mean like VS 2013 instead ?

    @chanmm, I tried reinstalling and deleting registry but things got worst. However I managed to get it back to the state as I originally installed it, but i'm still unhappy with why I'm not able to use WPF but everything else.

    Sunday, May 08, 2016 5:52 PM
  • Thanks all for the feedback!

    @christopher84 yeah, WPF seems harder I'm learning windows form right now and I'm sure it's more than enough for personal use however I'm afraid it might happen the same as WPF error right now in the future thats why I'm trying to fix it in case of such cases happening to my Windows form, but again I might be wrong because I'm still amatuerish if you guys tell me that windows form would not happen the same thing as WPF I'm pretty sure I won't be touching WPF at all since I'm creating applications for personal use.

    The bulk of WPF's power comes from the extra Language of XAML you need when developing the GUI. It is WPF's big tradeoff:

    XAML makes WPF and UWP a thousand times more powerfull.

    Unfortunately XAML also makes them a debugging nightmare:
    There is little to no compiler debugging for XAML.
    Half the time if the XAML interpretattion fails, it will boneheadedly just use the last compilation and continue to compile the code.
    And most runtime exceptions can not be tracked to the responsible XAML line either.
    You basically have to use MVVM or you are in debugging hell.

    WinForms uses partial classes, where the Designer is writing the exact same C# code that you would write. So there will alwasys be clear indication wich line caussed the exceptions, if it is written by you, the designer or the guys that wrote the classes.
    It has much more severe limtiations for GUI design, but in turn it is also a lot easier to learn.

    Sunday, May 08, 2016 9:01 PM

  • XAML makes WPF and UWP a thousand times more powerfull.


    Maybe you're exaggerating just a bit?

    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

    Sunday, May 08, 2016 9:16 PM

  • XAML makes WPF and UWP a thousand times more powerfull.


    Maybe you're exaggerating just a bit?


    Nope.

    I like WinForms for it's simplicity, but it was never designed for the kind of stuff we try to do with it/have to do with it in our current day and age.

    There is no proper transaprency except for the top level Windows.
    Making a image button requires you to inherit the button and override Paint plus half the events.

    XAML is so far developed that you can often implement MVVM pattern withou a single line of code behind for the View.
    Everything down to instantiating the ViewModel can be done in XAML.
    Custom controls have been replaced by Data Templates wich are better in every aspect.
    Making a image button is about as hard as a image link in HTML.
    It is the result of a decade of knowledge what all works badly in WinForms.

    WinForms to WPF is a step forward on par with using Garbage Collection. The first Visual Libraries. The Change from COM to .NET.

    Monday, May 09, 2016 12:56 AM
  • Hi 2xdswu,

    >>I tried finding fix and tried reinstall but it gaves me even more problems like corrupted and all, now I got back to the place where I started which is able to create any projects but WPF Applications.

    >> I even tried disabling 3.5 .net framwork and have 4.5 enabled however there's no fix I can find for this.

    This forum is about the C# programming language, IDE, libraries, samples, and tools, as your initial issue is more related to the Visual Studio itself, we help you move it to the Visual Studio General Questions forum for better support.

    Thank you for your understanding.

    Best Regards,

    Albert Zhang

    Monday, May 09, 2016 6:55 AM
  • @2xdswu That'd work, but installing any other edition of VS 2015 might also work.
    Monday, May 09, 2016 3:24 PM
  • Hi  2xdswu,

    Which VS version did you use, VS2012 or others? Please make sure that you installed the latest update package for your current VS version.

    >>but i'm still unhappy with why I'm not able to use WPF but everything else.

    So you mean that it still has this issue even if you create a blank WPF app, am I right?

    (1) If you run your VS in safe mode or as the admin, how about the result? At least, we could know that whether it is related add-ins or extension tools in your VS IDE.

    https://msdn.microsoft.com/en-us/library/ms241278.aspx?f=255&MSPPError=-2147217396

    (2) Since other projects work well, just the WPF app has this issue, maybe the specific project template package has the loaded issue.

    a. Please open Windows Explorer, and navigate to  <Visual Studio Installation Path>\Common7\IDE (by default is C:\Program Files \Microsoft Visual Studio 11.0\Common7\IDE);
    b. Delete the ItemTemplatesCache, ProjectTemplatesCache folder;
    c. Open Visual Studio Command Prompt (2010)/ VS2012 x64 Cross Tools Command Prompt under Start menu -> All Programs -> Microsoft Visual Studio 2012 -> Visual Studio Tools (run it with Administrator privilege: right-click the program -> Run as administrator);
    d. Run the devenv /InstallVSTemplates switch;
    e. Run the devenv /Setup switch

    And then create a new simple WPF app, check it again.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 10, 2016 4:17 AM
    Moderator
  • Hi 2xdswu,

    I am writing to check the status of the issue on your side. 

    What about this problem now?

    Would you mind letting us know the latest information about this issue?

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 16, 2016 7:26 AM
    Moderator
  • Im actually using Visual Basic 2015 Enterprise version.

    1. I've tried the running it in admin the results are still the same error as the first post I've posted.

    2. I tried creating new WPF app but it keeps showing the same issue as well.

    3. I've tried that however step C onwards I can't understand the process, my visual studio have consistent crashes too. I've tried installing the free version as well however it keeps locks on the enterprise version and not letting me runn the community version.

    Does visual studio runs on mac ? Because I've a vmware installed on mac I might try coding on vmware instead.

    Friday, May 20, 2016 11:15 PM
  • Still the same issue as I stated on my first post.
    Friday, May 20, 2016 11:15 PM
  • Hi 2xdswu,

    >>Does visual studio runs on mac ? Because I've a vmware installed on mac I might try coding on vmware instead.

    We can't install or run VS on a Mac directly.

    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/881bfc81-fd41-465b-aec1-cc951ec95063/cant-find-vs-community-for-mac?forum=visualstudiogeneral

    Do you mean that you installed the VM on mac? If so, as far as I know, we could install the VS in the VM machine.

    Since you couldn't create the WPF app, maybe we could collect the detailed log messages:

    You can get the log files with the following steps:
    1) Download collect.exe from the link below. <http://go.microsoft.com/?LinkId=8967043>
    2) You may choose to save the tool for later use, or to run directly.
    3) The utility creates a compressed cabinet of all the VS and .NET logs to %TEMP%\vslogs.cab.

    You can get more details about how to get the log files here:
    http://blogs.msdn.com/heaths/archive/2008/05/09/visual-studio-and-net-log-collection-utility.aspx

    You could upload your log files to the one drive and share us the downloaded link, I will check it in my side.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Saturday, May 21, 2016 6:45 AM
    Moderator