Select to view content in your preferred language

Cannot create an instance of ...

979
4
10-20-2010 06:12 AM
ShaningYu
Honored Contributor
I used one of ESRI's template, and loaded multiple user control components.  One component was from ESRI's sample: DriveTime, http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#DriveTimes
Then, in the Main.xaml file, I use the following code to create the instance:
            <unb:DriveTime x:Name="MyDriveTime" Visibility="Collapsed"
                             Height="110" Width="250" Canvas.Left="18" Canvas.Top="310" />
which is the same format as that used to crate multiple other user controls.
I also checked the class: DriveTime and found nothing wrong.  However, when I built it, I got the error message: 'Cannot create an instance of DriveTime'.  What's the possible reason for this bug?  If you know, please share.  Thanks.
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
It's hard to tell what's wrong in your XAML, unbDriveTime, I suspect is your class.  I believe you need to add the namespace of your assembly in XAML

xmlns:local="clr-namespace:YourNameSpace"

and then do

<local:unbDriveTime ..../>
0 Kudos
ShaningYu
Honored Contributor
Actually, in all of the classes (including the MainPage.xaml), the namespace is defined:
    xmlns:local="clr-namespace:UnBlendedCS1_Oct1"
For example, it is OK for
            <local:AddressLocator x:Name="MyAddressLocator" Visibility="Collapsed"
                             Height="300" Width="300" Canvas.Left="278" Canvas.Top="242" />
but not for            <local:DriveTime x:Name="MyDriveTime" Visibility="Collapsed"
                            Height="110" Width="250" Canvas.Left="18" Canvas.Top="310" />
0 Kudos
JenniferNery
Esri Regular Contributor
Is it a compile time error? Maybe it does not find a constructor to your DriveTime control or it is unable to initialize the contents of your control.  There must be something wrong with the control itself then.  You can place breakpoint before DriveTime's Initialize to see where it could be failing. Are you able to see its contents in design-time?  Sometimes just viewing the design page gives you error messages that you would not see in MainPage but might see in the control you are adding.
0 Kudos
ShaningYu
Honored Contributor
Jenniffer:
after commenting out
  //_Map.MouseClick += _Map_MouseClick;
in the constructor, the user control dialog displays on the MainPage.xaml.  Many thanks to you for your many times of quick and effective help.
Shaning
0 Kudos