I know this is a pretty common error, usually having to do with the onStart method of a windows service, but I can't figure out why this one isn't working.
Heres a stack trace of the error via windows event viewer:
at System.Diagnostics.EventLog.FindSourceRegistration(System.String, System.String, Boolean, Boolean)
at System.Diagnostics.EventLog.SourceExists(System.String, System.String, Boolean)
at System.Diagnostics.EventLog.SourceExists(System.String)
at ArchivalPurgeService.ArchivalPurge..ctor()
at ArchivalPurgeService.Program.Main()
and here is my program:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;
namespace ArchivalPurgeService
{
public partial class ArchivalPurge : ServiceBase
{
public ArchivalPurge()
{
try
{
InitializeComponent();
}
catch (Exception ex)
{
}
}
protected override void OnStart(string[] args)
{
try
{
timer2 = new Timer();
timer2.Enabled = true;
timer2.Interval = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["RuntimeFrequency"]);
}
catch (Exception ex)
{
}
}
private Queue<Job> QueryDBForJobs()
{
int i = 0;
return new Queue<Job>();
}
protected override void OnStop()
{
}
private void timer2_Elapsed(object sender, ElapsedEventArgs e)
{
QueryDBForJobs();
}
}
}
And I tried to run it even with everything commented out, and I'm getting the same issue. Could this just be a problem with the installation, maybe? I'm using an installer which I created almost exactly based on the MSDN how-to for creating windows services. I'm obviously also building/uninstalling/reinstalling after every code change.
Apparently the issue was with the install, not the code. When I install via installutil everything works fine.
Related
So I'm trying out SignalR, for this project I'm doing. And I don't really understand the .WithUrl paramater in HubConnectionBuilder. How do I know which URL to specify, if I want to host on localhost?
My HUB:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
namespace SignalRChat.MyHub
{
public class MyHub : Hub
{
public async Task SendMessage(string user, string message)
{
await Clients.All.SendAsync("SendMessage", user, message);
}
}
}
My program.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.AspNetCore.SignalR.Client;
using Owin;
using SignalRChat.MyHub;
using Microsoft.Owin.Hosting;
using Microsoft.Owin.Cors;
namespace SignalRChat
{
public partial class Form1 : Form
{
HubConnection connection;
public Form1()
{
InitializeComponent();
connection = new HubConnectionBuilder()
.WithUrl("http://localhost:8080/MyHub")
.Build();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private async void button1_Click(object sender, EventArgs e)
{
try
{
await connection.StartAsync();
//await connection.InvokeAsync("SendMessage", textBox1.Text, textBox2.Text);
//listBox1.Items.Add($"{textBox1.Text}: {textBox2.Text}");
}
catch (Exception ex)
{
listBox1.Items.Add(ex.Message);
}
}
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
I'm getting the following error:
Error message/Exception
I've tried searching around the internet, about how to use the .WithUrl, but with no luck. I'm hoping that some of you guys can help a brother out!
Can you try displaying the innerException in your exception handler and see what the detailed error is?
Also, check your SignalR Event Hub (http://localhost:8080/MyHub) is running.
If your SignalR event hub is running then try debugging it and see if it receiving requests in your service hub background task.
Another thing you can check is the URL you are calling is identical to the SignalR hub route configured in your SignalR hub hub service:
routes.MapHub<MyHubClass>("/MyHub");
I am using Gma.System.MouseKeyHook and getting the following exception:
Managed Debugging Assistant 'CallbackOnCollectedDelegate'
Message=Managed Debugging Assistant 'CallbackOnCollectedDelegate' : 'A callback was made on a garbage collected delegate of type 'Gma.System.MouseKeyHook!Gma.System.MouseKeyHook.WinApi.HookProcedure::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.'
I've tried to handle the function calls and subscription. However, the issue still persists. Also I try to run it many times, occasionally it gives a 'NullReferenceException' as well. It also confused me a lot, maybe those issues are correlated.
using Gma.System.MouseKeyHook;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
// Uses a MouseKeyHook Library license at
https://github.com/gmamaladze/globalmousekeyhook/blob/master/LICENSE.txt
namespace TransparentClickTest {
public partial class Form1 : Form {
public Form1() {
//GC.TryStartNoGCRegion(100);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
BackColor = Color.Red;
TransparencyKey = Color.Red;
InitializeComponent();
OnDown();
}
protected virtual void OnUp() {
Hook.GlobalEvents().MouseUp += (sender, e) => {
try {
label1.Text = "Mouse Up!!!";
Hook.GlobalEvents().Dispose();
OnDown();
}
catch(Exception e2) {
Hook.GlobalEvents().Dispose();
OnDown();
}
};
}
protected virtual void OnDown() {
Hook.GlobalEvents().MouseDown += (sender, e) => {
try {
label1.Text = $"Mouse {e.Button} Down at {e.X}, {e.Y}";
Opacity = 1;
Hook.GlobalEvents().Dispose();
OnUp();
}
catch(Exception e1) {
Hook.GlobalEvents().Dispose();
OnUp();
}
};
}
private void PictureBox1_Click(object sender, EventArgs e) {
}
private void Label1_Click(object sender, EventArgs e) {
}
}
}
add this: private static IKeyboardMouseEvents HookEvents = null;
use HookEvents.MouseDown replace Hook.GlobalEvents().MouseDown
I am working On Emgu cv on windows 7 32 bit os and, System.TypeInitializationException Error occurs, i tried every solution;
When i run the Examples coming with Emgu it's Ok but when i create my own project the error occurs.
here is my code;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Capture cap;
private bool capinpro;
public Form1()
{
InitializeComponent();
}
private void processframe(object o, EventArgs e)
{
Image<Bgr, byte> img = cap.QueryFrame();
imageBox1.Image = img;
}
private void button1_Click(object sender, EventArgs e)
{
if(cap!=null)
{
try
{
if (capinpro)
{
Application.Idle += processframe;
//i have also tried cap.start();
}
else
{
Application.Idle -= processframe;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
cap= new Capure();
}
}
}
}
Emgu library was requiring more dll Files, so I pasted all the dlls from the bin folder of Emgu to the path of my EXE file and the problem was solved.
I am trying to make an application with 5 virtual(hidden) Gecko(Xulrunner) Browser. But when I try to create one browser in Threading its return error at GeckoPreferences I am totally confused with it!
Here code Sample:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Skybound.Gecko;
using System.Threading;
namespace Gekco_Test
{
public partial class Main : DevExpress.XtraEditors.XtraForm
{
public Main()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
}
private void Main_Load(object sender, EventArgs e)
{
}
private void simpleButton1_Click(object sender, EventArgs e)
{
Thread th = new Thread(webControllerFunc);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
void webControllerFunc()
{
geckoWebControl gControll = new geckoWebControl();
gControll.webBrowserAccess("91.213.108.178", 80);
}
}
class geckoWebControl
{
bool readyState;
GeckoWebBrowser wb = new GeckoWebBrowser();
public string webBrowserAccess(string host,int port)
{
Skybound.Gecko.Xpcom.Initialize(Application.StartupPath + "\\xulrunner\\");
readyState = false;
Form form = new Form();
GeckoPreferences.User["network.proxy.http"] = host;
GeckoPreferences.User["network.proxy.http_port"] = port;
GeckoPreferences.User["network.proxy.type"] = 1;
wb.Navigate("about:blank");
wb.DocumentCompleted += wb_DocumentCompleted;
while (!readyState)
Application.DoEvents();
return wb.Document.TextContent;
}
void wb_DocumentCompleted(object sender, EventArgs e)
{
readyState = true;
}
}
}
Error:
{"Unable to cast COM object of type 'System.__ComObject' to interface type 'Skybound.Gecko.nsIServiceManager'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{8BB35ED9-E332-462D-9155-4A002AB5C958}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."}
Thanks!
Gecko Doesn't support multithreading. So you can use it following code to use it in the threads.
this.BeginInvoke(new Action(() => {
//What you want gecko browser to do! Like:
geckoBrowser.navigate("http://somewhere.com");
}));
I am creating a application form to view/change a tag from a software called InTouch.
I added the dll as a reference and I would like to use the Read(string tagName) fct in the IOM.InTouchDataAccess. VS does not see the fct Read when I write InTouchWrapper TagType = new read(). It only sees InTouchWrapper as I wrote in the code which gives me the error IOM.InTouchDataAccess.InTouchWrapper' does not contain a constructor that takes 0 arguments
I don't understand why is this happening. I am running the InTouch software while coding, maybe there is an access conflict with the software.
MyCode
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IOM.InTouchDataAccess;
namespace TagBrowser
{
public partial class TagBrowser : Form
{
public TagBrowser()
{
InitializeComponent();
}
private void TagBrowser_Load(object sender, EventArgs e)
{
}
private void TagBox_TextChanged(object sender, EventArgs e)
{
}
private void TypeBox_SelectedIndexChanged(object sender, EventArgs e)
{
InTouchWrapper TagType = new InTouchWrapper();
}
The dll
using System;
using System.Collections.Generic;
using System.Text;
using NDde.Client;
namespace IOM.InTouchDataAccess
{
public class InTouchDdeWrapper : IDisposable
{
private int DDE_TIMEOUT = 60000;
private DdeClient _ddeClient;
public InTouchDdeWrapper()
{
_ddeClient = new DdeClient("View", "Tagname");
}
~InTouchDdeWrapper()
{
Dispose();
}
public void Initialize()
{
_ddeClient.Connect();
}
public string Read(string tagName)
{
return _ddeClient.Request(tagName, DDE_TIMEOUT).Replace("\0", "");
}
I'm putting this here in case somebody else would get the same problem:
Are you sure it's the correct dll you referenced? Try to open the
exact referenced dll in a decompiler (JustDecompile free,
Reflector or dotPeek free) and see if it's the code you
expect.