With following code, by service does start but when I uncomment Debugger.Break() it doesn't. What's wrong.
protected override void OnStart(string[] args)
{
#if DEBUG
//Debugger.Break();
#endif
}
Further update, if I change the target framework to 3.5 it works but doesn't work in framework 4.0!!!
Related
Some context:
I am using .Net 6.0.101 and Microsoft.AspNetCore.Mvc.
I want to test on localhost before I commit and push, and not rely on a deployment to a QA-style environment for example. Here is some pseudo code of what I want to do:
[OneTimeSetup]
public void static OneTimeSetup()
{
pid = OurApplication.Start();
OurApplication.WaitForApplicationToBeStarted();
}
[OneTimeTeardown]
public void static OneTimeSetup()
{
pid.Kill();
}
I wonder if there is a library I can use that does this level of process or background thread orchestration?
I have a Windows service for test purposes that i want to migrate to Service Fabric. The service does nothing more than writing to a txt-file on my drive when it starts and when it stops. It works fine when i manually start and stop the service after installing it on my machine. Can i achieve the same result on service fabric or does the implementation be different?
I have created a guest executable with the service and deployed it to a local cluster following this guide.
First of all, I don't like this answer. After playing with it, I'm convinced the best way is to just port the code to a service fabric app. I would love to see a better "bolt-on" solution, but I haven't found any others. Every answer I've seen says "just run the exe as a Guest Executable", but a Windows Service exe doesn't "just run". It needs to be ran as a Windows Service which calls the OnStart entry point of the Service class (which inherits from ServiceBase).
The code below will allow your Windows Service to run in Service Fabric, but Service Fabric seems to report WARNINGS! So it's FAR from perfect.
It shouldn't require any changes to your OnStart or OnStop methods, however it does require some basic plumbing to work. This is also helpful if you wish to debug your windows services, as it allows you to pass in a /console command line argument and have it run in a console window.
First, either create your own ServiceBase class, or simply paste this code into your Service class (by default it's called Service1.cs in a C# Windows Service project):
// Expose public method to call the protected OnStart method
public void StartConsole(string[] args)
{
// Plumbing...
// Allocate a console, otherwise we can't properly terminate the console to call OnStop
AllocConsole();
// Yuck, better way?
StaticInstance = this;
// Handle CTRL+C, CTRL+BREAK, etc (call OnStop)
SetConsoleCtrlHandler(new HandlerRoutine(ConsoleCtrlCheck), true);
// Start service code
this.OnStart(args);
}
// Expose public method to call protected OnStop method
public void StopConsole()
{
this.OnStop();
}
public static Service1 StaticInstance;
private static bool ConsoleCtrlCheck(CtrlTypes ctrlType)
{
switch (ctrlType)
{
case CtrlTypes.CTRL_C_EVENT:
case CtrlTypes.CTRL_BREAK_EVENT:
case CtrlTypes.CTRL_CLOSE_EVENT:
case CtrlTypes.CTRL_LOGOFF_EVENT:
case CtrlTypes.CTRL_SHUTDOWN_EVENT:
StaticInstance.StopConsole();
return false;
}
return true;
}
[DllImport("kernel32.dll")]
private static extern bool AllocConsole();
[DllImport("Kernel32")]
public static extern bool SetConsoleCtrlHandler(HandlerRoutine Handler, bool Add);
public delegate bool HandlerRoutine(CtrlTypes CtrlType);
public enum CtrlTypes
{
CTRL_C_EVENT = 0,
CTRL_BREAK_EVENT,
CTRL_CLOSE_EVENT,
CTRL_LOGOFF_EVENT = 5,
CTRL_SHUTDOWN_EVENT
}
Now change your Main method in Program.cs to look like this:
static void Main(string[] args)
{
var service = new Service1();
if (args.Length > 0 && args.Any(x => x.Equals("/console", StringComparison.OrdinalIgnoreCase)))
{
service.StartConsole(args);
}
else
{
ServiceBase.Run(
new ServiceBase[]
{
service
});
}
}
You may need to rename 'Service1' to whatever your service class is called.
When calling it through Service Fabric, make sure it's passing in the /console argument in ServiceManifest.xml:
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>WindowsService1.exe</Program>
<Arguments>/console</Arguments>
<WorkingFolder>Work</WorkingFolder>
</ExeHost>
</EntryPoint>
</CodePackage>
If you wish to use this as a debuggable Windows Service, you can also set your 'Command line arguments' to /console under the Project settings > Debug tab.
EDIT:
A better option is to use TopShelf. This will work without warnings in Service Fabric, however it does require some code refactoring as it becomes a Console project instead of a Windows Service project.
I have one class writed on Symfony 3.1 with php 7.1 and when i decide add return type as void then symfony throw exception. Method look's like:
private function log(): void {
//body
}
"Not found App\TestBundle\Listener\void, none returned" .
How can i set return typing void for method?
Update php to version 7.1. That error means that you believe to work with 7.1 but you are not.
I had working code on VS 2013 NET4.5. After update (VS 2013, NET 4.5.1) of NuGet packages I got this error
An exception of type 'System.InvalidOperationException' occurred in
System.Web.Mvc.dll but was not handled in user code
Additional information: The given filter instance must implement one
or more of the following filter interfaces: IAuthorizationFilter,
IActionFilter, IResultFilter, IExceptionFilter.
I am sure that I implemented IActionFilter interface, so how can I get error like this and how can I fix it?
FYI:
public class WWWActionFilterAttribute : System.Web.Mvc.ActionFilterAttribute, System.Web.Mvc.IActionFilter
{
public override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
{
System.Uri Address = filterContext.HttpContext.Request.Url;
string[] domains = Address.Host.Split('.');
if (domains.Length == 2)
{
System.UriBuilder AddressBuilder = new System.UriBuilder(Address);
AddressBuilder.Host = string.Format("www.{0}", AddressBuilder.Host);
filterContext.HttpContext.Response.Redirect(AddressBuilder.Uri.AbsoluteUri);
}
else
{
base.OnActionExecuting(filterContext);
}
}
}
Config
public class FilterConfig
{
public static void RegisterGlobalFilters(System.Web.Mvc.GlobalFilterCollection filters)
{
filters.Add(new System.Web.Mvc.HandleErrorAttribute());
filters.Add(new TIKSN.HomeWebsite.Generalization.WWWActionFilterAttribute());
filters.Add(new TIKSN.HomeWebsite.Globalization.LanguageActionFilterAttribute());
}
}
Are we talking about System.Web.Mvc.dll having to have the save version and if so where? If I add this DLL to my domain I can only get up to version 4.0. However I have a version 5.1 in my web API the project with web config file. I really don't understand why I would have to match these versions and why my solution doesn't recognize the highest version if that is why its failing. I believe Visual Studio 2013 Express automatically loaded version 5.1, but I had to get my own for the domain project and that doesn't offer 5.1. One of the worst things about MVC is dependency management.
You are adding a HttpFilter (WebAPI filter) to an MVC Global filter. Your filter should be added to HttpFilterCollection
Add this to filterConfig.cs
public static void RegisterHttpFilters(HttpFilterCollection filters)
{
filters.Add(new WWWActionFilterAttribute());
}
And this to Global.ascx.cs:
FilterConfig.RegisterHttpFilters(GlobalConfiguration.Configuration.Filters);
This was because of web.config file. You have to specify exact version of packages there. Look here
Update
In Web.config all packages are registered and have their name and version pairs. The actual versions and the versions in the Web.config were not matching.
I want to make Blackberry application that can restart the blackberry it self (after doing some task)
for example, i make this little application using the dummy
dummy : (after it becomes dummy.cod, i move it to the res folder and rename it to dummy, not using .cod anymore)
public class Dummy extends Application{
public static void main( String[] args ) {
new Dummy().enterEventDispatcher();
}
public Dummy(){
}
}
application sample code :
(description of my application : just have 1 button to call the reset method)
public void reset() throws Exception {
// load the dummy cod file
byte[] cod = IOUtilities.streamToBytes(getClass().getResourceAsStream("/dummy"));
// create new module
int newHandle = CodeModuleManager.createNewModule(cod.length, cod, cod.length);
// install the module
if (newHandle != 0) {
int savecode = CodeModuleManager.saveNewModule(newHandle, true);
if (savecode == CodeModuleManager.CMM_OK_MODULE_OVERWRITTEN)
Logger.debug("The operation completed successfully; a module was overwritten and marked for deletion in the process.");
// now run the dummy application in background
ApplicationDescriptor appDesc = CodeModuleManager.getApplicationDescriptors(newHandle)[0];
ApplicationManager.getApplicationManager().runApplication(appDesc, false);
CodeModuleManager.deleteModuleEx(newHandle, true);
}
// restart the blackberry if required
CodeModuleManager.promptForResetIfRequired();
}
When I run my code to Simulator (SimPackage 6.0.0.587 - 9780 & SimPackage 5.0.0.977 - 9300) the code was running well, it shows a message to "Restart Now / Restart Later".
But when I’ve load my code to real device 9780 OS 6.0.0.570 and device 9300 OS 5.0.0.846, the code is still won’t work.
Any idea why is it happen ? or I just make a simple but fatal mistake ?
Thanks :)
Your code is correct, but you need to sign your code to be able to execute CodeModuleManager.deleteModuleEx on a real device.
Please refer to the CodeModuleManager documentation for more information.