【发布时间】:2019-11-13 20:47:40
【问题描述】:
我有一个项目被设置为带有 SharpShell 库的 shell 扩展。当我使用regasm 工具(打开/codebase 标志)注册它时,它一直有效,直到我需要通过EntityNetwork 使用数据库。我收到此错误:
找不到名为“EntitiesName”的连接字符串 应用程序配置文件。
当然我在config 文件中有正确的ConnectionString。看来整个 config 文件根本没有被读取。
于是我找到了一种hack解决方案,我把这个放在构造函数中:
Dim assemblyLoc As String = [GetType].Assembly.Location
Dim configName As String = assemblyLoc + ".config"
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configName)
似乎已读取某些内容,但并非所有内容,我收到一个新错误:
System.TypeInitializationException:“System.Data.Entity.Internal.AppConfig”的类型初始化程序引发了异常。 ---> System.Configuration.ConfigurationErrorsException:为 entityFramework 创建配置节处理程序时出错:无法加载文件或程序集“EntityFramework,Version=6.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”或其依赖项之一。系统找不到指定的文件。
如何使用配置文件或如何使用EntityFramework 进行这种设置?
这就是我的config 文件的样子:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="EntitiesName" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="***"" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
我怀疑我可能需要使用Code-based configuration。如果是这种情况,我会很感激vb.net 指向那个方向的指针。
【问题讨论】:
标签: .net dll app-config regasm sharpshell