小编use*_*261的帖子

将证书添加到 x509Store 不会执行任何操作 C#

我正在尝试添加证书,但 Add 功能似乎没有做任何事情。

我有两个证书。我可以通过右键单击并保存到个人“testStore”商店来手动添加,但是当我尝试以编程方式添加它们时,它们不会被保存。我什至只添加了其中一个,X509Store 对象就如预期的那样包含它,但是当我调用 .Add(cert) 时,那里没有保存任何内容。

//I've already added 1 cert manually
X509Certificate2 cert2 = new X509Certificate2(@"C:\temp\Cert2.cer");
X509Store store = new X509Store("testStore", StoreLocation.CurrentUser);
store.Open(OpenFlags.MaxAllowed);

//here store.Certificates has the one Certificate I added manually as expected.

store.Certificates.Add(cert2);

//here store.Certificates still only has the first certificate, cert2 still isn't there..

store.Close();
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

编辑我也尝试过使用 StorePermission(如下所示)并尝试模拟管理员帐户,但这些也没有帮助

StorePermission sp = new StorePermission( PermissionState.Unrestricted);
sp.Flags = StorePermissionFlags.AllFlags;
sp.Assert();
Run Code Online (Sandbox Code Playgroud)

c# certificate-store x509certificate x509

5
推荐指数
2
解决办法
3524
查看次数

EF随机查看错误的属性类型

我们首先使用EF代码和EF 6.1.3以及SimpleInjector 3.1.0,我们随机获得类似的异常:

"位置"上的"IsDeleted"属性无法设置为"System.Int32"值.必须将此属性设置为类型为"System.Boolean"的非null值.
System.Data.Entity.Cart.Eternal中的System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader,Int32 ordinal)
处于System.Data.Materialization.Shaper.GetPropertyValueWithErrorHandling [TProperty] System.Data.Entity.Core上的System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) 中的
lambda_method(Closure,Shaper)
处的(Int32 ordinal,String propertyName,String typeName)
.
System.Linq.Enumerable.FirstOrDefault [TSource]中的Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()(IEnumerable`1 source)

在这种情况下,Location表的IsDeleted列是bit/not null.而Location实体上的Property绝对是一个不可为空的布尔值.我已经检查了我们的git存储库中的实体的整个历史记录,这个属性从来都不是布尔值,并且服务器上的当前dll是正确的,所以它不是问题是由错误的代码引起的/ DLL.

真正奇怪的是,大部分时间我们的网站工作得很好,我希望每次都会发生异常.更奇怪的是,我们已经看到同样类型的错误发生在其他3个实体上(也似乎是随机的).在每种情况下,它都是不同的属性和数据类型.例如:

'SysGroup'上的'Description'属性无法设置为'System.Boolean'值.您必须将此属性设置为类型为"System.Int32"的非null值.

'SysInfo'上的'SysGroupId'属性无法设置为'System.String'值.您必须将此属性设置为类型为"System.Int32"的非null值.

'BaseEntity'上的'Id'属性无法设置为'System.Guid'值.您必须将此属性设置为类型为"System.Int32"的非null值.

关于最后一个......我们从BaseEntity继承的每个实体都有一个名为'Id'的非可空int属性.我们也不在任何地方使用任何Guid.因此,如果BaseEntity确实使用了ID属性的Guid,那么每个查询都会失败.最后一个异常发生在代码导航属性时,如下所示:

var desc = SysInfoInstance.SysGroup.Description;
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Location类是基本的:

public class Location : 
    BaseEntity
{
    ...
    public virtual bool IsDeleted { get; set; }
}
public abstract class BaseEntity
{
    public virtual int Id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

c# mapping entity-framework exception

5
推荐指数
1
解决办法
690
查看次数