gpt4 book ai didi

android - Realm - System.TypeInitializationException : The type initializer for 'Realms.Realm' threw an exception. ---> System.DllNotFoundException

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:29:24 26 4
gpt4 key购买 nike

这是 Realm 的异常(exception)

{System.TypeInitializationException: The type initializer for 'Realms.Realm' threw an exception. ---> 
System.DllNotFoundException: realm-wrappers
at (wrapper managed-to-native) Realms.NativeCommon:register_notify_realm_changed
(Realms.NativeCommon/NotifyRealmCallback)
at Realms.Realm..cctor () [0x0004f] in <f0097c463d884e09ba2bde58b530c6d7>:0

--- End of inner exception stack trace ---
at DAL.t_MobileUser..ctor () [0x0001e] in
D:\visual studio 2015\Projects\RBankCI\DAL\t_MobileUser.cs:17
at BLL.BLL_MobileUser.m05_selectSpecific (System.Int32 id) [0x00013] in
D:\visual studio 2015\Projects\RBankCI\BLL\BLL_MobileUser.cs:34
at RBankCI.Activity_PDRN.m7_btnSaveClick () [0x00008] in
D:\visual studio 2015\Projects\RBankCI\RBankCI\Activities\Activity_PDRN.cs:96 }

当我调用 Realm realm = Realm.GetInstance(config);我收到一个位于顶部的错误。我从 nugget packager 下载了这个 Realm ,所以我不知道它说的是什么 DllNotFoundException

我尝试下载这些版本,但异常结果相同:2.1.0、0.82.1 和 0.80(与我之前的应用程序相同,无一异常(exception))

这是我的示例代码。

    private Realm realm;

public void insert(object obj)
{
try
{
realm = Realm.GetInstance(DAL_DBAccessVariable.config); //Error occur here
ENT_MobileUser entity = (ENT_MobileUser)obj;
using (var transaction = realm.BeginWrite())
{
DAL_MobileUserEntity dbTable = realm.CreateObject<DAL_MobileUserEntity>();
dbTable.id = entity.id;
dbTable.firstName = entity.firstName;
dbTable.middleName = entity.middleName;
dbTable.lastName = entity.lastName;
dbTable.userID = entity.userID;
dbTable.userPinCode = entity.userPinCode;
dbTable.licenseKey = entity.licenseKey;
dbTable.licenseExpiry = entity.licenseExpiry;

transaction.Commit();
}
}
catch (Exception e)
{ throw; }
}

这是 DAL_DBAccessVariables

using Realms;
using System;
using System.IO;

namespace DAL
{
public class DAL_DBAccessVariable
{
private const string databaseName = "name.realm";
public static readonly string dbPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), databaseName);
public static readonly RealmConfiguration config = new RealmConfiguration(dbPath);
}
}

如果有帮助,请提供其他信息。我将我的 xamarin 更新到最新版本,visual studio 2015 professional。

最佳答案

我在这里找到了答案 - https://github.com/realm/realm-dotnet/issues/1354提供截图。

enter image description here

真正的问题是当您实现一个业务层并有一个 DLL 项目来存储您的数据库连接时。如果是这样,我们不仅要将 Realm 包含在 DLL 或 DAL 中,还要包含在我们的主项目中,它可以 100% 解决问题

关于android - Realm - System.TypeInitializationException : The type initializer for 'Realms.Realm' threw an exception. ---> System.DllNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47827941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com