Nancy Empty Self Hosting - System.AccessViolationException - nancy

I am using Visual Studio 2015 Community Edition in Administrator mode. I installed SideWaffle Template Pack v1.21.400. I created a new Nancy Empty Self Host Project. The below is the Source Code:
using System;
using Nancy.Hosting.Self;
namespace NancyEmptySelfHost
{
class Program
{
static void Main(string[] args)
{
var uri =
new Uri("http://localhost:3579");
using (var host = new NancyHost(uri))
{
host.Start();
Console.WriteLine("Your application is running on " + uri);
Console.WriteLine("Press any [Enter] to close the host.");
Console.ReadLine();
}
}
}
}
On execution, I am getting System.AccessViolationException in the line host.Start(); with the below message:
Attempted to read or write protected memory. This is often an
indication that other memory is corrupt.
I get the same exception, when I create Projects with other Nancy Templates. If I create a Console application (without using Nancy template) and refer Nancy dlls, it's working fine. How should this be fixed?

Related

UnmanagedExports .net Standard 2.0 package in .net 7.0 not loading Runtime

I am using the UnmanagedExports.Repack https://github.com/kevingosse/UnmanagedExports.Repack in a .net framework project. It is being upgraded to .net 7.0. However, in 7.0 it always returns "Could not load file or assembly 'System.Runtime, Version=7.0.0.0" whenever an application tries to connect to the DLL.
I got it to work if my dll project is also a .net Standard 2.0. However, I need it in a .net 7.0 project.
I pulled the source code for UnmanagedExports.Repack and upgraded to .net 7.0 (had to add AsssemblyInfo.cs as it was missing). Added references to the projects in my soulution and still give the same error, but the exact code works fine if it is a .net Standard project.
Any ideas on how why I get the "Could not load file or assembly 'System.Runtime, Version=7.0.0.0" error.
*To Reproduce
create a .net standard 2.0 library project and add the DllExample and nuget package UnmanagedExports.Repack. (Make sure the project is set to X64 not any)
add a console application project (I used .net 7.0) add the "Calling Code" classes below.
Run and you get correct results.
remove the .net standard 2.0 library project
Add a .net 7.0 library project, add the DllExample and nuget package UnmanagedExports.Repack (Make sure the project is set to X64 not any)
run in command line and you get the error.*
Dll Exmple:
using System;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
namespace NewDLLTest2
{
public class DLLCalls
{
[DllExport("TestGetJSON", CallingConvention = CallingConvention.StdCall)]
static public string TestGetJSON()
{
string ret = "{\"Message\":\"Hello\"}";
return ret;
}
}
}
Calling Code:
NativeMethods.cs
using System;
using System.Runtime.InteropServices;
namespace ConsoleApp1
{
class NativeMethods
{
const string _dllLocation = "NewDLLTest2.dll";
[DllImport(_dllLocation, CallingConvention = CallingConvention.StdCall)]
public static extern string TestGetJSON();
}
}
Program.cs
using System;
using System.IO;
namespace ConsoleApp1
{
class Program
{
[STAThread]
static void Main(string[] args)
{
string ret = NativeMethods.TestGetJSON();
Console.WriteLine(ret);
}
}
}

Unable to connect a Run A Script in Selenium using IE Driver

Trying to Run a Script in Luna Eclipse using IE Driver
and getting the following error:
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Here is the code trying to Run:
package com.newpack;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class SecondClass {
public static void main(String[] args)
{
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability("requireWindowFocus", true);
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL,"https://www.google.co.in");
System.setProperty("webdriver.ie.driver","M:\\workspace\\IEDriver.exe");
WebDriver driver ;
driver = new InternetExplorerDriver(capabilities);
String baseUrl = "https://www.google.co.in";
driver.get(baseUrl);
String expectedTitle = "Google";
String actualTitle = "";
actualTitle = driver.getTitle();
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
driver.close();
System.exit(0);
}
}
try once following steps
Got to
internet options>>Security>>
click on:"Reset all zones to default level"
ensure that the 'Enable protected mode' checkbox is ticked for all the four zones. Like i.e Internet, Local internet, Trusted Sites, Restricted Sites.
Internet Explorer needs to be configured first in order to successfully run a selenium script.
Make sure you complete all the following steps:
Go to Internet Options > Security and enable "Protected Mode" for all the 4 zones: Internet, Local internet, Trusted Sites, Restricted Sites.
Also, click on Custom Level for all 4 zones and reset Recent Custom Settings to same level, say "Medium" or "High".
If this does not work, please update your IEDriverServer from Selenium Official Downloads

debug in localhost using deployed database

I use Google Eclipse Plugin, develop a web page using GWT + GAE/Java.
I would like to debug in localhost with the local GWT code but want to use the database in my actual deployed web page.
Is it possible?
Yes, you can connect to your production database using Google App Engine Remote API. You can get inspired by Gealyk Remote Connector which is doing exactly the same. Check the Remote Connector Filter source code for example. Basically you need to create filter which
Check if the Remote API is installed and if it's not install it using given credentials
Proceed to your application code using chain.doFilter(request, response)
Uninstall the Remote API Installer when the execution is finished
Just be careful that depending on your internet connection the application might be slow and sometimes timeouts.
Filter doesn't work well with RemoteServiceServlets so add these to your RemoteServiceServlet:
RemoteApiOptions options;
RemoteApiInstaller installer;
#Override
protected void onBeforeRequestDeserialized(String serializedRequest) {
if (getThreadLocalRequest().getRequestURL().indexOf("127.0.0.1") != -1) {
if (options == null) {
options = new RemoteApiOptions().server("example.appspot.com", 443).credentials("username",
"password");
installer = new RemoteApiInstaller();
try {
installer.install(options);
options.reuseCredentials("username", installer.serializeCredentials());
}
catch (IOException e) {
e.printStackTrace();
}
}
else {
installer = new RemoteApiInstaller();
try {
installer.install(options);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
#Override
protected void onAfterResponseSerialized(String serializedResponse) {
if (getThreadLocalRequest().getRequestURL().indexOf("127.0.0.1") != -1)
installer.uninstall();
}

How Do I implement PhantomJS + Wedriver on c#

I have written the following code and downloaded PhantomJS intot he specified folder on c:\ but am getting the error: "Unable to connect to remote server ...". Here is the code I wrote:
[TestMethod]
public void HeadlessBrowser()
{
IWebDriver driver = new PhantomJSDriver("C:\\trashStuff\\phantomjs-1.9.0-windows"); //or some other driver
driver.Navigate().GoToUrl("http://yahoo.com");
// Lets take a screenshot to really make sure we did visit the site above
Console.WriteLine("Take A screen shot");
Screenshot myScreenShot = ((ITakesScreenshot)driver).GetScreenshot();
myScreenShot.SaveAsFile("c:\\trashStuff\\screenshot.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
// after the run, go to the location above and find screenshot.jpg
}
Download PhantomJS or add it to your project using NuGet Package Manager. I got it using NuGet and didn't have to put the path to the driver as one of the parameters in PhantomJSDriver class.
var driver = new PhantomJSDriver();

HTTP Status 500 - Java Runtime Environment (JRE) version 1.7 is not supported by this driver

I am trying to access MS SQL server 2005 from a servlet file. I am using JDBC 4.0 driver.
I have already added the JAR files sqljdbc.jar and sqljdbc4.jar files to my Tomcat /lib folder.
But while running code I am getting an error
HTTP Status 500 - Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
How is this caused and how can I solve it?
My code is:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = conn = DriverManager.getConnection("jdbc:sqlserver://localhost;databaseName=school;user=sa;password=123");
PrintWriter pwOut = res.getWriter();
pwOut.println("Connected");
Statement st = conn.createStatement();
String searchCriteria = req.getParameter("txtSearch");
ResultSet rs = st.executeQuery("select * from student");
res.setContentType("text/html");
The error message is pretty clear. Tomcat is using the wrong driver.
You state that you copied sqljdbc.jar and sqljdbc4.jar into the Tomcat lib folder. That is most probably the reason for your problem.
You only need sqljdbc4.jar otherwise Tomcat picks up the wrong one.
Try to delete sqljdbc.jar from the Tomcat lib folder
Here is my Code to connect java to Microsoft sql Server 2012
You only need sqljdbc4.jar that avail on offical Microsoft website. Here is the link:
http://download.microsoft.com/download/0/2/A/02AAE597-3865-456C-AE7F-613F99F850A8/sqljdbc_4.0.2206.100_enu.exe
It contains 2 jar files, and I am trying to use sqljdbc4.jar. This is the code I am using to connect:
package com.Sql.ConnectDB;
import java.sql.*;
public class DbClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
**String url="jdbc:sqlserver://localhost;databaseName=Student";**//important
String user="username";
String pass="password";
**Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");**//important
Connection con=DriverManager.getConnection(url,user,pass);
System.out.println("Conneccted Successfully");
}catch(Exception e){
e.printStackTrace();
}
}
}

Resources