将 StructureMap 与 Xamarin.Forms 一起使用

Using StructureMap with Xamarin.Forms

我正在开发基于 Xamarin Forms 的跨平台应用程序。 在我的应用程序中,我想为 IoC 使用 StructureMap。

我制作了一个示例应用程序。添加 StructureMap 包 (4.6.1) 后,部署时出现错误:

Synchronizing files... Building and running... Built with 1 messages. (1,1): error: Failed to load assembly from stream: System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path "/data/user/0/com.xamarin.live/files/External/.nuget/packages/system.runtime.loader/4.3.0/ref/netstandard1.5/System.Runtime.Loader.dll". at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0017d] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
at System.IO.File.OpenRead (System.String path) [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at .$LocalFileSystem+Upsight-IFileSystem-OpenReadAsync@49-1.Invoke () [0x00012] in <5a7d391011b47c3aa745038310397d5a>:0 at System.Threading.Tasks.Task1[TResult].InnerInvoke () [0x0000f] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Threading.Tasks.Task.Execute () [0x00010] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 --- End of inner exception stack trace --- --- End of inner exception stack trace --- ---> (Inner Exception #0) System.AggregateException: One or more errors occurred. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path "/data/user/0/com.xamarin.live/files/External/.nuget/packages/system.runtime.loader/4.3.0/ref/netstandard1.5/System.Runtime.Loader.dll". at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0017d] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)<br> at System.IO.File.OpenRead (System.String path) [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at <StartupCode$Continuous-Core-Droid>.$LocalFileSystem+Upsight-IFileSystem-OpenReadAsync@49-1.Invoke () [0x00012] in <5a7d391011b47c3aa745038310397d5a>:0 at System.Threading.Tasks.Task1[TResult].InnerInvoke () [0x0000f] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Threading.Tasks.Task.Execute () [0x00010] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 --- End of inner exception stack trace --- ---> (Inner Exception #0) System.IO.DirectoryNotFoundException: Could not find a part of the path "/data/user/0/com.xamarin.live/files/External/.nuget/packages/system.runtime.loader/4.3.0/ref/netstandard1.5/System.Runtime.Loader.dll". at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0017d] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
at System.IO.File.OpenRead (System.String path) [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at .$LocalFileSystem+Upsight-IFileSystem-OpenReadAsync@49-1.Invoke () [0x00012] in <5a7d391011b47c3aa745038310397d5a>:0 at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 at System.Threading.Tasks.Task.Execute () [0x00010] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 <--- <---

Failed to debug your app.

我使用 Visual Studio 2017 (15.7.1) 和 Xamarin Forms 3.0.0.482510.

我对 Entity Framerwork Core SQLite 也有同样类型的问题

你遇到过这个错误吗?

我建议您不要在 Xamarin.Forms 上使用 StructureMap,因为它不受支持:

StructureMap 4.5+ will not work on Xamarin iOS because it depends on System.Reflection.Emit, which is not available in MonoTouch. StructureMap 4.4 works for at least basic scenarios on that platform. Nobody in the core StructureMap team is currently working with Xamarin mobile runtimes, but we are interested in verifying StructureMap on new platforms if any volunteers are interested in helping us out.

http://structuremap.github.io/get-structuremap/