-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'Assembly with type "....ActionService" is not loaded' #7
Comments
PS. Starting Client and Server inside single process is working. |
Hello. You need to load assembly: await factory.LoadAssemblyAsync(typeof(ActionService).Assembly.Location).ConfigureAwait(false); There is example app: But I do not recommend using this library, I see the development of IPC in explicit code generation instead of IL code generation like here. |
Thank you for response. I ended up using your wrapper for Named pipes (PipeServer and PipeClient) 👍 |
Yes, this is the best option for now. |
I'm actively developing a SourceGenerator that generates client/server code based on a C# interface. I would be glad if you take a look at it (if you are still interested) and provide any feedback - https://github.com/HavenDV/H.Ipc |
I have built solution around your Pipes wrapper, and everything seems to be working good. It is kind of private project, paused for now, and not sure what will happen... However, since things are good in this project, it is unlikely that i will change communication method in the future. Best regards |
I want to clarify that this is just a SourceGenerator that removes the boilerplate code. You will still continue to use H.Pipes. Here is an example of what is generated based on this code: namespace H.Ipc.Apps.Wpf;
public interface IActionService
{
void ShowTrayIcon();
void HideTrayIcon();
void SendText(string text);
}
[H.IpcGenerators.IpcClient]
public partial class ActionServiceClient : IActionService
{
}
[H.IpcGenerators.IpcServer]
public partial class ActionService : IActionService
{
public void ShowTrayIcon()
{
}
public void HideTrayIcon()
{
}
public void SendText(string text)
{
}
} will produce: //HintName: ActionServiceClient.generated.cs
#nullable enable
namespace H.Ipc.Apps.Wpf
{
public partial class ActionServiceClient
{
#region Properties
private global::H.Pipes.IPipeConnection<string>? Connection { get; set; }
#endregion
#region Events
public event global::System.EventHandler<global::System.Exception>? ExceptionOccurred;
private void OnExceptionOccurred(global::System.Exception exception)
{
ExceptionOccurred?.Invoke(this, exception);
}
#endregion
public void Initialize(global::H.Pipes.IPipeConnection<string> connection)
{
Connection = connection ?? throw new global::System.ArgumentNullException(nameof(connection));
}
public async void ShowTrayIcon()
{
try
{
await WriteAsync(new ShowTrayIconMethod()).ConfigureAwait(false);
}
catch (global::System.Exception exception)
{
OnExceptionOccurred(exception);
}
}
public async void HideTrayIcon()
{
try
{
await WriteAsync(new HideTrayIconMethod()).ConfigureAwait(false);
}
catch (global::System.Exception exception)
{
OnExceptionOccurred(exception);
}
}
public async void SendText(string text)
{
try
{
await WriteAsync(new SendTextMethod(text)).ConfigureAwait(false);
}
catch (global::System.Exception exception)
{
OnExceptionOccurred(exception);
}
}
private async global::System.Threading.Tasks.Task WriteAsync<T>(
T method,
global::System.Threading.CancellationToken cancellationToken = default)
where T : global::H.IpcGenerators.RpcRequest
{
if (Connection == null)
{
throw new global::System.InvalidOperationException("You need to call Initialize() first.");
}
var json = global::System.Text.Json.JsonSerializer.Serialize(method);
await Connection.WriteAsync(json, cancellationToken).ConfigureAwait(false);
}
}
} //HintName: ActionService.generated.cs
#nullable enable
namespace H.Ipc.Apps.Wpf
{
public partial class ActionService
{
#region Events
public event global::System.EventHandler<global::System.Exception>? ExceptionOccurred;
private void OnExceptionOccurred(global::System.Exception exception)
{
ExceptionOccurred?.Invoke(this, exception);
}
#endregion
public void Initialize(global::H.Pipes.IPipeConnection<string> connection)
{
connection = connection ?? throw new global::System.ArgumentNullException(nameof(connection));
connection.MessageReceived += (_, args) =>
{
try
{
var json = args.Message ?? throw new global::System.InvalidOperationException("Message is null.");
var request = Deserialize<global::H.IpcGenerators.RpcRequest>(json);
if (request.Type == global::H.IpcGenerators.RpcRequestType.RunMethod)
{
var method = Deserialize<global::H.IpcGenerators.RunMethodRequest>(json);
switch (method.Name)
{
case nameof(ShowTrayIcon):
{
var arguments = Deserialize<ShowTrayIconMethod>(json);
ShowTrayIcon();
break;
}
case nameof(HideTrayIcon):
{
var arguments = Deserialize<HideTrayIconMethod>(json);
HideTrayIcon();
break;
}
case nameof(SendText):
{
var arguments = Deserialize<SendTextMethod>(json);
SendText(arguments.Text);
break;
}
}
}
}
catch (global::System.Exception exception)
{
OnExceptionOccurred(exception);
}
};
}
private static T Deserialize<T>(string json)
{
return
global::System.Text.Json.JsonSerializer.Deserialize<T>(json) ??
throw new global::System.ArgumentException($@"Returned null when trying to deserialize to {typeof(T)}.
json:
{json}");
}
}
} //HintName: IActionService_Requests.generated.cs
#nullable enable
namespace H.Ipc.Apps.Wpf
{
public class ShowTrayIconMethod : global::H.IpcGenerators.RunMethodRequest
{
public ShowTrayIconMethod()
{
Name = "ShowTrayIcon";
}
}
public class HideTrayIconMethod : global::H.IpcGenerators.RunMethodRequest
{
public HideTrayIconMethod()
{
Name = "HideTrayIcon";
}
}
public class SendTextMethod : global::H.IpcGenerators.RunMethodRequest
{
public string Text { get; set; }
public SendTextMethod(string text)
{
Name = "SendText";
Text = text ?? throw new global::System.ArgumentNullException(nameof(text));
}
}
} |
Aha, i get it now. This looks really promising, will definitely give it a try. PS. Here is my use-case, maybe it will benefit you. |
Hello, i have tried to create sample solution, but it crashes on this line...
var service = await factory.CreateInstanceAsync<ActionService, IActionService>();
And here is Project structure. Client and Server reference Shared project, and both are started as independent processes.
![image](https://user-images.githubusercontent.com/6333352/153709906-326211a5-2ae5-4f80-9dd9-a4fae8dd605f.png)
Am i missing something?
Thanks
The text was updated successfully, but these errors were encountered: