Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc Mono 4.5概要文件,实体框架Npgsql-NpgsqlSystem.InvalidCastException无法从源类型强制转换为目标类型_Asp.net Mvc_Entity Framework_Mono_Npgsql - Fatal编程技术网

Asp.net mvc Mono 4.5概要文件,实体框架Npgsql-NpgsqlSystem.InvalidCastException无法从源类型强制转换为目标类型

Asp.net mvc Mono 4.5概要文件,实体框架Npgsql-NpgsqlSystem.InvalidCastException无法从源类型强制转换为目标类型,asp.net-mvc,entity-framework,mono,npgsql,Asp.net Mvc,Entity Framework,Mono,Npgsql,我有“系统无效”例外 无法从源类型强制转换为目标类型。”当尝试在后端使用mono 4.5配置文件和postgres从asp.net mvc3访问数据库时 下面是我的代码的样子: public class User { public int Id { get; set; } public string Username { get; set; } public string PasswordHash { get; set; } public string Passw

我有“系统无效”例外 无法从源类型强制转换为目标类型。”当尝试在后端使用mono 4.5配置文件和postgres从asp.net mvc3访问数据库时

下面是我的代码的样子:

public class User
{
    public int Id { get; set; }
    public string Username { get; set; }
    public string PasswordHash { get; set; }
    public string PasswordSalt { get; set; }    
} // class
AppContext:

using System;
using System.Data.Entity;
using Npgsql;
using NpgsqlTypes;

namespace Web
{
public class AppContext : DbContext
{
    public DbSet<User> Users { get; set; }

    protected override void OnModelCreating (DbModelBuilder modelBuilder)
    {
        base.OnModelCreating (modelBuilder);
    }   
} // class
} // namespace
我得到的错误是:

System.InvalidCastException

Cannot cast from source type to destination type.

Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): Npgsql.
Exception stack trace:
at Npgsql.NpgsqlFactory.CreateConnection () [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/mcs/class/Npgsql/Npgsql/NpgsqlFactory.cs:64
at System.Data.Entity.Internal.LazyInternalConnection.CreateConnectionFromProviderName (string) [0x00007] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalConnection.cs:379
at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting (System.Configuration.ConnectionStringSettings) [0x00045] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalConnection.cs:368
at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig (string,System.Data.Entity.Internal.AppConfig) [0x0000e] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalConnection.cs:310
at System.Data.Entity.Internal.LazyInternalConnection.Initialize () [0x00047] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalConnection.cs:242
at System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName () [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalConnection.cs:118
at System.Data.Entity.Internal.LazyInternalContext.get_ProviderName () [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalContext.cs:290
at System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create (System.Data.Entity.DbContext) [0x00022] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/DefaultModelCacheKeyFactory.cs:20
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext () [0x00091] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalContext.cs:388
at System.Data.Entity.Internal.InternalContext.Initialize () [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/InternalContext.cs:421
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType (System.Type) [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/InternalContext.cs:650
at System.Data.Entity.Internal.Linq.InternalSet`1<Web.Users>.Initialize () <0x0006f>
at System.Data.Entity.Internal.Linq.InternalSet`1<Web.Users>.get_InternalContext () <0x00028>
at System.Data.Entity.Internal.Linq.InternalSet`1<Web.Users>.Find (object[]) <0x0002e>
at System.Data.Entity.DbSet`1<Web.Users>.Find (object[]) <0x0002f>
at Web.Controllers.HomeController.Index () [0x0001c] in /Users/nix/Documents/Projects/Dot.NET/Store/Web/Controllers/HomeController.cs:15
at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,System.Web.Mvc.ControllerBase,object[]) <IL 0x00006, 0x0003f>
at System.Web.Mvc.ActionMethodDispatcher.Execute (System.Web.Mvc.ControllerBase,object[]) [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/mcs/class/System.Web.Mvc3/Mvc/ActionMethodDispatcher.cs:27
at System.Web.Mvc.ReflectedActionDescriptor.Execute (System.Web.Mvc.ControllerContext,System.Collections.Generic.IDictionary`2<string, object>) [0x00074] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/mcs/class/System.Web.Mvc3/Mvc/ReflectedActionDescriptor.cs:84
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod (System.Web.Mvc.ControllerContext,System.Web.Mvc.ActionDescriptor,System.Collections.Generic.IDictionary`2<string, object>) [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/mcs/class/System.Web.Mvc3/Mvc/ControllerActionInvoker.cs:173
at System.Web.Mvc.ControllerActionInvoker/<InvokeActionMethodWithFilters>c__AnonStorey3B.<>m__46 () [0x00014] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/mcs/class/System.Web.Mvc3/Mvc/ControllerActionInvoker.cs:216
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter (System.Web.Mvc.IActionFilter,System.Web.Mvc.ActionExecutingContext,System.Func`1<System.Web.Mvc.ActionExecutedContext>) [0x00033] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/mcs/class/System.Web.Mvc3/Mvc/ControllerActionInvoker.cs:189
System.InvalidCastException
无法从源类型强制转换为目标类型。
描述:HTTP 500。处理请求时出错。
详细信息:非web异常。异常源(应用程序或对象的名称):Npgsql。
异常堆栈跟踪:
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/mcs/class/Npgsql/Npgsql/NpgsqlFactory.cs:64中的Npgsql.NpgsqlFactory.CreateConnection()[0x00000]
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/entityframework/Internal/lazynternalconnection.cs379中的System.Data.Entity.internalconnection.CreateConnectionFromProviderName(string)[0x00007]中
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/entityframework/Internal/lazynternalconnection.cs:368中的System.Data.Entity.entications.connection.lazynternalconnection.initializefromconnectionstringset(System.Configuration.ConnectionStringSettings)[0x00045]
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/entityframework/Internal/lazynternalconnection.cs:310中的System.Data.Entity.internalconnection.TryInitializeFromAppConfig(string,System.Data.Entity.Internal.AppConfig)[0x0000e]
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/entityframework/Internal/lazynternalconnection.cs:242中的System.Data.Entity.Internal.lazynternalconnection.Initialize()[0x00047]
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/entityframework/Internal/lazynternalconnection.cs:118中的System.Data.Entity.Internal.lazynternalconnection.get_ProviderName()[0x00000]
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/entityframework/Internal/lazynternalcontext.get_ProviderName()[0x00000]中
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/entityframework/Internal/DefaultModelCacheKeyFactory.cs:20中的System.Data.Entity.Entity.Entity.Entity.DbContext[0x00022]创建
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/entityframework/Internal/lazynternalcontext.cs:388中的System.Data.Entity.Internal.lazynternalcontext.InitializeContext()[0x00091]
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/entityframework/Internal/InternalContext.cs:421中的System.Data.Entity.InternalContext.initial()[0x00000]
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/entityframework/Internal/InternalContext中的System.Data.Entity.setandbasetypefortype(System.Type)[0x00000
位于System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
位于System.Data.Entity.Internal.Linq.InternalSet`1.get\u InternalContext()
位于System.Data.Entity.Internal.Linq.InternalSet`1.Find(对象[])
位于System.Data.Entity.DbSet`1.Find(对象[])
在/Users/nix/Documents/Projects/Dot.NET/Store/Web/Controllers/HomeController.cs:15中的Web.Controllers.HomeController.Index()[0x0001c]
at(包装器动态方法)object.lambda_方法(System.Runtime.CompilerServices.Closure,System.Web.Mvc.ControllerBase,object[])
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/mcs/class/System.Web.Mvc3/Mvc/ActionMethodDispatcher.cs:27中的System.Web.Mvc.Mvc.ActionMethodDispatcher.Execute(System.Web.Mvc.Mvc.ControllerBase,object[])[0x00000]
在/private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_-build/mono-2.11.git/mcs/class/System.Web.Mvc3/Mvc/ReflectedActionDescriptor.cs中的System.Web.Mvc.ReflectedActionDescriptor.Execute(System.Web.Mvc.Mvc.Mvc.idActionDescriptor.iductor.2)[0x00074]
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/mcs/class/System/System.Mvc3/Mvc/ControllerActionInvoker.cs:173中的System.Web.Mvc.Mvc.ControllerActionInvoker.InvokeActionMethod(System.Web.Mvc.ControllerContext,System.Mvc.Mvc.ActionDescriptor,System.Collections.Generic.IDictionary`2)[][.0x00000]
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/mcs/class/System.Web.Mvc3/Mvc/ControllerActionInvoker.cs:216中的System.Web.Mvc.Mvc.ControllerActionInvoker/c/c AnonStorey3B.m\u 46()[0x00014]
在/private/tmp/source/bockbuild/profiles/mono-mac release/build root/mono-2.11/_build/mono-2.11.git/mcs/class/System/Web.Mvc3/Mvc/ControllerActionInvoker.cs:189中的System.Web.Mvc.ControllerActionInvoker.invoker.InvokeActionMethodFilter(System.Web.Mvc.IActionFilter,System.Mvc.IActionFilter,System.Mvc.ActionExecutingContext,System.Func`1)[00033]

关于发生了什么有什么建议或线索吗?

根据我的经验,这个问题是由于编译器混淆了Npgsql的dll和gac版本

您正在引用Npgsql的dll吗? 如果是,并且不需要,请尝试删除引用和dll,并将其替换为N
System.InvalidCastException

Cannot cast from source type to destination type.

Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): Npgsql.
Exception stack trace:
at Npgsql.NpgsqlFactory.CreateConnection () [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/mcs/class/Npgsql/Npgsql/NpgsqlFactory.cs:64
at System.Data.Entity.Internal.LazyInternalConnection.CreateConnectionFromProviderName (string) [0x00007] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalConnection.cs:379
at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting (System.Configuration.ConnectionStringSettings) [0x00045] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalConnection.cs:368
at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig (string,System.Data.Entity.Internal.AppConfig) [0x0000e] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalConnection.cs:310
at System.Data.Entity.Internal.LazyInternalConnection.Initialize () [0x00047] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalConnection.cs:242
at System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName () [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalConnection.cs:118
at System.Data.Entity.Internal.LazyInternalContext.get_ProviderName () [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalContext.cs:290
at System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create (System.Data.Entity.DbContext) [0x00022] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/DefaultModelCacheKeyFactory.cs:20
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext () [0x00091] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/LazyInternalContext.cs:388
at System.Data.Entity.Internal.InternalContext.Initialize () [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/InternalContext.cs:421
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType (System.Type) [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/external/entityframework/src/EntityFramework/Internal/InternalContext.cs:650
at System.Data.Entity.Internal.Linq.InternalSet`1<Web.Users>.Initialize () <0x0006f>
at System.Data.Entity.Internal.Linq.InternalSet`1<Web.Users>.get_InternalContext () <0x00028>
at System.Data.Entity.Internal.Linq.InternalSet`1<Web.Users>.Find (object[]) <0x0002e>
at System.Data.Entity.DbSet`1<Web.Users>.Find (object[]) <0x0002f>
at Web.Controllers.HomeController.Index () [0x0001c] in /Users/nix/Documents/Projects/Dot.NET/Store/Web/Controllers/HomeController.cs:15
at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,System.Web.Mvc.ControllerBase,object[]) <IL 0x00006, 0x0003f>
at System.Web.Mvc.ActionMethodDispatcher.Execute (System.Web.Mvc.ControllerBase,object[]) [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/mcs/class/System.Web.Mvc3/Mvc/ActionMethodDispatcher.cs:27
at System.Web.Mvc.ReflectedActionDescriptor.Execute (System.Web.Mvc.ControllerContext,System.Collections.Generic.IDictionary`2<string, object>) [0x00074] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/mcs/class/System.Web.Mvc3/Mvc/ReflectedActionDescriptor.cs:84
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod (System.Web.Mvc.ControllerContext,System.Web.Mvc.ActionDescriptor,System.Collections.Generic.IDictionary`2<string, object>) [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/mcs/class/System.Web.Mvc3/Mvc/ControllerActionInvoker.cs:173
at System.Web.Mvc.ControllerActionInvoker/<InvokeActionMethodWithFilters>c__AnonStorey3B.<>m__46 () [0x00014] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/mcs/class/System.Web.Mvc3/Mvc/ControllerActionInvoker.cs:216
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter (System.Web.Mvc.IActionFilter,System.Web.Mvc.ActionExecutingContext,System.Func`1<System.Web.Mvc.ActionExecutedContext>) [0x00033] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-2.11/_build/mono-2.11.git/mcs/class/System.Web.Mvc3/Mvc/ControllerActionInvoker.cs:189