在OS X上运行Aspnet Mvc应用程序时出现异常

时间:2014-11-14 10:59:35

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

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

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

  

程序集数据中缺少方法Microsoft.Framework.Runtime.ILibraryInformation :: get_LoadableAssemblies() - 0x7feb6aa02a00,在程序集/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__Iterator12 2[Microsoft.Framework.Runtime.ILibraryInformation,System.Reflection.AssemblyName].MoveNext () [0x00000] in <filename unknown>:0 at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10 2 [System.Reflection.AssemblyName,System.Reflection.Assembly] .MoveNext()[0x00000] in:0         在System.Linq.Enumerable + c__Iterator12 2[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.NestedProviderManager 1 + CallNext [Microsoft.AspNet.Mvc.ActionDescriptorProviderContext] .CallNextProvider()[0x00000] in:0         在Microsoft.Framework.DependencyInjection.NestedProviders.NestedProviderManager 1[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.Action 1 configureRoutes)[0x00000] in:0         在Microsoft.AspNet.Builder.BuilderExtensions.UseMvc(IApplicationBuilder app)[0x00000] in:0         在KWebStartup.Startup.Configure(IApplicationBuilder app)[0x00000] in:0         at(wrapper managed-to-native)System.Reflection.MonoMethod:InternalInvoke(System.Reflection.MonoMethod,object,object [],System.Exception&amp;)         在System.Reflection.MonoMethod.Invoke(System.Object obj,BindingFlags invokeAttr,System.Reflection.Binder binder,System.Object [] parameters,System.Globalization.CultureInfo culture)[0x00000] in:0

谷歌没有确切的问题。我试图重新安装kvm,删除和结帐NuGet deps。

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

  

System.MissingMethodException:找不到方法:'System.Collections.Generic.IEnumerable 1<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.WhereSelectEnumerableIterator 2.MoveNext()
at System.Linq.Enumerable.<SelectManyIterator>d__14
2.MoveNext()
     在System.Linq.Enumerable.WhereEnumerableIterator 1.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.NestedProviderManager 1.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应用程序)
     at HelloMvc.Startup.Configure(IApplicationBuilder app)在C:\ prj \ Home \ samples \ HelloMvc \ Startup.cs:第18行

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

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());
    }
}

2 个答案:

答案 0 :(得分:1)

我在Windows上遇到了类似的问题,发现错误的KRE处于活动状态。

执行kvm list会显示KRE列表。在我的情况下,1.0.0-alpha4版本是有效的,而不是最近的测试版。

切换到kvm use default的默认设置为我排序。

答案 1 :(得分:0)

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

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

然后你应该能够运行k kestrel

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

  • brew link --overwrite mono
  • brew uninstall mono
  • brew重新安装kvm