相关疑难解决方法(0)

AppDomain和MarshalByRefObject的生命周期:如何避免RemotingException?

当MarshalByRef对象从AppDomain(1)传递到另一个(2)时,如果你在第二个AppDomain(2)中调用方法之前等待6分钟,你将得到一个RemotingException:

System.Runtime.Remoting.RemotingException:对象[...]已断开连接或在服务器上不存在.

有关此问题的一些文档:

如果我错了,请纠正我:如果InitializeLifetimeService返回null,那么当AppDomain 2被卸载时,该对象只能在AppDomain 1中收集,即使收集了代理?

有没有办法禁用生命周期并保持代理(在AppDomain 2中)和对象(在AppDomain1中)保持活动状态,直到代理完成为止?也许与ISponsor ......?

.net c# remoting appdomain object-lifetime

56
推荐指数
4
解决办法
3万
查看次数

EF代码第一次迁移错误"对象已断开连接或在服务器上不存在"

我在SQL Server 2008上使用Entity Framework 6.1.1,我有一个长期运行的代码第一次迁移(大约20分钟).它结束然后给出以下错误.

System.Runtime.Remoting.RemotingException: Object '/f10901d8_94fe_4db4_bb9d_51cd19292b01/bq6vk4vkuz5tkri2x8nwhsln_106.rem' has been disconnected or does not exist at the server.
   at System.Data.Entity.Migrations.Design.ToolingFacade.ToolLogger.Verbose(String sql)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbTransaction transaction, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection)
   at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClass30.<ExecuteStatements>b__2e()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements, DbTransaction existingTransaction)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)
   at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at …
Run Code Online (Sandbox Code Playgroud)

entity-framework ef-migrations

12
推荐指数
3
解决办法
2784
查看次数

如何在两个.NET AppDomains之间传递未知类型?

我有一个.NET应用程序,其中单独的AppDomains中的程序集必须共享按值传递的序列化对象.

两个程序集都引用一个共享程序集,该程序集定义服务器类的基类,并定义将在域之间传递的entiy类型的基类:

public abstract class ServerBase : MarshalByRefObject
{
    public abstract EntityBase GetEntity();
}

[Serializable]
public abstract class EntityBase
{
}
Run Code Online (Sandbox Code Playgroud)

服务器程序集定义服务器类和实体类型的具体实现:

public class Server : ServerBase
{
    public override EntityBase GetEntity()
    {
        return new EntityItem();
    }
}

[Serializable]
public class EntityItem : EntityBase
{
}
Run Code Online (Sandbox Code Playgroud)

客户端程序集创建AppDomain托管服务器程序集的位置,并使用服务器类的实例来请求实体类型的具体实例:

class Program
{
    static void Main()
    {
        var domain = AppDomain.CreateDomain("Server");

        var server = (ServerBase)Activator.CreateInstanceFrom(
            domain,
            @"..\..\..\Server\bin\Debug\Server.dll",
            "Server.Server").Unwrap();

        var entity = server.GetEntity();
    }
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,这种方法失败了,SerializationException因为客户端程序集并不直接了解返回的具体类型.

我已经读过使用二进制序列化时.NET Remoting支持未知类型,但我不确定这是否适用于我的设置或如何配置它.

或者,是否有任何其他方法可以将未知的具体类型从服务器传递到客户端,因为客户端只需要通过其已知的基类接口访问它.

谢谢你的建议, …

.net remoting appdomain

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

ISponsor 和 ILease 接口如何工作?

我创建了一个继承自MarshalByRefObject和的对象ISponsor。在我的实现中,ISponsor我只返回一个时间跨度来指示我希望对象更新多长时间。

当我调用InitializeLifetimeService()以获取ILease要传递到我的ISponsor对象中的引用时,它似乎从未在我见过的示例中使用

ISponsor似乎只是在没有实际使用ILease参考的情况下返回一个 TimeSpan 。但我敢肯定,由于涉及远程处理,这里还有更多事情要做。

如何工作ISponsorILease工作,特别是在对象生命周期更新方面?

.net c# object-lifetime .net-remoting

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