Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Problem with custom controls RSS

13 replies

Last post Jan 14, 2008 03:00 AM by mchlsync

(0)
  • Snowbunny

    Snowbunny

    Member

    10 Points

    9 Posts

    Problem with custom controls

    Jun 04, 2007 04:09 PM | LINK

    Hi there.

    I have a Silverlight solution containing two projects. One, TestProject is the project containing my main root and the other, SilverlightUIControls is a copy of the same Silverlight controls provided by MS. When the controls project is built, the DLL is copied to the ClientBin directory in TestProject.

    In TestProject Page.xaml, I have this line in my <Canvas> declaration:

    xmlns:uicontrol = "clr-namespace:Silverlight.Samples.Controls;assembly=ClientBin/Silverlight.Samples.Controls.dll"

    and below this, I have:

    <uicontrol:ListBox x:Name = "listBox" Canvas.Top="10" Canvas.Left="10"></uicontrol:ListBox >

    When I build and test, this works fine, and any changes I make the the ListBox control appear as you'd expect.

    Now, I woud like to add a new control, SelectBox. I tried and failed for a while - it always built correctly, but I'd get an error when I tried to view the html (which I'll get to in a minute). So, I thought that I'd go back to basics. I copied the ListBox.cs and ListBox.xaml files as SelectBox.cs and SelectBox.xaml - updated the class declarations and the link to the xaml so it all should work. I included this in my SilverlightUIControls project and built it. No errors. Woohoo.

    Going back to my Page.xaml, I looked at the codebehind, and the Intellisense was working fine for the new SelectBox control, so all I did to that <uicontrol:ListBox /> is change it to <uicontrol:SelectBox />. There were no build errors, so I F5ed and, lo and behold, I get the following error:

    Silverlight error message
    ErrorCode: 2210
    ErrorType: ParserError
    Message: AG_E_INVALID_ARGUMENT
    XamlFile: Page.xaml
    Line: 19
    Position: 70

    The position of the error is the end of that uicontrol. This has been driving me mad. I've checked the DLLs and they're updated with the correct date/time, so I can't for the life of me work out why simply copying the class under a different name would break it!

    Any help would save my mind and my hair...and probably my laptop, too, which at the moment is under threat of disappearing off the balcony...

    Thanks!

  • Vivek Dalvi

    Vivek Dalvi

    Member

    468 Points

    123 Posts

    Microsoft

    Re: Problem with custom controls

    Jun 05, 2007 05:21 PM | LINK

    Dont know about laptop but hair...dont make them disappear over and off the balcony, especially if attached to your head  :) Lets see if we can resolve the issue before it gets there.

    When you add a new control, SelectBox, does it's constructor  succeeds? Does it even gets called? if you can put a break point and see if that works then it would be helpful to figure out whether the problem is in SelectBox control or something the way ListBox is working or something else.

    You dont get errors while compilation because when you put those custom tags in XAML they are not really instantiated at compile time. So that is why you get runtime error.

     

  • tmasopust

    tmasopust

    Member

    4 Points

    2 Posts

    Re: Problem with custom controls

    Jun 08, 2007 06:04 PM | LINK

    I'm having the same error and issue. The break point in the constructor never gets hit. The problem appears to be somewhere in the XAML parsing side. 

  • sony05

    sony05

    Member

    8 Points

    5 Posts

    Re: Re: Problem with custom controls

    Jun 13, 2007 06:18 AM | LINK

     im gettin tis error whn im running the code

    Silverlight error message
    ErrorCode: 2254
    ErrorType: Parser Error
    Message: AG_E_RUNTIME_MANAGER_ASSEMBLY_DOWNLOAD
    XamlFile:xaml/Page.xaml
    Line: 10
    Position:3

    x:Class="SilverlightStarterKit.Page;assembly=ClientBin/SilverlightStarterKit.dll"

    xmlns:uicontrol="clr-namespace:Silverlight.Samples.Controls;assembly=ClientBin/Silverlight.Samples.Controls.dll"

    tis is my xaml code

    and wid the same assembly used in another project its running perfectly well

    i hav downloaded the SDk 1.1 alpha also, but nothin seems to working and even in tis project it is not even going to the breakpoint

  • nirajswami

    nirajswami

    Member

    34 Points

    16 Posts

    Re: Re: Problem with custom controls

    Jun 19, 2007 10:10 AM | LINK

    Hi Sony5,

    I have tried same thing as above. But not get solution of my error.

    Any help?

    Thanks in Advance.

     

    Thanks and Regards,
    Nirajswami
  • Alex Ivanov

    Alex Ivanov

    Member

    18 Points

    30 Posts

    Re: Problem with custom controls

    Jun 19, 2007 05:51 PM | LINK

    Hi,

     I experienced the same problem (AG_E_INVALID_ARGUMENT error). I was implementing the Control UI from the Silverlight 1.1 SDK. I added the library to a project and the error was with Line and Position on that line:

    <my:MyLabel x:Name="label" Height="30" Width="200" Text="Hello" LabelColor="Blue"/>

    When I traced the program, I discovered that the fault was one minor omission on my part. I named my library project "MyFirstLibrary" and the default name for the project was "SilverlightSampleControl". I forgot to change the following line in the contructor that created the object:

    public MyLabel()
            {
                Stream s = this.GetType().Assembly.GetManifestResourceStream("SilverlightSampleControl.MyLabel.xaml");
                ....

                ....

            }

     Changing the above line to "...MyFirstLibrary.MyLabel.xaml" solved my problem. Now see whether you have not made the same omission in your ListBox constructor.

                                                                                                  ~ Alex Ivanov


  • nirajswami

    nirajswami

    Member

    34 Points

    16 Posts

    Re: Problem with custom controls

    Jun 20, 2007 05:23 AM | LINK

    Thanks Alex,

    My problem has solved.

    Thanks and Regards,
    Nirajswami
  • lefnire

    lefnire

    Member

    20 Points

    13 Posts

    Re: Re: Problem with custom controls

    Jun 24, 2007 04:56 PM | LINK

    I, too, am getting the ag_e_invalid_argument.  i'm just gonna dump all my code here :)  I tried alex's solution, but my namespace was already in the constructor :(

     

    Page.xaml

    <Canvas xmlns="http://schemas.microsoft.com/client/2007"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            x:Class="client.Page;assembly=ClientBin/client.dll"
            xmlns:my="clr-namespace:client;assembly=ClientBin/client.dll"
            x:Name="parentCanvas"
            Loaded="Page_Loaded"
            Width="640"
            Height="480"
            >
      <my:MyControl x:Name="mycontrol1" Canvas.Left="100" Canvas.Top="100"/>
    </Canvas>

     MyControl.xaml

    <Canvas
        xmlns="http://schemas.microsoft.com/client/2007"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Name="MyControl"
        Width="640" Height="480">
    </Canvas>

     

    MyControl.xaml.cs

    using System;
    using System.IO;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;

    namespace client
    {
        public class MyControl: Control
        {
            public MyControl()
            {
                Stream s = this.GetType().Assembly.GetManifestResourceStream("client.MyControl.xaml");
                this.InitializeFromXaml(new StreamReader(s).ReadToEnd());
            }
        }
    }

     

  • tmasopust

    tmasopust

    Member

    4 Points

    2 Posts

    Re: Re: Problem with custom controls

    Jun 27, 2007 03:18 PM | LINK

    My issue is resolved. It also traced back to the constructor of the custom control. Inside the custom control's constructor there is a line:

    System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream("[YourFileName].xaml"); 

    When I set a breakpoint in this constructor, "GetManifestResourceStream" was returning null. The subsequent call to “InitializeFromXaml” caused the 2210 ParserError.

    After using the ILDASM to view the manifest of the control’s DLL, I noticed that the embedded resource for the xaml file was prefixed with a namespace that I had not placed in the GetManifestResourceStream parameter.

  • Snowbunny

    Snowbunny

    Member

    10 Points

    9 Posts

    Re: Re: Problem with custom controls

    Jun 28, 2007 07:03 AM | LINK

    Ah, mine was a different issue - eventually I found out that the Build Action for the XAML wasn't set to 'Embedded Resource' as it should have been.... Fixing this solved my issue.

     

    Hope this helps someone.