Usercontrol no puede crear instancias [XapCannotFindFindFileInPackage]

In Windows Phone7 I created an UserControl in which I am parsing some Data. Now I am not able to make instances of that Usercontrol.

When I remove parsing from the usercontrol I am able to make instances unless I am getting error such as

`"Cannot create instance of '<usercontrolname>' 
"XapCannotFindFileInPackage]
Arguments:HelpScreenData.xml 
Debugging Resource String are unavailable.Often the key and
arguments provide sufficient information to diagonise the problem.see
http://go.microsoft.com'/fwlink/?linkid=106663&version5.0.10411.00&
file=system.xml.dll&key=Xml_cannot find file in Xappackage"

My UserControl CodeBehind

 public partial class ques : UserControl
{
    Popup popup = new Popup();
    tutorial tut = new tutorial();   //another usercontrol

    String[] str;
    String[] nam;
    public ques()
    {
        InitializeComponent();

   }
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {

        LayoutRoot.Visibility = Visibility.Visible;

        buy_bac.Visibility = Visibility.Collapsed;
        buy_hme.Visibility = Visibility.Collapsed;
        buy_qestim.Visibility = Visibility.Collapsed;
        buy_piti.Visibility = Visibility.Collapsed;
        buy_qual.Visibility = Visibility.Collapsed;
        buy_rent.Visibility = Visibility.Collapsed;
        buy_rep.Visibility = Visibility.Collapsed;
        buy_mre.Visibility = Visibility.Collapsed;

        if (Modules.Programname == "Buyers")
        {
            buy_bac.Visibility = Visibility.Visible;
            buy_hme.Visibility = Visibility.Visible;
            buy_qestim.Visibility = Visibility.Visible;
            buy_piti.Visibility = Visibility.Visible;
            buy_qual.Visibility = Visibility.Visible;
            buy_rent.Visibility = Visibility.Visible;
            buy_rep.Visibility = Visibility.Visible;
            buy_mre.Visibility = Visibility.Visible;
        }
        XDocument doc = XDocument.Load("HelpScreenData.xml");
        string val = doc.ToString();

        XElement doc1 = doc.Descendants("buyer").First();

        var parsedPlist = doc1.Descendants("row");

        int i = 0;
        str = new string[parsedPlist.Count()];
        nam = new string[parsedPlist.Count()];
        foreach (XElement elem in parsedPlist)
        {
            nam[i] = (string)elem.Element("btn_name");
            str[i] = (string)elem.Element("string");
            i++;
        }
    }
    private void i1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {


        if (nam[0] == buy_bac.Name)
        {


            Modules.msg = str[0];
            if (Modules.msg != null)
            {
                if (popup.IsOpen != true)
                {

                    popup.Child = tut;
                    popup.IsOpen = true;
                    popup.VerticalOffset = 200;
                    popup.HorizontalOffset = 50;
                    popup.IsOpen = true;
                    tut.lb_tut.Text = Modules.msg;
                }
                else
                {
                    popup.IsOpen = false;
                }
            }
            else if (nam[1] == buy_hme.Name)
            {
                Modules.msg = str[1];
                if (Modules.msg != null)
                {
                    if (popup.IsOpen != true)
                    {
                        popup.Child = tut;
                        popup.IsOpen = true;
                        popup.VerticalOffset = 400;
                        popup.HorizontalOffset = 50;
                        popup.IsOpen = true;
                        tut.lb_tut.Text = Modules.msg;
                    }
                    else
                    {
                        popup.IsOpen = false;
                    }
                }

            }
            else if (nam[1] == buy_qestim.Name)
            {
                Modules.msg = str[2];
                if (Modules.msg != null)
                {
                    if (popup.IsOpen != true)
                    {
                        popup.Child = tut;
                        popup.IsOpen = true;
                        popup.VerticalOffset = 400;
                        popup.HorizontalOffset = 50;
                        popup.IsOpen = true;
                        tut.lb_tut.Text = Modules.msg;
                    }
                    else
                    {
                        popup.IsOpen = false;
                    }
                }

            }
        }


    }

    private void i3_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        if (nam[2] == buy_piti.Name)
        {
            Modules.msg = str[3];
            if (Modules.msg != null)
            {
                if (popup.IsOpen != true)
                {
                    popup.Child = tut;
                    popup.IsOpen = true;
                    popup.VerticalOffset = 600;
                    popup.HorizontalOffset = 50;
                    popup.IsOpen = true;
                    tut.lb_tut.Text = Modules.msg;
                }
                else
                {
                    popup.IsOpen = false;
                }
            }

        }
        else if (nam[2] == buy_rent.Name)
        {
            Modules.msg = str[4];
            if (Modules.msg != null)
            {
                if (popup.IsOpen != true)
                {
                    popup.Child = tut;
                    popup.IsOpen = true;
                    popup.VerticalOffset = 600;
                    popup.HorizontalOffset = 50;
                    popup.IsOpen = true;
                    tut.lb_tut.Text = Modules.msg;
                }
                else
                {
                    popup.IsOpen = false;
                }
            }

        }
        else if (nam[2] == buy_qual.Name)
        {
            Modules.msg = str[5];
            if (Modules.msg != null)
            {
                if (popup.IsOpen != true)
                {
                    popup.Child = tut;
                    popup.IsOpen = true;
                    popup.VerticalOffset = 600;
                    popup.HorizontalOffset = 50;
                    popup.IsOpen = true;
                    tut.lb_tut.Text = Modules.msg;
                }
                else
                {
                    popup.IsOpen = false;
                }
            }

        }
        else if (nam[2] == buy_mre.Name)
        {
            Modules.msg = str[6];
            if (Modules.msg != null)
            {
                if (popup.IsOpen != true)
                {
                    popup.Child = tut;
                    popup.IsOpen = true;
                    popup.VerticalOffset = 600;
                    popup.HorizontalOffset = 50;
                    popup.IsOpen = true;
                    tut.lb_tut.Text = Modules.msg;
                }
                else
                {
                    popup.IsOpen = false;
                }
            }

        }
    }

A sample of xml that parsed

<?xml version="1.0" encoding="utf-8" ?>
<plist version="1.0">
<Main_Screen>
<row>
<btn_name>Buyer Programs</btn_name>
<string>Answer your client’s difficult .</string>
</row>
<row>
<btn_name>Seller’s Programs</btn_name>
<string>What do sellers want s needs.</string>
</row>
</Main_Screen>
 <abssas>
<row>
<btn_name>dat Programs</btn_name>
<string> your client’s </string>
</row>
<row>
<btn_name>my Programs</btn_name>
<string> sellers want s needs.</string>
</row>
</abssas>
</plist>

preguntado el 31 de julio de 12 a las 14:07

do you know Harry Potter? He has discover a magical word that can help to guess how your control is coded. Unfortunately, he's not registered on stackoverflow. Not yet -

abracadabra! Which line is causing the issue? The one with //parsing? If yes, what's the content of the xml file? -

The error doesnt occur on the code But While I drag n drop the UserControl.Check the edit, the XML that I have parsed -

When you drag and drop your control, the code in the constructor IS called. Move your initialization to the Loaded event to avoid this issue. This will at least allow you to debug the loaded event. That said, why are you setting the visibility of all controls within the constructor? You should use the xaml markup. More consistent -

I moved the initialization to UserControl Loaded.Now the same error gets displayed in the designer's view. -

1 Respuestas

You are trying to load "HelpScreenData.xml" but it can't be resolved. Make sure you have included this file as part of your project.

Respondido 31 Jul 12, 18:07

Yes,"HelpScreenData.xml" is a part of my project. - Mini estafa

For the properties of that xml file in your project, is the Build Action set to "Content" and the Copy to Output Directory set to "Copy if newer" or "Copy Always"? - Gambito

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.