Nunit MySQl Error
本文关键字:Error MySQl Nunit | 更新日期: 2023-09-27 18:16:09
使用NUnit测试时MySQL异常。我已经在两台机器上安装了MySQL连接器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>();
}
例外:
来源:MySql.Data
错误:Object reference not set to an instance of an object.
声明类型:{Name = "MySqlClientFactory" FullName = "MySql.Data.MySqlClient.MySqlClientFactory"}
组件:{MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d}
。dbset有NullReferenceException,而在正确工作的系统中,我有这个。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`}"
配置我们更改了数据库提供程序工厂,MySQL连接器版本从6.6.5到6.6.6。这就解决了问题。