【问题标题】:Exception when run Aspnet Mvc app on OS X在 OS X 上运行 Aspnet Mvc 应用程序时出现异常
【发布时间】:2015-01-11 18:06:19
【问题描述】:

我正在尝试在 os x 上运行 aspnet 5 的示例: git clone https://github.com/shirhatti/Home.git

当我构建项目 HelloMvc -- 'kpm build' -- 没关系。 然后我使用“k kestrel”运行应用程序并看到以下错误:

在程序集 data-0x7feb6aa02a00 中缺少方法 Microsoft.Framework.Runtime.ILibraryInformation::get_LoadableAssemblies(),在程序集 /Users/minya/.kpm/packages/Microsoft.AspNet.Mvc.Core/6.0.0-beta2- 中引用11905/lib/aspnet50/Microsoft.AspNet.Mvc.Core.dll System.MissingMethodException:找不到方法:“Microsoft.Framework.Runtime.ILibraryInformation.get_LoadableAssemblies”。 在 System.Linq.Enumerable+c__Iterator122[Microsoft.Framework.Runtime.ILibraryInformation,System.Reflection.AssemblyName].MoveNext () [0x00000] in <filename unknown>:0 at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator102[System.Reflection.AssemblyName,System.Reflection.Assembly].MoveNext () [0x00000] in :0 在 System.Linq.Enumerable+c__Iterator122[System.Reflection.Assembly,System.Reflection.TypeInfo].MoveNext () [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Mvc.ControllerActionDescriptorProvider.BuildModel () [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Mvc.ControllerActionDescriptorProvider.GetDescriptors () [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Mvc.ControllerActionDescriptorProvider.Invoke (Microsoft.AspNet.Mvc.ActionDescriptorProviderContext context, System.Action callNext) [0x00000] in <filename unknown>:0 at Microsoft.Framework.DependencyInjection.NestedProviders.NestedProviderManager1+CallNext[Microsoft.AspNet.Mvc.ActionDescriptorProviderContext].CallNextProvider () [0x00000] 在:0 在 Microsoft.Framework.DependencyInjection.NestedProviders.NestedProviderManager1[Microsoft.AspNet.Mvc.ActionDescriptorProviderContext].Invoke (Microsoft.AspNet.Mvc.ActionDescriptorProviderContext context) [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Mvc.DefaultActionDescriptorsCollectionProvider.GetCollection () [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Mvc.DefaultActionDescriptorsCollectionProvider.get_ActionDescriptors () [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Mvc.Routing.AttributeRouting.GetActionDescriptors (IServiceProvider services) [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Mvc.Routing.AttributeRouting.CreateAttributeMegaRoute (IRouter target, IServiceProvider services) [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Builder.BuilderExtensions.UseMvc (IApplicationBuilder app, System.Action1 configureRoutes) [0x00000] 在:0 在 Microsoft.AspNet.Builder.BuilderExtensions.UseMvc(IApplicationBuilder 应用程序)[0x00000] 中:0 在 KWebStartup.Startup.Configure(IApplicationBuilder 应用程序)[0x00000] 中:0 在(包装器托管到本机) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) 在 System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] 参数, System.Globalization.CultureInfo 文化) [0x00000] in :0

谷歌没有确切的问题。我试图重新安装 kvm,删除并签出 NuGet 部门。

更新: 当我尝试通过“k web”运行同一个项目时,Windows 上的类似行为:

System.MissingMethodException:找不到方法:'System.Collections.Generic.IEnumerable1<System.Reflection.AssemblyName> Microsoft.Framework.Runtime.ILibraryInformation.g et_LoadableAssemblies()'.
at Microsoft.AspNet.Mvc.DefaultAssemblyProvider.<>c__DisplayClass0.<get_CandidateAssemblies>b__1(ILibraryInformation l)
at System.Linq.Enumerable.<SelectManyIterator>d__14
2.MoveNext()
在 System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
at System.Linq.Enumerable.<SelectManyIterator>d__14
2.MoveNext()
在 System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext()
at Microsoft.AspNet.Mvc.ControllerActionDescriptorProvider.BuildModel()
at Microsoft.AspNet.Mvc.ControllerActionDescriptorProvider.GetDescriptors()
at Microsoft.AspNet.Mvc.ControllerActionDescriptorProvider.Invoke(ActionDescriptorProviderContext context, Action callNext)
at Microsoft.Framework.DependencyInjection.NestedProviders.NestedProviderManager
1.CallNext.CallNextProvider()
在 Microsoft.Framework.DependencyInjection.NestedProviders.NestedProviderManager1.Invoke(T context)
at Microsoft.AspNet.Mvc.DefaultActionDescriptorsCollectionProvider.GetCollection()
at Microsoft.AspNet.Mvc.DefaultActionDescriptorsCollectionProvider.get_ActionDescriptors()
at Microsoft.AspNet.Mvc.Routing.AttributeRouting.GetActionDescriptors(IServiceProvider services)
at Microsoft.AspNet.Mvc.Routing.AttributeRouting.CreateAttributeMegaRoute(IRouter target, IServiceProvider services)
at Microsoft.AspNet.Builder.BuilderExtensions.UseMvc(IApplicationBuilder app, Action
1 configureRoutes)
在 Microsoft.AspNet.Builder.BuilderExtensions.UseMvc(IApplicationBuilder 应用程序)
在 C:\prj\Home\samples\HelloMvc\Startup.cs:第 18 行中的 HelloMvc.Startup.Configure(IApplicationBuilder 应用程序)

似乎问题出在 Microsoft.AspNet.Mvc.* 程序集中引用的一个(或多个)中。这是来自 Microsoft.AspNet.Mvc.Core 的 DefaultAssemblyProvider 的反汇编。我猜问题出在 ILibraryManager 的实现 GetReferenceLibraries() 方法中。但我找不到这个实现。

public class DefaultAssemblyProvider : IAssemblyProvider
{
    private static readonly HashSet<string> _mvcAssemblyList;
    private readonly ILibraryManager _libraryManager;

    public IEnumerable<Assembly> CandidateAssemblies
    {
        get
        {
            return Enumerable.Select<AssemblyName, Assembly>(Enumerable.SelectMany<ILibraryInformation, AssemblyName>(this.GetCandidateLibraries(), DefaultAssemblyProvider.\u003C\u003Ec__DisplayClass0.CS\u0024\u003C\u003E9__CachedAnonymousMethodDelegate2 ?? (DefaultAssemblyProvider.\u003C\u003Ec__DisplayClass0.CS\u0024\u003C\u003E9__CachedAnonymousMethodDelegate2 = new Func<ILibraryInformation, IEnumerable<AssemblyName>>(DefaultAssemblyProvider.\u003C\u003Ec__DisplayClass0.CS\u0024\u003C\u003E9__inst.\u003Cget_CandidateAssemblies\u003Eb__1))), new Func<AssemblyName, Assembly>(DefaultAssemblyProvider.Load));
        }
    }

    static DefaultAssemblyProvider()
    {
        HashSet<string> hashSet = new HashSet<string>((IEqualityComparer<string>) StringComparer.Ordinal);
        string str1 = "Microsoft.AspNet.Mvc";
        hashSet.Add(str1);
        string str2 = "Microsoft.AspNet.Mvc.Core";
        hashSet.Add(str2);
        string str3 = "Microsoft.AspNet.Mvc.ModelBinding";
        hashSet.Add(str3);
        string str4 = "Microsoft.AspNet.Mvc.Razor";
        hashSet.Add(str4);
        string str5 = "Microsoft.AspNet.Mvc.Razor.Host";
        hashSet.Add(str5);
        string str6 = "Microsoft.AspNet.Mvc.Rendering";
        hashSet.Add(str6);
        DefaultAssemblyProvider._mvcAssemblyList = hashSet;
    }

    public DefaultAssemblyProvider(ILibraryManager libraryManager)
    {
        this._libraryManager = libraryManager;
    }

    internal IEnumerable<ILibraryInformation> GetCandidateLibraries()
    {
        return Enumerable.Where<ILibraryInformation>(Enumerable.Distinct<ILibraryInformation>(Enumerable.SelectMany<string, ILibraryInformation>((IEnumerable<string>) DefaultAssemblyProvider._mvcAssemblyList, new Func<string, IEnumerable<ILibraryInformation>>(this._libraryManager.GetReferencingLibraries))), new Func<ILibraryInformation, bool>(DefaultAssemblyProvider.IsCandidateLibrary));
    }

    private static Assembly Load(AssemblyName assemblyName)
    {
        return Assembly.Load(assemblyName);
    }

    private static bool IsCandidateLibrary(ILibraryInformation library)
    {
        return !DefaultAssemblyProvider._mvcAssemblyList.Contains(library.get_Name());
    }
}

【问题讨论】:

  • 几件事:1)。这里没有问题。 2)。请格式化您的错误 sn-p。 3)。在把它扔在这里之前,请向我们展示你为解决你的问题所做的工作。我们不是您的个人 GoG(Google 员工组)
  • @JSKNS 感谢 cmets。对不起第一个版本。
  • kvm list 的输出是什么?
  • Active Version Runtime Architecture Location ------ ------- ------- ------------ -------- 1.0.0-beta1 Mono.1.0.0 x86 /Users/minya/.kre/packages 1.0.0-alpha3-10143 mono45 x86 /Users/minya/.kre/packages * 1.0.0-alpha4-10353 mono45 x86 /Users/minya/.kre/packages`

标签: asp.net-mvc macos kvm asp.net-core kruntime


【解决方案1】:

我在 Windows 上遇到了类似的问题,发现激活了错误的 KRE。

执行 kvm list 会显示 KRE 列表。在我的情况下,1.0.0-alpha4 版本处于活动状态,而不是更新的 beta 版本。

使用kvm use default 切换到默认设置为我解决了问题。

【讨论】:

  • 是的,这是个问题。我检测到我的机器上有 2 个不同的 KRE。首先在我家 (~/.kre/) 中,然后在 /usr/local/Cellar/kre 中。然后另外我无法选择 kre 的 beta1 使用 kvm 使用。所以我从我的机器上删除了所有的 kre、kvm、kpm 包并重新安装。现在一切正常。
【解决方案2】:

我能够通过更新我的 KVM 版本来解决此错误,可能有一种更简单的方法,但假设您最初使用自制软件安装,运行这些命令应该可以解决您的问题

  • brew untap aspnet/k
  • brew tap aspnet/k
  • brew install kvm

那么你应该可以运行 kestrel

如果您收到 kvm 已安装的消息,则:

  • 酿造链接--覆盖单声道
  • brew 卸载单声道
  • brew 重新安装 kvm

【讨论】:

  • 如果 brew 说 kvm 已安装,则更新答案并提供更多信息
  • 我尝试在 Windows 中运行相同的应用程序。我也有类似的错误。我已经更新了我的帖子。我认为kre没有问题。相反,问题似乎出在 asp.net 库中。
  • 是的,事后看来,重新安装 kvm 只是在后台更新了一些单声道依赖项,这为我解决了问题
  • 你运行的是什么版本的单声道?
  • kre 版本为 1.0.0-alpha4-10353 mono45 x86; mono --version: Mono JIT 编译器版本 3.10.0 (tarball Wed Oct 22 10:06:03 BST 2014)
猜你喜欢
  • 2021-05-29
  • 2011-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多