Skip to main content
Microsoft Silverlight
Home Forums General Silverlight Getting Started Problem with custom controls
13 replies. Latest Post by mchlSync on January 13, 2008.
(0)
Snowbunny
Member
10 points
9 Posts
06-04-2007 12:09 PM |
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.
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 messageErrorCode: 2210ErrorType: ParserErrorMessage: AG_E_INVALID_ARGUMENTXamlFile: Page.xamlLine: 19Position: 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
458 points
123 Posts
06-05-2007 1:21 PM |
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
4 points
2 Posts
06-08-2007 2:04 PM |
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
8 points
5 Posts
06-13-2007 2:18 AM |
im gettin tis error whn im running the code
Silverlight error messageErrorCode: 2254ErrorType: Parser ErrorMessage: AG_E_RUNTIME_MANAGER_ASSEMBLY_DOWNLOADXamlFile:xaml/Page.xamlLine: 10Position:3
x:Class="SilverlightStarterKit.Page;assembly=ClientBin/SilverlightStarterKit.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
34 points
16 Posts
06-19-2007 6:10 AM |
Hi Sony5,
I have tried same thing as above. But not get solution of my error.
Any help?
Thanks in Advance.
Alex Ivanov
18 points
30 Posts
06-19-2007 1:51 PM |
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:
<
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.
06-20-2007 1:23 AM |
Thanks Alex,
My problem has solved.
lefnire
20 points
13 Posts
06-24-2007 12:56 PM |
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()); } }}
06-27-2007 11:18 AM |
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.
06-28-2007 3:03 AM |
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.
06-28-2007 5:18 AM |
Better to try code given in Silverlight Alpha 1.1 SDK/Control Library Starter kit.
{
resourceStream = assembly.GetManifestResourceStream(name);
It dynamically resolves issue related to assembly stream reader.
Thanks & regards,
Nirajswami
varza
4 Posts
12-20-2007 6:40 AM |
I'm getting the same error as sony05.
AG_E_RUNTIME_MANAGER_ASSEMBLY_DOWNLOAD
I built a custom control in a Silverlight class library and referenced it from a Silverlight project.
I used Expression Blend to open the xaml file where I used my custom control and I got the error:
The name 'SlidingText' does not exist in the namespace 'clr-namespace:SilverControls;assembly=ClientBin/SilverControls.dll'.
My xaml file from the Sillverligh project references the assembly like this:
xmlns:my
Any idea what the problem could be?
mario_mh
498 points
117 Posts
01-11-2008 6:25 AM |
the problem with the embedded resource comes when you copy the [FileName].xaml and .cs into the project. so whenever you add an exiting control, "BuildAction" is Silverlightpage, but for a control it should be embedded resource as Snowbunny already mentioned
furthermore, you need to change the filename in
System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream("[ProjectName].[File].xaml");
mchlsync
Star
14606 points
2,732 Posts
01-13-2008 11:00 PM |
You can take a look this sample. You can download the sample (zip format) that is working with Silverlight 1.1 beta.