D
Dmitry Post
Guest
Hello,
I am trying to achieve object remoting and was working with an example but seems like once <g class="gr_ gr_160 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="160" id="160">i</g> expanded upon the example I started getting null reference exception on the object.
The full zipped source here.
// create the channel
TcpChannel channel = new TcpChannel();
// register channel
ChannelServices.RegisterChannel(channel);
// activate server object
Process process = (Process) Activator.GetObject(
typeof(Process),
"tcp://localhost:8085/Process");
// if not activated
if (process != null)
{
//process.Id = System.Diagnostics.Process.GetCurrentProcess().Id;
//Console.WriteLine($"Process name is {process.Name}");
process.Procs = "Chrome";
var processes = process.ProcessesByName;
Console.WriteLine($"Proccesses {processes.Length}");
foreach (var proc in processes)
{
Console.WriteLine(proc);
}
}
The null reference occurs when trying to get the array of string that is returned by <g class="gr_ gr_229 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" data-gr-id="229" id="229">process</g>.<g class="gr_ gr_233 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="233" id="233">ProcessesByName</g>
here is the remote class:
public class Process : MarshalByRefObject
{
public int Id;
public string Name => System.Diagnostics.Process.GetProcessById(Id).ProcessName;
public string Procs;
public string[] ProcessesByName => (from p in System.Diagnostics.Process.GetProcessesByName(Procs) select p.ProcessName) as string[];
}
Server side:
internal class Program
{
public static void Main(string[] args)
{
TcpChannel channel = new TcpChannel(8085);
// register the channel
ChannelServices.RegisterChannel(channel);
// register the service on the channel
RemotingConfiguration.ApplicationName = "Process";
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(Process),
"Process",
WellKnownObjectMode.SingleCall);
System.Console.Read();
}
}
<g class="gr_ gr_303 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="303" id="303">Client side</g> AGAIN:
internal class Program
{
public static void Main(string[] args)
{
try
{
// create the channel
TcpChannel channel = new TcpChannel();
// register channel
ChannelServices.RegisterChannel(channel);
// activate server object
Process process = (Process) Activator.GetObject(
typeof(Process),
"tcp://localhost:8085/Process");
// if not activated
if (process != null)
{
//process.Id = System.Diagnostics.Process.GetCurrentProcess().Id;
//Console.WriteLine($"Process name is {process.Name}");
process.Procs = "Chrome";
var processes = process.ProcessesByName;
Console.WriteLine($"Proccesses {processes.Length}");
foreach (var proc in processes)
{
Console.WriteLine(proc);
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
Dim Blondedude092 as SkypeUser
Continue reading...
I am trying to achieve object remoting and was working with an example but seems like once <g class="gr_ gr_160 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="160" id="160">i</g> expanded upon the example I started getting null reference exception on the object.
The full zipped source here.
// create the channel
TcpChannel channel = new TcpChannel();
// register channel
ChannelServices.RegisterChannel(channel);
// activate server object
Process process = (Process) Activator.GetObject(
typeof(Process),
"tcp://localhost:8085/Process");
// if not activated
if (process != null)
{
//process.Id = System.Diagnostics.Process.GetCurrentProcess().Id;
//Console.WriteLine($"Process name is {process.Name}");
process.Procs = "Chrome";
var processes = process.ProcessesByName;
Console.WriteLine($"Proccesses {processes.Length}");
foreach (var proc in processes)
{
Console.WriteLine(proc);
}
}
The null reference occurs when trying to get the array of string that is returned by <g class="gr_ gr_229 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" data-gr-id="229" id="229">process</g>.<g class="gr_ gr_233 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="233" id="233">ProcessesByName</g>
here is the remote class:
public class Process : MarshalByRefObject
{
public int Id;
public string Name => System.Diagnostics.Process.GetProcessById(Id).ProcessName;
public string Procs;
public string[] ProcessesByName => (from p in System.Diagnostics.Process.GetProcessesByName(Procs) select p.ProcessName) as string[];
}
Server side:
internal class Program
{
public static void Main(string[] args)
{
TcpChannel channel = new TcpChannel(8085);
// register the channel
ChannelServices.RegisterChannel(channel);
// register the service on the channel
RemotingConfiguration.ApplicationName = "Process";
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(Process),
"Process",
WellKnownObjectMode.SingleCall);
System.Console.Read();
}
}
<g class="gr_ gr_303 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="303" id="303">Client side</g> AGAIN:
internal class Program
{
public static void Main(string[] args)
{
try
{
// create the channel
TcpChannel channel = new TcpChannel();
// register channel
ChannelServices.RegisterChannel(channel);
// activate server object
Process process = (Process) Activator.GetObject(
typeof(Process),
"tcp://localhost:8085/Process");
// if not activated
if (process != null)
{
//process.Id = System.Diagnostics.Process.GetCurrentProcess().Id;
//Console.WriteLine($"Process name is {process.Name}");
process.Procs = "Chrome";
var processes = process.ProcessesByName;
Console.WriteLine($"Proccesses {processes.Length}");
foreach (var proc in processes)
{
Console.WriteLine(proc);
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
Dim Blondedude092 as SkypeUser
Continue reading...