昨天我问了一个关于为什么我的程序没有创建数据库的问题,因为本教程http://www.entityframeworktutorial.net/code-first/code-first-conventions.aspx表明应该这样做。我修复了一些问题,但结果又抛出了另一个异常: 类型为#System; TypeInitializationException'的未处理异常发生在EntityFramework.dll
中其他信息:Typeinitialiseringsfunktionen for' System.Data.Entity.Internal.AppConfig'抛出异常。
因此,如果有人知道为什么会抛出此异常,请帮助:)
整个例外详情:
function PrintElem(elem) {
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head><title>' + document.title + '</title>');
mywindow.document.write('</head><body >');
mywindow.document.write('<h1>' + document.title + '</h1>');
mywindow.document.write(document.getElementById(elem).innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();
return true;
}
代码:
System.TypeInitializationException was unhandled HResult=-2146233036 Message=Typeinitialiseringsfunktionen for 'System.Data.Entity.Internal.AppConfig' udløste en undtagelse. Source=EntityFramework TypeName=System.Data.Entity.Internal.AppConfig StackTrace:
ved System.Data.Entity.Internal.AppConfig.get_DefaultInstance()
ved System.Data.Entity.Internal.LazyInternalConnection..ctor(DbContext context, String nameOrConnectionString)
ved System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
ved ShopEntity.ShopContext..ctor() i C:\Users\Anders\documents\visual studio 2015\Projects\ShopEntity\ShopEntity\ShopContext.cs:linje 12
ved ShopEntity.Program.Main() i C:\Users\Anders\documents\visual studio 2015\Projects\ShopEntity\ShopEntity\Program.cs:linje 17
ved System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
ved System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
ved Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
ved System.Threading.ThreadHelper.ThreadStart_Context(Object state)
ved System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
ved System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
ved System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
ved System.Threading.ThreadHelper.ThreadStart() InnerException:
BareMessage='connectionStrings'-element, der ikke er genkendt.
Filename=C:\Users\Anders\documents\visual studio 2015\Projects\ShopEntity\ShopEntity\bin\Debug\ShopEntity.vshost.exe.Config
HResult=-2146232062
Line=15
Message='connectionStrings'-element, der ikke er genkendt. (C:\Users\Anders\documents\visual studio 2015\Projects\ShopEntity\ShopEntity\bin\Debug\ShopEntity.vshost.exe.Config line 15)
Source=System.Configuration
StackTrace:
ved System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
ved System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
ved System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
ved System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
ved System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
ved System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
ved System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
ved System.Configuration.ConfigurationManager.GetSection(String sectionName)
ved System.Data.Entity.Internal.AppConfig..ctor()
ved System.Data.Entity.Internal.AppConfig..cctor()
InnerException: