Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Silverlight 2 Beta Bug?
17 replies. Latest Post by Bijoy Thangaraj on November 6, 2008.
(0)
arshadm
Member
20 points
7 Posts
04-26-2008 4:45 AM |
Hi,
I am trying to write a library of usercontrols that the rest of my applications can use but have come across a problem. Let's say I create a user control called MyControl and then I create a subclass of that (a standard class) then we I try and create an instance of the new class I get the following error
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.dll
Additional information: AG_E_PARSER_BAD_TYPE [Line: 4 Position: 29]
From reading on the internet I gather this is because the x:Class in the XAML does not match the type to Application.LoadComponent in InitializeComponent. In my case the argument to Application.LoadComponent is the subclass, but I don't see why that should cause a problem per se.
Any ideas why this behaviour is implement in Silverlight.
Regards.
mchlsync
Star
14566 points
2,730 Posts
04-26-2008 6:08 AM |
Someone posted about that in this forum earlier. I tried two different approach in User control inheritance.
1)
http://michaelsync.net/2008/03/24/silverlight-2-beta1-user-control-inheritance
2)
Both ways are working fine. Are you using other different way? Can you show us your code?
04-26-2008 7:00 AM |
I am trying to use your first solution but I am still not getting it to work. Here are the files (main snippet, just missing using clauses).
SimplyActivity.xaml:
<
<TextBlock x:Name="QuestionText" Text="Question" Canvas.Top="100" Canvas.Left="20" VerticalAlignment="Bottom" Width="250" Height="250"></TextBlock>
</
SimpleActivity.xaml.cs:
InitializeComponent();
}
Sublcass SilverlightControl1.xaml:
SilverlightControl1.xaml:
Here is code where I create an instance of the subclass and then add it as a child to a canvas in my application:
LayoutRoot.Children.Add(control);
As mentioned this gives an exception as follows:
Additional information: System.Windows.Markup.XamlParseException: AG_E_PARSER_BAD_TYPE [Line: 4 Position: 29]
The only thing I didn't do which was mentioned in your blog is add anything to the assemblies, but I thought that was if I wanted add the name to a namespace so that I could use it as child.
04-26-2008 11:02 AM |
I have tested your code. It's working fine. (I think there are some typo errors in yourposts)
You can download the code from this link. http://michaelsync.net/demo/SilverlightApplication10.zip
04-26-2008 12:42 PM |
Hmm, your code works if the subclass is treated as a control via the assembly.
But, if I add the following line to Page.xaml.cs then it throws the error I mention, and I am not sure why anymore because it works when it's used via the Xaml but not in code.
Canvas.SetLeft(50);
I changed the Page.xaml to remove the mention of the control to :-
This should be doing in C# code what the xaml is doing, but it throws the exception I mentioned above.
04-26-2008 1:00 PM |
Sorry, syntax error in code
But still gives same exception.
04-27-2008 1:43 AM |
You are right. Adding the control from code is giving you this problem... Is it possible for you to add the control in XAML? (Like I did in my sample)
04-27-2008 2:39 AM |
Actually, it doesn't work from the XAML either because afterwards I noticed that Page.xaml was uing ctl:SimplyActivity rather than the subclass ctl:SilverlightControl1, when I changed that it gave the same error.
I think I can understand why this might not be allowed in the current circumstances because it doesn't really make sense to have two separate XAML in the class hierarchy (which one is the real user interface because there can only be one root control in each user control).
My original requirement though was much simpler and shouldn't cause a problem as far as I can see, I wanted a base class with XAML. This base class may be abstract, a derived class would then provide the actual implementation for the event handlers and other logic. I think this would be a very useful feature, but obviously since I am a Silverlight newbie it might open up a can of worms which I don't understand.
Necroman
04-27-2008 5:42 AM |
I use different way, when inheriting objects:
3)
In classic WPF it works without a problem, but in Silverlight 2 I still get the error, when I try to instantiate MyControl.
MyControl control = new MyControl();
It crashes with AG_E_PARSER_BAD_TYPE when calling InitializeComponents() in BaseControl.Just try it and you'll surely get the same error message.
Btw. In your example, http://michaelsync.net/demo/SilverlightApplication10.zip you are adding the Base class <ctl:SimplyActivity /> into Page, try adding the inherited class <ctl:SilverlightControl1 /> and you get the exact same error.
04-29-2008 1:47 AM |
Hello,
The problem is that we can't have XAML in Base Control. Is it possible for you not to use XAML in BaseControl?
Yi-Lun L...
All-Star
25052 points
2,747 Posts
04-29-2008 2:33 AM |
Hello, this is a known issue. It's true that if the base UserControl is declared in XAML, the sub UserControl can only use code. But due to some internal parser issues, currently even if the sub UserControl only uses code, you'll get errors. Our developers are tracking this issue. But sorry I can't give you more details at this time...
04-29-2008 3:34 AM |
Yi-Lun Luo - MSFT:Hello, this is a known issue. It's true that if the base UserControl is declared in XAML, the sub UserControl can only use code. But due to some internal parser issues, currently even if the sub UserControl only uses code, you'll get errors. Our developers are tracking this issue. But sorry I can't give you more details at this time...
Thanks for your reply. Yi-Lun.
makkros
14 points
09-17-2008 7:28 AM |
Hi
what about the solution of this problem? Does this problem is solved in the future release? Actually I can't run my silverlight application and I need to kwow it in order to plan the update that application.
Thanks in advance
09-24-2008 5:22 AM |
Hi all,
does anybody has found a workaround to this problem?
Yi-Lun Luo - MSFT: It's true that if the base UserControl is declared in XAML, the sub UserControl can only use code. But due to some internal parser issues, currently even if the sub UserControl only uses code, you'll get errors.
It's true that if the base UserControl is declared in XAML, the sub UserControl can only use code. But due to some internal parser issues, currently even if the sub UserControl only uses code, you'll get errors.
I have urgently to solve it, otherwise I have to change all my application logic.
thanks
peterdungan
223 points
150 Posts
10-28-2008 4:36 PM |
I'm getting this error after trying to update a beta 2 project to rtw.
It worked fine in beta 2.
Should it also wrk ok in rtw, or does it indicate the update didn't work properly?
10-29-2008 5:07 AM |
Strange, because with the final release it worked for me .
I have the base UserControl declared in XAML and the sub UserControl in the code only.
10-30-2008 11:38 AM |
Sorry I found that the error I was getting was because of some differences in xaml syntax when I upgraded - it wasn't due to this bug
Bijoy Th...
29 points
29 Posts
11-06-2008 6:36 AM |
What were those differences?
Play hundreds of free games at JoyRack Games