Skip to content

Commit

Permalink
fixed unloadedappdomain exception bug
Browse files Browse the repository at this point in the history
  • Loading branch information
derabbink committed Aug 12, 2013
1 parent 0cb733b commit 3978f1c
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<PropertyGroup>
<PostBuildEvent>copy ..\..\DistrEx.Communication.Service.Test.dll.config</PostBuildEvent>
<PostBuildEvent>copy ..\..\..\DistrEx.Communication.Service.Test.dll.config</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
2 changes: 1 addition & 1 deletion DistrEx.Coordinator.Test/DistrEx.Coordinator.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<PropertyGroup>
<PostBuildEvent>copy ..\..\DistrEx.Coordinator.Test.dll.config .\</PostBuildEvent>
<PostBuildEvent>copy ..\..\..\DistrEx.Coordinator.Test.dll.config .\</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
</system.serviceModel>

<appSettings>
<add key="DistrEx.Coordinator.Test.worker-exe-file" value="..\..\..\DistrEx.Worker.Host\bin\Debug\DistrEx.Worker.Host.exe" />
<add key="DistrEx.Coordinator.Test.worker-exe-file" value="..\..\..\..\DistrEx.Worker.Host\bin\Debug\DistrEx.Worker.Host.exe" />
</appSettings>
</configuration>
7 changes: 6 additions & 1 deletion DistrEx.Coordinator.Test/TargetSpecs/OnWorkerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,15 @@ public void TimeoutOnWorker()
var result = Interface.Coordinator.Do(_onWorker.Do(_haltingIdentity), _argumentIdentity).ResultValue;
}

[TearDown]
public void Teardown()
{
_onWorker.ClearEverything();
}

[TestFixtureTearDown]
public void TeardownFixture()
{
_onWorker.ClearEverything();
ProcessHelper.Stop(_workerProcess);
}
}
Expand Down
2 changes: 1 addition & 1 deletion DistrEx.Plugin.Test/DistrEx.Plugin.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<PropertyGroup>
<PostBuildEvent>copy ..\..\DistrEx.Plugin.Test.dll.config .\</PostBuildEvent>
<PostBuildEvent>copy ..\..\..\DistrEx.Plugin.Test.dll.config .\</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
18 changes: 18 additions & 0 deletions DistrEx.Plugin/ExecutionException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.Serialization;
using DistrEx.Common.Serialization;

namespace DistrEx.Plugin
{
Expand All @@ -21,6 +22,23 @@ protected ExecutionException(SerializationInfo info, StreamingContext context)
SerializedInnerException = info.GetValue("SerializedInnerException", typeof(string)) as string;
}

public static ExecutionException FromException(Exception e)
{
string serializedExTypeName;
string serializedEx;
try
{
serializedEx = Serializer.Serialize(e);
serializedExTypeName = e.GetType().FullName;
}
catch
{
serializedEx = null;
serializedExTypeName = typeof(Exception).FullName;
}
return new ExecutionException(serializedExTypeName, serializedEx);
}

public string InnerExceptionTypeName
{
get;
Expand Down
21 changes: 2 additions & 19 deletions DistrEx.Plugin/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal SerializedResult Execute(ExecutorCallback callback, string assemblyQual
}
catch (Exception e)
{
throw HandleException(e);
throw ExecutionException.FromException(e);
}
}

Expand Down Expand Up @@ -86,7 +86,7 @@ internal SerializedResult ExecuteTwoStep(ExecutorCallback callback, ExecutorCall
}
catch (Exception e)
{
throw HandleException(e);
throw ExecutionException.FromException(e);
}
}

Expand All @@ -113,23 +113,6 @@ private SerializedResult ExecuteWrapped(MethodInfo func, ExecutorCallback callba
}
}

private ExecutionException HandleException(Exception e)
{
string serializedExTypeName;
string serializedEx;
try
{
serializedEx = Serializer.Serialize(e);
serializedExTypeName = e.GetType().FullName;
}
catch
{
serializedEx = null;
serializedExTypeName = typeof(Exception).FullName;
}
return new ExecutionException(serializedExTypeName, serializedEx);
}

internal void Cancel()
{
_cancellationTokenSource.Cancel();
Expand Down
10 changes: 9 additions & 1 deletion DistrEx.Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,15 @@ public SerializedResult Execute(string assemblyQualifiedName, string methodName,
cancellationToken.Register(executor.Cancel);
var callback = new ExecutorCallback(reportProgress);

return executor.Execute(callback, assemblyQualifiedName, methodName, argumentTypeName, serializedArgument);
try
{
return executor.Execute(callback, assemblyQualifiedName, methodName, argumentTypeName,
serializedArgument);
}
catch (AppDomainUnloadedException e)
{
throw ExecutionException.FromException(e);
}
}

public SerializedResult ExecuteTwoStep(string assemblyQualifiedName, string methodName, CancellationToken cancellationToken, Action reportProgress,
Expand Down
27 changes: 15 additions & 12 deletions DistrEx.Worker/Executor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
Expand Down Expand Up @@ -69,23 +70,25 @@ private void Execute(ExecuteEventArgs instruction)
Action reportProgress = () => callback.Progress(progressMsg);
try
{
SerializedResult serializedResult = _pluginManager.Execute(instruction.AssemblyQualifiedName, instruction.MethodName, cts.Token,
reportProgress, instruction.ArgumentTypeName, instruction.SerializedArgument);
SerializedResult serializedResult = _pluginManager.Execute(instruction.AssemblyQualifiedName,
instruction.MethodName, cts.Token,
reportProgress, instruction.ArgumentTypeName,
instruction.SerializedArgument);
callback.Complete(new Result
{
OperationId = operationId,
ResultTypeName = serializedResult.TypeName,
SerializedResult = serializedResult.Value
});
{
OperationId = operationId,
ResultTypeName = serializedResult.TypeName,
SerializedResult = serializedResult.Value
});
}
catch (ExecutionException e)
{
var msg = new Error
{
OperationId = operationId,
ExceptionTypeName = e.InnerExceptionTypeName,
SerializedException = e.SerializedInnerException
};
{
OperationId = operationId,
ExceptionTypeName = e.InnerExceptionTypeName,
SerializedException = e.SerializedInnerException
};
callback.Error(msg);
}
finally
Expand Down
Loading

0 comments on commit 3978f1c

Please sign in to comment.