How to parse a xaml which reference types from other dll ?
I want to develop a game support mod, in the mod there are xamls for GUI, and dlls for logic.
for example, the xaml like this:
xmlns:native="clr-namespace:Mods.Native;assembly=Assembly set the dll for mod.
This xaml is parsed in code
Assembly.Load(File.ReadAllBytes(filePath + "/mods/native/Assembly.dll")) load the dll, which have the class "SceneMainView".
The project is run succesful in Blend, but run faild in Unity. it report an exception:
I think it because the "Assembly.Load" not add assembly to Application. But how to resolve this issue?
for example, the xaml like this:
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:jui="clr-namespace:JiangH;assembly=JiangH.UI"
xmlns:native="clr-namespace:Mods.Native;assembly=Assembly"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Canvas>
<Canvas.DataContext>
<native:SceneMainView/>
</Canvas.DataContext>
<Label Name ="name" Content="{Binding player.name,FallbackValue = '_PLAYER_NAME_'}"/>
</Canvas>
</UserControl>
This xaml is parsed in code
Code: Select all
public partial class JiangHMainView : UserControl
{
public JiangHMainView()
{
InitializeComponent();
#if NOESIS
var filePath = UnityEngine.Application.streamingAssetsPath;
#else
var filePath = "../../../Assets/StreamingAssets";
#endif
var str = File.ReadAllText(filePath + "/mods/native/SceneMain.xaml");
var ass = Assembly.Load(File.ReadAllBytes(filePath + "/mods/native/Assembly.dll"));
var userControl = XamlReader.Parse(str) as UserControl;
var uiElement = userControl.Content as UIElement;
userControl.Content = null;
this.rootCanvas.Children.Add(uiElement);
}
The project is run succesful in Blend, but run faild in Unity. it report an exception:
Code: Select all
[NOESIS/E] <memory>(12): Unknown type 'mods.native.SceneMainView'.
UnityEngine.Debug:LogError (object,UnityEngine.Object)
NoesisUnity:UnityLog (int,string) (at Packages/NoesisGUI/Runtime/NoesisUnity.cs:317)
Noesis.GUI:ParseXaml (string) (at Packages/NoesisGUI/Runtime/API/Core/NoesisGUI.cs:291)
Noesis.XamlReader:Parse (string) (at Packages/NoesisGUI/Runtime/API/Proxies/XamlReader.cs:20)
JiangH.JiangHMainView:.ctor () (at Assets/Scenes/MainScene/JiangHMainView.xaml.cs:36)
(wrapper dynamic-method) object:lambda_method (System.Runtime.CompilerServices.Closure)
Noesis.Extend:CreateInstance (intptr,intptr) (at Packages/NoesisGUI/Runtime/API/Core/Extend.cs:4681)
Noesis.GUI:LoadXaml (System.IO.Stream,string) (at Packages/NoesisGUI/Runtime/API/Core/NoesisGUI.cs:270)
NoesisXaml:Load () (at Packages/NoesisGUI/Runtime/NoesisXaml.cs:17)
NoesisView:LoadXaml (bool) (at Packages/NoesisGUI/Runtime/NoesisView.cs:465)
NoesisView:OnEnable () (at Packages/NoesisGUI/Runtime/NoesisView.cs:553)
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: How to parse a xaml which reference types from other dll ?
Hi, this is related to issues #1016, #1283, and #1320, that we solved for next release.
As a workaround you can manually load the referenced assembly into the domain before loading the xaml:
As a workaround you can manually load the referenced assembly into the domain before loading the xaml:
Code: Select all
Assembly.Load("YourAssembly");
Who is online
Users browsing this forum: Google [Bot], vinick and 61 guests