使用 NUnit 测试时出现 MySQL 异常。我已经在两台机器上安装了 MySQL Connector 6.6.5,但是其中一台系统在使用 Nunit 运行相同的测试时出现以下错误。而在其他系统中它工作成功。
at MySql.Data.MySqlClient.MySqlClientFactory.get_MySqlDbProviderServicesInstance()
at MySql.Data.MySqlClient.MySqlClientFactory.System.IServiceProvider.GetService(Type serviceType)
at System.Data.Common.DbProviderServices.GetProviderServices(DbProviderFactory factory)
at System.Data.Metadata.Edm.StoreItemCollection.Loader.InitializeProviderManifest(Action`3 addError)
at System.Data.EntityModel.SchemaObjectModel.Schema.HandleAttribute(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.SchemaElement.ParseAttribute(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.SchemaElement.Parse(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.Schema.HandleTopLevelSchemaElement(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.Schema.InternalParse(XmlReader sourceReader, String sourceLocation)
at System.Data.EntityModel.SchemaObjectModel.Schema.Parse(XmlReader sourceReader, String sourceLocation)
at System.Data.EntityModel.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection)
at System.Data.Metadata.Edm.StoreItemCollection.Loader.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths)
at System.Data.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerManifestToken, Memoizer`2& cachedCTypeFunction)
at System.Data.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths)
at System.Data.Metadata.Edm.MetadataCache.StoreMetadataEntry.LoadStoreCollection(EdmItemCollection edmItemCollection, MetadataArtifactLoader loader)
at System.Data.Metadata.Edm.MetadataCache.LoadItemCollection[T](IItemCollectionLoader`1 itemCollectionLoader, T entry)
at System.Data.Metadata.Edm.MetadataCache.GetOrCreateStoreAndMappingItemCollections(String cacheKey, MetadataArtifactLoader loader, EdmItemCollection edmItemCollection, Object& entryToken)
at System.Data.EntityClient.EntityConnection.LoadStoreItemCollections(MetadataWorkspace workspace, DbConnection storeConnection, DbProviderFactory factory, DbConnectionOptions connectionOptions, EdmItemCollection edmItemCollection, MetadataArtifactLoader artifactLoader)
at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections)
at System.Data.Objects.ObjectContext.EnsureMetadata()
at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery.ToTraceString()
at FreeLance.Data.Framework.EntityFramework.Repository`1.GetSingle(Expression`1 where, Expression`1[] include) in D:\CMS_Org\SonnetCMS\FreeLance\Framework\Data\FreeLance.Data.Framework\EntityFramework\Repository.cs:line 114
at FreeLance.Business.PageBC.GetUserName(Int32 userId) in D:\CMS_Org\SonnetCMS\FreeLance\Business\FreeLance.Business\Admin\PageBC.cs:line 179
at FreeLance.Services.PageService.GetUserName(Int32 userId) in D:\CMS_Org\SonnetCMS\FreeLance\Services\FreeLance.Services\PageService.cs:line 42
at TestCMS.Class1.Test()
编辑:
函数我收到错误的地方:
public virtual TEntity GetSingle(Expression<Func<TEntity, bool>> where, params Expression<Func<TEntity, object>>[] include)
{
IQueryable<TEntity> query = this.dbSet.Where(where);
if (include != null)
{
query = this.dbSet.Include<TEntity>(include).Where(where);
}
Debug.Write(query.ToString());
return query.SingleOrDefault<TEntity>();
}
异常(exception):
来源:MySql.Data
错误:未将对象引用设置为对象的实例。
声明类型:{Name = "MySqlClientFactory"FullName = "MySql.Data.MySqlClient.MySqlClientFactory"}
程序集:{MySql.Data,Version=6.6.5.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d}
在函数 this.dbset 中有 NullReferenceException,而在正常工作的系统中我有 this.dbset,
"{SELECT
`Extent1`.`UserID`,
`Extent1`.`UserGUID`,
`Extent1`.`UserCode`,
`Extent1`.`UserAuthentication`,
`Extent1`.`UserType`,
`Extent1`.`UserPassword`,
`Extent1`.`UserPasswordSalt`,
`Extent1`.`UserFirstName`,
`Extent1`.`UserMiddleName`,
`Extent1`.`UserLastName`,
`Extent1`.`UserCompanyName`,
`Extent1`.`IsUserNeedToResetPasswordNextLogin`,
`Extent1`.`UserPasswordExpiryDate`,
`Extent1`.`UserLoginFailAttempts`,
`Extent1`.`UserLoginFailDate`,
`Extent1`.`UserPasswordResetDate`,
`Extent1`.`UserPasswordResetBy`,
`Extent1`.`UserLastLoginDate`,
`Extent1`.`IsUserLoginLocked`,
`Extent1`.`UserLoginLockedDate`,
`Extent1`.`IsForUserSecurityQuestionRequired`,
`Extent1`.`Remarks`,
`Extent1`.`IsActive`,
`Extent1`.`CreatedBy`,
`Extent1`.`CreatedDate`,
`Extent1`.`UpdatedBy`,
`Extent1`.`UpdatedDate`
FROM `isuser` AS `Extent1`}"
最佳答案
在 Web.Config 中,我们将数据库提供程序工厂、MySQL 连接器版本从 6.6.5 更改为 6.6.6。这解决了我们的问题。
关于c# - Nunit MySQL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25080043/