ConfigurationManager issue in VS 2017 - visual-studio-2017

The following code, when run in Visual Studio 2015 and earlier, results in a message box being shown with the expected value "12345".
string executablePath = Application.ExecutablePath;
executablePath = Path.GetFileNameWithoutExtension(executablePath);
executablePath = executablePath + ".vshost.exe";
if (!File.Exists(executablePath))
throw new FileNotFoundException(executablePath);
Configuration cfg = ConfigurationManager.OpenExeConfiguration(executablePath);
cfg.AppSettings.Settings.Add("Testing", "12345");
cfg.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(cfg.AppSettings.SectionInformation.Name);
string testing = ConfigurationManager.AppSettings["Testing"];
MessageBox.Show(testing);
When I run the same code in Visual Studio 2017 the message box displays a blank value.
Is this a bug in Visual Studio 2017 or does the code require modification?
UPDATE (specific cause):
So the main cause, along with the accepted answer, was that I had opened the solution in VS 2015 which generated the *.vshost.exe related files. Later I opened the solution in VS 2017 and, of course, the *.vshost.exe files aren't cleaned automatically so were still there.
UPDATE 2 (for those who want to be able to use similar code in both):
string executablePath = Application.ExecutablePath;
executablePath = Path.GetFileNameWithoutExtension(executablePath);
executablePath = executablePath + ".vshost.exe";
// Check if the *.vshost.exe exists
if (File.Exists(executablePath))
{
try
{
// If deleting throws an exception then the stub is being run by *.vshost.exe while
// debugging which means this is NOT Visual Studio 2017 (*.vshost.exe is no longer used in VS 2017)
File.Delete(executablePath);
// If it deletes then use the regular app path since VS2017 is using that now.
executablePath = Application.ExecutablePath;
}
catch (Exception)
{
executablePath = Application.ExecutablePath;
}
}
else
executablePath = Application.ExecutablePath;
Configuration cfg = ConfigurationManager.OpenExeConfiguration(executablePath);
cfg.AppSettings.Settings.Add("Testing", "12345");
cfg.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(cfg.AppSettings.SectionInformation.Name);
string testing = ConfigurationManager.AppSettings["Testing"];
MessageBox.Show(testing);

The debugger hosting process has been removed in VS2017, so when you run your application the path you give to the OpenExeConfiguration method is incorrect.
Instead, pass Application.ExecutablePath to that method and it should work. The same should work in VS 2015 if you turn off the hosting process (Project properties -> Debug -> Enable the Visual Studio hosting process).
It's odd that you were using the hosting process path in the first place, as that would only ever work while running in the debugger from within Visual Studio.

Related

Cannot debug single theory in isolation

Is there a way to debug an individual theory in Visual Studio 2017? This worked in 2015. Now, in 2017, starts the debugger and kicks off all test cases in the theory.
I just updated the latest release of 2017 (15.9.7). Not sure if it worked beforehand.
I can choose an individual test, but when I click debug, they are all executed.
This works in Visual Studio 2015 (14.0.25431.01 Update 3). The issue persists in Visual Studio 2019 preview 1.1.
Shortened code sample:
namespace MyNameSpace
{
public class PayloadTest : BaseTest
{
[InlineData("AllergyDataChanged")]
[InlineData("ImplantableDeviceDataChanged")]
public void test1(string source, Type entityIdType = null)
{
TestSubscriber(source, entityIdType);
}
Go to: Tools > Options > Test > General > Uncheck "Discover tests in real time from source files"
This appears to be an issue with Visual Studio 2017+.
Source of quote is a response a received on Github

Facing Test Case not found on Visual Studio 2017 [version 15.8.1]

I am facing "test method not found" on visual studio 2017 - Version 15.8.1, When i am trying to run or debug the code from visual studio.
Issue: [Test project {Project Name} does not reference any .NET NuGet adapter. Test discovery or execution might not work for this project. It is recommended to reference NuGet test adapters in each test project in the solution. ]
Note: I am able to solve the above error on visual studio 2017 versions 15.7.* using below link.
Please note this is not duplicate of - "Visual Studio 17: Facing Test Case not found issue in Visual Studio 17" or any other question already in stack overflow.
If you have the same version. It can be reproduced using this code.
[TestClass]
public class ATest : ATestBase
{
[TestInitialize]
public override void TestInitialize()
{
if (Playback.IsInitialized == false)
Playback.Initialize();
}
[TestCleanup]
public override void TestCleanup()
{
if (Playback.IsInitialized == true)
Playback.Cleanup();
base.TestCleanup();
}
[TestMethod, TestCategory("SmokeTest")]
[DeploymentItem(#"DataSource\Documents\some.pdf")]
public void SmokeFlow()
{
string name = "test";
}
}
Starting Visual studio 2017 version 15.8 and on wards. A new option is added under tools -> options -> test as shown in screenshot. Uncheck the option and restart your visual studio. This solves the issue.

Visual Studio 2012 : Oracle Database program using VC++ (MFC) & Oracle OCCI Library

I tried to connect the oracle XE (11.2.0.2.0) database using VC++ MFC (Visual Studio 2012). Below is a example code given at oracle website.
void CMFCOracleOCCIDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
const string userName = "<username>";
const string password = "<password>";
const string connectString = "";
Environment *env = Environment::createEnvironment();
{
Connection *conn = env->createConnection(userName, password, connectString);
Statement *stmt = conn->createStatement("SELECT * FROM tab");
ResultSet *rs = stmt->executeQuery();
for(int i=1;i<20;i++){
rs->next();
//Below are the commented 4 lines
/*
string s = rs->getString(1);
CString str2(s.c_str());
lstBox01.AddString(str2);
MessageBox(str2);
*/
}
stmt->closeResultSet(rs);
conn->terminateStatement(stmt);
env->terminateConnection(conn);
}
Environment::terminateEnvironment(env);
}
In the above code while the 4 line in comment, it works fine. Otherwise it works for only one loop (i=1) and display the proper message (for only 1 time). After that, getting the below error
First-chance exception at 0x51A4CCC8 (msvcp110d.dll). After selecting the break it goes to the file xutility and function
inline void _Container_base12::_Orphan_all()
How to solve this error?
Usually what is best practice to connect oracle using VC++ MFC?
Environment :
Windows 8.1 (64)
Oracle XE (11.2.0.2.0)
OCCI Library : Instant Client Package - SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client
Download instantclient-sdk-nt-11.2.0.2.0.zip
Visual Studio 2012 (Debug - Configuration)
Edit
This error raised in-case of getString() (varchar2 field). When using integer field with getInt(), it is working fine.

OCCI app crashes when running in debug mode in Visual Studio 2005

I'm attempting to get a development environment up and running for developing applications with Oracle C++ Call Interface (OCCI) in Visual Studio 2005.
My system specs are:
OS: Windows 7, 64-bit
Oracle: 11g release 11.2.0.2, 32-bit
Instant Client: BasicLite and SDK version 11.2.0.4 32-bit
Visual Studio 2005 Professional Edition version 8.0 with 32-bit tools enabled
I've followed this guide by Mark Williams and I got the example running but only in release mode. When I switch to debug mode the app will build, but when I run it I get the following error:
Problem signature:
Problem Event Name: APPCRASH
Application Name: OCCITest.exe
Application Version: 0.0.0.0
Application Timestamp: 53f5dfdd
Fault Module Name: KERNELBASE.dll
Fault Module Version: 6.1.7601.18229
The small example program that triggers this error is:
#include "employees.h"
using namespace std;
using namespace oracle::occi;
int main (void)
{
Employees *pEmployees = new Employees();
delete pEmployees;
return 0;
}
Employees::Employees()
{
user = "hr";
passwd = "hr";
db = "localhost:1521/service_name";
env = Environment::createEnvironment(Environment::DEFAULT);
try
{
con = env->createConnection(user, passwd, db);
}
catch (SQLException& ex)
{
cout << ex.getMessage();
exit(EXIT_FAILURE);
}
}
Employees::~Employees()
{
env->terminateConnection (con);
Environment::terminateEnvironment (env);
}
If I remove all calls to OCCI functionality the application doesn’t crash. That is, this program runs error-free:
#include "employees.h"
using namespace std;
using namespace oracle::occi;
int main (void)
{
Employees *pEmployees = new Employees();
delete pEmployees;
return 0;
}
Employees::Employees()
{
user = "hr";
passwd = "hr";
db = "localhost:1521/service_name";
cout<<"Look at me, I'm running"<<endl;
}
Employees::~Employees()
{}
In the guide Mark mentions that when running in debug mode, the linker should use the library file oraocci11d.lib. However, this file is not included in the Instant Client SDK version 11.2.0.4, so I’m using the input file oraocci11.lib for both the release and debug version.
I'm running out of ideas about how to proceed in solving this problem, and I would greatly appreciate any and all help.
If the Oracle DLL receives and/or passes objects such as std::string or any other object that either:
Manipulates the heap in any way, or
The objects could have differing internals between app and DLL,
then you have no choice but to use the correct library to link with. Otherwise you wind up with binary or heap incompatible objects being passed, which leads to what you're seeing now.
See here: http://docs.oracle.com/cd/E11882_01/appdev.112/e10764/install.htm#CBHGBBJI
The link above mentions both the debug import library and debug version of the DLL. Also this is stated at the link:
Applications that link to MSVCRTD.DLL, a debug version of Microsoft C-Runtime, /MDd compiler flag, should link with these specific OCCI libraries: oraocci11d.lib and oraocci11d.dll.
Since it took me quite some time to get the debug environment working I figured I'd answer my own question now that I did.
I got a variety of errors throughout the ordeal, but the error that I got most stuck on was an error saying:
'The application was unable to start correctly (0xc0150002).
Click OK to close the application.'
Also, I used http://www.dependencywalker.com which repeatedly told me that either oraocci11d.dll or a the following list of dll's could not be found.
API-MS-WIN-APPMODEL-RUNTIME-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
API-MS-WIN-SHCORE-SCALING-L1-1-1.DLL
DCOMP.DLL
IESHIMS.DLL
However, what was really missing was for the executable to be able to find oci.dll. I'm just mentioning the errors in case someone else runs into these.
Here is what was needed to make it work:
First of all, the Instant Client does not contain the oraocci11d.lib or oraocci11d.dll, so it is necessary to install the full Oracle Client.
Next, the following must be added to the PATH:
C:\Program Files\Oracle\11.2.0\OCI\lib\MSVC\vc8
C:\Program Files\Oracle\11.2.0\BIN
In Visual Studio, select Tools -> Options, unfold 'Projects and Solutions' and select VC++ Directories. In 'Show directories for' under:
Include Files add C:\Program Files\Oracle\11.2.0\OCI\include
Library files add C:\Program Files\Oracle\11.2.0\OCI\lib\MSVC\vc8
In the property page for your project under Configuration Properties -> Linker select Input and under Additional Dependencies add oraocci11d.lib (or oraocci11.lib for release mode). Then select debug/release mode in the Configuration Manager
I have a related problem in that I am successfully using oraocci12d.dll/msvcr100d.dll, but this in turn is using oci.dll/msvcr100.dll. ie, oci.dll is not using the debug version of msvcr100.
My program seems to run okay, but any memory leak reporting disappears on exit.

Visual Studio 2013 crashes when compiling Sqlite C++ library

I'm having an absolute nightmare of a time trying to get the Sqlite C++ library to compile in Visual Studio 2013 Ultimate (Compiles fine in VS2012).
Basically regardless of whether I try to perform a clean or a rebuild VS will claim to successfully finish but will subsequently freeze and become unresponsive, never to recover.
Here is the output
and here is the actual VS project.
Anyone care to give it a crack and see if they are running into the same problem or provide any suggestions?
Tim Heuer gives step by step instructions ON THIS LINK. The batch files are hardcoded for TCL 8.5, you'll save yourself some time if you don't download the latest (8.6)
EDITED - I successfully compiled SQLite with Tim's steps (I just reinstalled Windows 8.1 / VS 2013). Note: the only issue I encountered was taking the steps to literally, be sure to change into the newly created SQLite directory before running the fossil command.
FYI for WinRT, be sure to use the correct path, if you just specify the filename you will get an access denied error (which will surface as a "cannot open database" error).
using namespace Windows::Storage;
using namespace std;
void SqliteWrapper::RunTest(void)
{
sqlite3 *db;
int rc;
auto path = ApplicationData::Current->LocalFolder->Path+"\\MyDatabase.db";
string dataPath(path->Begin(), path->End());
rc = sqlite3_open(dataPath.c_str(), &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
}
sqlite3_close(db);
}