System.IO.FileNotFoundException:由自己的控件引起的InitializeComponent

时间:2015-11-07 12:20:50

标签: c# ios xamarin xamarin.forms

我在创建自己的控件时遇到问题:我正在尝试使网格视图类似于列表视图。问题出在页面的xaml文件中 - 当我初始化我的组件应用程序崩溃时,该页面上找不到文件异常。

  

错误说:System.IO.FileNotFoundException无法加载文件或程序集“FastFood”或其依赖项之一。系统不能   找到指定的文件。

     

调用栈

sudo
     

[0x00081] in   /Users/builder/data/lanes/2320/1f068b49/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/AppDomain.cs:706

    _at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity)
     

/Users/builder/data/lanes/2320/1f068b49/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/AppDomain。 CS:674

at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef) [0x00000] in
     

/Users/builder/data/lanes/2320/1f068b49/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/ Assembly.cs:551

at System.Reflection.Assembly.Load (System.Reflection.AssemblyName assemblyRef) [0x00000] in
     

System.Reflection.Assembly currentAssembly,   Xamarin.Forms.Xaml.XamlParseException&安培;异常)[0x00133] in:0       在Xamarin.Forms.Xaml.CreateValuesVisitor.Visit(Xamarin.Forms.Xaml.ElementNode节点,INode parentNode)[0x0002a] in   :0       在Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor,INode parentNode)[0x000b1] in:0       在Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor,INode parentNode)[0x00089] in:0       在Xamarin.Forms.Xaml.RootNode.Accept(IXamlNodeVisitor visitor,INode parentNode)[0x00064] in:0       在Xamarin.Forms.Xaml.XamlLoader.Load(Xamarin.Forms.BindableObject视图,System.String xaml)[0x000a4]中   :0       在Xamarin.Forms.Xaml.XamlLoader.Load(Xamarin.Forms.BindableObject视图,System.Type callingType)[0x0002e]   in:0       在Xamarin.Forms.Xaml.Extensions.LoadFromXaml [CategoryPage](FastFood.CategoryPage视图,System.Type callingType)[0x00000] in:0       在/Users/Slider/Coffetab/iOS/obj/iPhoneSimulator/Debug/FastFood.iOS..Users.Slider.Coffetab.FastFood.CategoryPage.xaml.g.cs:33中的FastFood.CategoryPage.InitializeComponent()[0x0000c] / p>

at Xamarin.Forms.Xaml.XamlParser.GetElementType (Xamarin.Forms.Xaml.XmlType xmlType, IXmlLineInfo xmlInfo,
     

/Users/Slider/Coffetab/FastFood/MainPage.xaml.cs:29       在Xamarin.Forms.Button.Xamarin.Forms.IButtonController.SendClicked()   [0x00020] in:0       在Xamarin.Forms.Platform.iOS.ButtonRenderer.OnButtonTouchUpInside(System.Object sender,System.EventArgs eventArgs)[0x0000e] in:0       在/Users/builder/data/lanes/2320/1f068b49/source/maccore/src/UIKit/UIControl.cs:37中的UIKit.UIControlEventProxy.Activated()[0x00007]中

at FastFood.CategoryPage..ctor () [0x0001a] in /Users/Slider/Coffetab/FastFood/CategoryPage.xaml.cs:25 
at FastFood.MenuPage..ctor () [0x0004b] in /Users/Slider/Coffetab/FastFood/MenuPage.xaml.cs:14 
at FastFood.MainPage.OnLogin (System.Object sender, System.EventArgs e) [0x0002f] in
     

/Users/builder/data/lanes/2320/1f068b49/source/maccore/src/UIKit/UIApplication.cs:77

at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in
     

/Users/builder/data/lanes/2320/1f068b49/source/maccore/src/UIKit/UIApplication.cs:61

at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in

我做错了什么?

1 个答案:

答案 0 :(得分:0)

几年后(为您),但我在一个论坛上找到了解决方案。

我在其他组件和NuGet上也遇到过这种情况 包。您可能不得不忍受必须 包括实例化ExtendedSlider的伪代码行。它 无需执行任何操作,只需在某处引用它即可。

仅在XAML中使用它时,编译器不会检测到 参考,因此排除了所需的dll。直到创建者 组件为此找到了一些解决方法,您必须使用此替代方法。

来源:https://forums.xamarin.com/discussion/comment/187222/#Comment_187222

因此,只需在代码中的任意位置添加随机var foo = new YourComponentFromTheAssemblyInQuestion();,它就不会再抱怨了。

也许这将有助于其他人像我一样在以后遇到同样的问题。