I have the following application
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
try
{
var listener = new HttpListener();
listener.TimeoutManager.RequestQueue = TimeSpan.FromSeconds(10);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
Console.ReadLine();
}
}
}
The output of the application is as follows
System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Net.HttpListenerTimeoutManager.set_RequestQueue(TimeSpan value)
at ConsoleApp2.Program.Main(String[] args) in C:\Users\a\source\repos\ConsoleApp2\ConsoleApp2\Program.cs:line 13
Unhandled exception. System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Net.HttpListenerTimeoutManager.set_RequestQueue(TimeSpan value)
at ConsoleApp2.Program.Main(String[] args) in C:\Users\a\source\repos\ConsoleApp2\ConsoleApp2\Program.cs:line 13
This was run on Debian but we get the same error on Alpine. No such error on Windows.
Is this truly not supported? If not, is it something that is managed within the OS?
Short answer is, if you want to run on Linux, don't use HttpListener. It's built on top of HTTP.sys which is a Windows specific kernel mode listener
There is an ongoing discussion related to deprecating HttpListener and it points to using Kestrel as an alternative
Related
Why C#8 Default implementations of interface members will report an error?
public interface Logger
{
void Info(string message);
void Error(string message);
// C#8 Default implementations of interface
void Warn(string message)
{
// "interface method cannot declare a body" error message
}
}
and
.NET Core 3.0 is configured as shown in the screenshot.
This is a Resharper/Rider bug: https://youtrack.jetbrains.com/issue/RSRP-474628
The feature is sound and your setup is correct. Also the following works for me, i can compile and run the following in .Net Core 3
class Program
{
interface IDefaultInterfaceMethod
{
void DefaultMethod()
{
Console.WriteLine("I am a default method in the interface!");
}
}
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
Note though, i get your error in the IDE!! yet there was no error in the error window. However, it still compiles and runs so it is not C#8.. Seeing this is a sure-sign something else is the issue
In Short, this is likely a Resharper problem, when i suspended Resharper the false positive went away
The project is a chat program with a multi-threaded server to handle multiple clients. The code below is server-side for the thread that begins once a client connects. The ConnectionHandler takes a connected clients socket and 'ID'.
The static "broadcast" method called in run() is not relevant to the question as well as both functions in the finally clause.
I have been working on the project on both a Windows 10 desktop, and an XPS laptop running Ubuntu 18.04.
Client disconnection is handled once the IOException is caught in the run() method. This works as designed on Windows, however for Ubuntu that is not the case. When exiting the GUI client it seems like only the exception is caught on Windows and doesn't happen on Ubuntu. Thus rendering the server non-working for Linux and working perfectly on Windows.
Is this not a well practiced method to handle a client disconnection in general? Or is it something else that I need to change in order for this to work on Linux? I have no idea what to do because I'm not sure if it's an error in my code or it's just the way Linux handles Java versus Windows?
Any help or tips is appreciated. Thanks in advance.
class ConnectionHandler implements Runnable
{
//Begin declarations for new client thread
int clientId;
Socket connection;
BufferedReader reader;
BufferedWriter writer;
String message;
//end declarations for new client thread
public ConnectionHandler(int clientId, Socket connection)
{
this.clientId = clientId;
this.connection = connection;
}
#Override
public void run()
{
try
{
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
}
catch (IOException e)
{
e.printStackTrace();
}
try
{
while (true)
{
message = reader.readLine();
if (message != null)
{
System.out.println("Message from " + message);
CrosstalkServer.broadcast(message);
}
}
}
catch (IOException e)
{
System.out.println("Client has disconnected. Recycling client ID: " + clientId);
}
finally
{
//Close the reader, writer, and socket.
terminateClient();
//Client has disconnected, handle client count and recycle client ID
CrosstalkServer.recycleClientId(this);
}
}
Edit: I tested the program on Windows 10, Windows 7, and Ubuntu 18.04. After some testing, it is the client side causing the problem. I ran the server on my Ubuntu laptop, and tested a Windows 7 client along with a Windows 10 clients. The Windows 7 client did not cause an IOException to be thrown, while Windows 10 did. Ubuntu client-side does not cause the IOException either.. What is a better way to determine a client disconnection? Start a thread to monitor by attempting to constantly write to each client in my client arraylist?
We are using spring-cloud-starter-hystrix with spring-cloud-starter-archaius where we are unable to stop the poolingconfigurationSource thread of archaius once the war is un-deployed. But spring-cloud-starter-archaius is working fine without hystrix and thread is stopped once war is un-deployed.
Try reseting Hystrix before the Spring Application shuts down
#EnableCircuitBreaker
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
#PreDestroy
public void cleanUp() {
Hystrix.reset();
}
}
**Issue resolved permanently.**
**There are 2 approach :**
1) Create ContextListener in Servlet and in destroy method , copy below code.
2) If you are using Histrix + Spring Boot + Archaius then on main spring application java file , copy below code in method annonated with #PreDestory annotations.
**Solution :**
try {
if (ConfigurationManager.getConfigInstance() instanceof DynamicConfiguration) {
DynamicConfiguration config = (DynamicConfiguration) ConfigurationManager.getConfigInstance();
config.stopLoading();
} else if (ConfigurationManager.getConfigInstance() instanceof ConcurrentCompositeConfiguration) {
ConcurrentCompositeConfiguration configInst = (ConcurrentCompositeConfiguration) ConfigurationManager
.getConfigInstance();
List<AbstractConfiguration> configs = configInst.getConfigurations();
if (configs != null) {
for (AbstractConfiguration config : configs) {
if (config instanceof DynamicConfiguration) {
((DynamicConfiguration) config).stopLoading();
break;
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
both Davin and Ashish Patel are right: there are multiple leaks caused by Spring cloud.
The presence of a some threads named pollingConfigurationSource can be partially fixed by the solution proposed by Davin. You also need to make sure not to have any file named config.properties in your classpath because com.netflix.config.sources.URLConfigurationSource (look in the source for all the cases) will search for common patsh and start an exectutor thread. there are multiple path in the code that causes an executorservice on thread "pollingConfigurationSource" to be started (an not be always stopped). In my case removing "config.properties" solved this leak
The other leak I'm aware of is caused by Hystrix/RjJava. Instead of calling Histrix.reset call rx.schedulers.Schedulers.shutdown(); this will force threads "RxIoScheduler-" to exit.
In c# .Net 4.0 I am attempting to automate WordPerfect.
To do this I add a reference in my project to the wpwin14.tlb file that lives in the WordPerfect program folder.
That has the effect of creating the COM interfaces within my project.
Next I should be able to write code that instantiates a WordPerfect.PerfectScript object that I can use to automate WordPerfect.
However, when I try to instantiate the WordPerfect.PerfectScript object c# throws the error:
"Unable to cast COM object of type 'System.__ComObject' to interface
type 'WordPerfect.PerfectScript'. This operation failed because the
QueryInterface call on the COM component for the interface with IID
'{C0E20006-0004-1000-0001-C0E1C0E1C0E1}' failed due to the following
error: The RPC server is unavailable. (Exception from HRESULT:
0x800706BA)."
The thing to zero in on in that message (I do believe) is that the RPC server is unavailable.
I have tried this with WordPerfect running in the background and without. And I have gone to my services and made sure that RPC services were all running and restarting everything.
Is it possible that I am getting blocked by a firewall? That is my only faintest guess
I just wrap it as an OLE call and clean up my COM object with FinalReleaseComObject.
Here's a simple wrapper class I've been using to open Wp docs and convert them to pdf. It cleans up nicely in our automated process:
public class WpInterop : IDisposable
{
private bool _disposed;
private PerfectScript _perfectScript;
public PerfectScript PerfectScript
{
get
{
if (_perfectScript == null)
{
Type psType = Type.GetTypeFromProgID("WordPerfect.PerfectScript");
_perfectScript = Activator.CreateInstance(psType) as PerfectScript;
}
return _perfectScript;
}
}
protected void Dispose(bool disposing)
{
if (disposing)
{
Marshal.FinalReleaseComObject(_perfectScript);
}
_disposed = true;
}
public void Dispose()
{
if (_disposed == false)
{
GC.SuppressFinalize(this);
Dispose(true);
}
}
}
Make sure your version of WordPerfect has all of the service packs and hot fixes installed. This step has fixed many random-sounding issues for me over the years. Looks like you are using X4, which is no longer supported by Corel, which means that the updates are no longer on its web site. You should be running version 14.0.0.756 (SP2 plus 2 hotfixes).
I just uninstalled WPX4 and re-installed it, without the service pack updates. Running this code gave the exact error as the OP:
using System.Runtime.InteropServices;
using WordPerfect;
namespace WP14TLB
{
class Program
{
static void Main(string[] args)
{
PerfectScript ps = new PerfectScript();
ps.WPActivate();
ps.KeyType("Hello WP World!");
Marshal.ReleaseComObject(ps);
ps = null;
}
}
}
Installing the service packs "magically" fixed the problem.
BTW, for future reference, you can also try the WPUniverse forums. There are quite a few WP experts who regularly answer difficult questions.
There is also a link to the X4 updates here:
I developed a desktop application, it's almost done but still contains some bugs which I'm eliminating.
I use a general [try...catch] block wrapped around my application
[STAThread]
static void Main()
{
try
{
program = new Program();
// ...
}
catch (Exception x)
{
// ...
MessageBox.Show(
message,
Resources.MESSAGEBOX_ERROR_CRASH_Caption,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
my Program class constructor being:
public Program()
{
// [...]
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// [...]
frmLogon = new Logon();
Application.Run(frmLogon);
}
to ensure that any unhandled exception will bubble all the way up the stack and is at least responded to with some communicative message box.
It works fine when I run the application under Visual Studio (debug mode), but when I deployed it and installed on my PC, it doesn't - that's what I get when the bug (which I've already identified, by the way) causes it to read from a null array
Why? It baffles me really. Why was it "unhandled"? It was my understanding that try...catch should work regardless of whether it's release or debug mode, otherwise what would be the point.
This is kind of old, but if you still need a solution, you need to handle some events, enclosing the entire thing in a try catch won't work. Do something like this:
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
AppDomain.CurrentDomain.UnhandledException += ProcessAppException;
Application.ThreadException += ProcessThrException;
Application.Run(new MainForm());
}
private static void ProcessAppException(object sender, UnhandledExceptionEventArgs e)
{
XtraFunctions.LogException((Exception)e.ExceptionObject);
throw (Exception)e.ExceptionObject; //MessageBox in your case.
}
private static void ProcessThrException(object sender, ThreadExceptionEventArgs e)
{
XtraFunctions.LogException(e.Exception);
throw e.Exception; //MessageBox in your case.
}
When an exception isn't caught, it will go through one of those before displaying the exception dialog. So you have the option to override it and display a nice message of your choice.