I am developing a WEB API 2 project and I am trying to set up a basic authentication system on my REST server.
I'm having issues with an error when I launch my application and I don't find the origin of this error.
Class code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
namespace CalypsoWebApplication.App_Code
{
public class ResultWithChallenge : IHttpActionResult
{
private readonly System.Web.Http.IHttpActionResult next;
public ResultWithChallenge(IHttpActionResult next)
{
this.next = next;
}
public async Task<HttpResponseMessage> ExecuteAsync(
CancellationToken cancellationToken)
{
var res = await next.ExecuteAsync(cancellationToken);
if (res.StatusCode == HttpStatusCode.Unauthorized)
{
res.Headers.WwwAuthenticate.Add(
new AuthenticationHeaderValue("Basic", null));
}
return res;
}
}
}
Erreur au lancement :
Message d'erreur du compilateur: CS0246: Le type ou le nom d'espace de noms 'HttpResponseMessage' est introuvable (une directive using ou une référence d'assembly est-elle manquante ?)
English translation : type or namespace 'HttpResponseMessage' cannot be found, is a using directive or an assembly reference missing ?
Erreur source:
Ligne 22 : }
Ligne 23 :
Ligne 24 : public async Task ExecuteAsync(
Ligne 25 : CancellationToken cancellationToken)
Ligne 26 : {
Fichier source: e:\Users\mehin\Documents\Visual Studio 2013\Projects\Calypso\CalypsoWebApplication\App_Code\ResultWithChallenge.cs Ligne: 24
Whe looking on https://msdn.microsoft.com/fr-fr/library/w7xf6dxs.aspx the possibles sources of this error, I still don't understand why it happens.
Target Framework .NET 4.5
In my project references, I have "System.Net.Http" which targets System.NetNHttp.dll, version 4.0.0.0
When trying to prefix HttpResponseMessage with System.Net.http, the error still occurs.
When cleaning and building my solution in Visual Studio 2013, I don't get any error. I only get it when i launch the application.
I don't know what else I could add, don't hesitate to ask for more details.
Related
In order to avoid browser driver version mismatch issue every time I execute my Selenium tests using xUnit test runner, I have added below line of code to my .cs file
new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);
but, when I execute my test, I'm getting below error
SampleXUnitTestProject.FirstSeleniumTests.CorrectTitleDisplayed_When_NavigateToHomePage
Source: FirstSeleniumTests.cs line 25
Duration: 1 ms
Message:
System.Net.WebException : The remote server returned an error: (404) Not Found.
Stack Trace:
HttpWebRequest.GetResponse()
ChromeConfig.GetLatestVersion(String url)
ChromeConfig.GetMatchingBrowserVersion()
DriverManager.GetVersionToDownload(IDriverConfig config, String version)
DriverManager.SetUpDriver(IDriverConfig config, String version, Architecture architecture)
FirstSeleniumTests.ctor() line 18
My test is getting passed if I remove VersionResolveStrategy.MatchingBrowser argument from SetUpDriver, but correct version of drivers matching my current version of installed browsers will be downloaded only when I pass VersionResolveStrategy.MatchingBrowser argument to the SetUpDriver. Can someone help me to resolve the above error?
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using System;
using WebDriverManager;
using WebDriverManager.DriverConfigs.Impl;
using WebDriverManager.Helpers;
using Xunit;
namespace SampleXUnitTestProject
{
public class FirstSeleniumTests : IDisposable
{
private IWebDriver _driver;
public FirstSeleniumTests()
{
new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);
_driver = new ChromeDriver();
_driver.Manage().Window.Maximize();
}
[Fact]
public void CorrectTitleDisplayed_When_NavigateToHomePage()
{
_driver.Navigate().GoToUrl("https://lambdatest.github.io/sample-todo-app/");
Assert.Equal("Sample page - lambdatest.com", _driver.Title);
}
public void Dispose()
{
_driver.Quit();
}
}
}
I'm following along with a Tim Corey tutorial on making a Tournament Tracker WinForm app (this one at this point, in case it helps - https://preview.tinyurl.com/yxmyz8h6)
I've gotten to the point where we are starting to hook up the class library to SQL using some NuGet packages - namely Dapper, System.Data.SqlClient & System.Configuration.ConfigurationManager.
So far the project is split across two namespaces, the class library that holds all the models and data access classes (TrackerLibrary) & the form UI (TrackerUI). I was under the impression from the tutorial that these references only need to exist in the class library and not in the UI (as TrackerLibrary is where Tim directed us to add them)
But without them referenced in the TrackerUI - a FileNotFoundException shows up for all three when you run the code. However, that doesn't happen to him in the tutorial.
The SQL connection string is set up in the App.Config file of the TrackerUI and looks like this...
<connectionStrings>
<add name="Tournaments"
connectionString="Server=localhost;Database=TournamentTracker;Trusted_Connection=True;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
There is a class in TrackerUI called CreatePrizeForm that has a button click method to validate the form a user completes and then turn that data into a model and pass that model into SQL...
using System;
using System.Windows.Forms;
using TrackerLibrary;
using TrackerLibrary.Models;
namespace TrackerUI
{
public partial class CreatePrizeForm : Form
{
public CreatePrizeForm()
{
InitializeComponent();
}
private void createPrizeButton_Click(object sender, EventArgs e)
{
if (ValidateForm())
{
PrizeModel model = new PrizeModel(
placeNameValue.Text,
placeNumberValue.Text,
prizeAmountValue.Text,
prizePercentageValue.Text);
GlobalConfig.Connection.CreatePrize(model);
placeNameValue.Text = "";
placeNumberValue.Text = "";
prizeAmountValue.Text = "0";
prizePercentageValue.Text = "0";
}
GlobalConfig class handles deciphering whether we are saving to SQL or saving to a Text File as per the imaginary client requirements for the tutorial and grabs the connection string, which looks like this...
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using TrackerLibrary.DataAccess;
using System.Data.SqlClient;
using Dapper;
public static class GlobalConfig
{
public static IDataConnection Connection { get; private set; }
public static void InitializeConnections(DatabaseType db)
{
if (db == DatabaseType.Sql)
{
SqlConnector sql = new SqlConnector();
Connection = sql;
}
else if (db == DatabaseType.TextFile)
{
TextConnector text = new TextConnector();
Connection = text;
}
}
public static string CnnString(string name)
{
return ConfigurationManager.ConnectionStrings[name].ConnectionString;
}
}
The IDataConnection interface looks like this...
using System;
using System.Collections.Generic;
using System.Text;
using TrackerLibrary.Models;
namespace TrackerLibrary.DataAccess
{
public interface IDataConnection
{
PrizeModel CreatePrize(PrizeModel model);
}
}
And the CreatePrize method looks like this...
using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using TrackerLibrary.Models;
public class SqlConnector : IDataConnection
{
public PrizeModel CreatePrize(PrizeModel model)
{
using (IDbConnection connection = new
System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("Tournaments")))
{
var p = new DynamicParameters(); // Dapper object
p.Add("#PlaceNumber", model.PlaceNumber);
p.Add("#PlaceName", model.PlaceName);
p.Add("#PrizeAmount", model.PrizeAmount);
p.Add("#PrizePercentage", model.PrizePercentage);
p.Add("#id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
connection.Execute("dbo.spPrizes_Insert", p, commandType: CommandType.StoredProcedure);
model.Id = p.Get<int>("#id");
return model;
}
The error occurs when the code reaches here...
GlobalConfig.Connection.CreatePrize(model);
With the following exception...
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Data.SqlClient, Version=4.6.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
When I installed the System.Data.SqlClient NuGet package into the TrackerUI's references - it errors at the same point as before but this time it talks about Dapper...
System.IO.FileNotFoundException: 'Could not load file or assembly 'Dapper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.'
Then if you then install Dapper into TrackerUI references, it gets past the GlobalConfig.Connection.CreatePrize call into SqlConnector.cs and errors on the using (IDbConnection connection = new System.Data.SqlClient.SqlConnection... line below...
using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using TrackerLibrary.Models;
namespace TrackerLibrary.DataAccess
{
public class SqlConnector : IDataConnection
{
public PrizeModel CreatePrize(PrizeModel model)
{
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("Tournaments")))
{
var p = new DynamicParameters(); // Dapper object
p.Add("#PlaceNumber", model.PlaceNumber);
p.Add("#PlaceName", model.PlaceName);
p.Add("#PrizeAmount", model.PrizeAmount);
p.Add("#PrizePercentage", model.PrizePercentage);
p.Add("#id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
connection.Execute("dbo.spPrizes_Insert", p, commandType: CommandType.StoredProcedure);
model.Id = p.Get<int>("#id"); //Pulls ID from the p variable that represents the id of the record in the database
return model;
}
With another FileNotFoundException...
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.'
Adding references within the TrackerUI namespace to Dapper, System.Data.SqlClient and System.Configuration.ConfigurationManager resolves the exceptions and enables the program to write to SQL no problem. I just wanted to clear up whether that was what I needed to do by default or whether I've missed something earlier and the TrackerUI namespace shouldn't feature references to them. Just don't want to get into bad habits.
Sorry if I've missed any important detail - kinda new to this and have tried to be as thorough as possible but let me know if there is anything else I need to provide.
Thank you for your clarification and help in advance!
I am trying to build an sqlite database on xamarin(C#) in pcl project. I am following this tutorial. On the Android Implementation (Step5) i get these errors:
Error CS0104 'Environment' is an ambiguous reference between 'Android.OS.Environment' and 'System.Environment' AlarmSQLite.Android c:\users\thomas\source\repos\AlarmSQLite\AlarmSQLite\AlarmSQLite.Android\SQLite_Android.cs 30 Active
Error CS0234 The type or namespace name 'Net' does not exist in the namespace 'SQLite' (are you missing an assembly reference?) AlarmSQLite.Android c:\users\thomas\source\repos\AlarmSQLite\AlarmSQLite\AlarmSQLite.Android\SQLite_Android.cs 33 Active
I use VisualStudio2017. I tried to remove .Net and added System.Environment but i get more and new errors.
My code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using SQLite;
using Xamarin.Forms;
using AlarmSQLite.Droid;
using System.IO;
[assembly: Dependency(typeof(SQLite_Android))]
namespace AlarmSQLite.Droid
{
public class SQLite_Android : ISQLite
{
public SQLite_Android() { }
public SQLite.SQLiteConnection GetConnection()
{
var dbName = "AlarmDB.db3";
var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var path = Path.Combine(documentsPath, dbName);
var platform = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid();
var connection = new SQLite.Net.SQLiteConnection(platform, path);
return connection;
}
}
}
Everything is the same with the tutorial. What am i doing wrong? Thank you!
New Errors:
Error CS0234 The type or namespace name 'Platform' does not exist in the namespace 'SQLite' (are you missing an assembly reference?) AlarmSQLite.Android C:\Users\Thomas\source\repos\AlarmSQLite\AlarmSQLite\AlarmSQLite.Android\SQLite_Android.cs 33 Active
Error CS0029 Cannot implicitly convert type 'SQLite.Net.SQLiteConnection' to 'SQLite.SQLiteConnection' AlarmSQLite.Android C:\Users\Thomas\source\repos\AlarmSQLite\AlarmSQLite\AlarmSQLite.Android\SQLite_Android.cs 36 Active
Error CS0104:
Environment comes from 'Android.OS.Environment' as well as 'System.Environment' so giving you and ambiguity issue. Just Prepend System to the Environment.
var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
Error CS0234: Seems like you haven't added SQLite-Async Nuget Package. You have to add this in your PCL as well as in Android project and build project again.
Error CS0234 & CS0029: Make sure you added following two nuget packages in android and pcl projects.
Then, instead of using Sqlite, try to use Sqlite.Net.
Your Final Code should Look :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Xamarin.Forms;
using AlarmSQLite.Droid;
using System.IO;
using SQLite.Net;
using SQLite.Net.Async;
[assembly: Dependency(typeof(SQLite_Android))]
namespace AlarmSQLite.Droid
{
public class SQLite_Android : ISQLite
{
public SQLite_Android() { }
public SQLiteConnection GetConnection()
{
var dbName = "AlarmDB.db3";
var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var path = Path.Combine(documentsPath, dbName);
var platform = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid();
var connection = new SQLiteConnection(platform, path);
return connection;
}
}
}
Do not forget to adjust your interface for the same. It should be like:
SQLiteConnection GetConnection():
Note: You can omit Sqlite.Net.Async PCL reference if you don't need it.
I get the following error when connecting to tfsapi using c#.I have the right credentials, url and added the dlls Microsoft.TeamFoundation.Client from
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0
& System.Net too. Any suggestions of what might be causing the issue ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using Microsoft.TeamFoundation.Client;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Uri url = new Uri("https://");
NetworkCredential nc = new NetworkCredential("", "", "");
TfsTeamProjectCollection coll = new TfsTeamProjectCollection(url, nc);
coll.EnsureAuthenticated();
}
}
}
Error :
"An unhandled exception of type 'System.Net.WebException' occurred in Microsoft.TeamFoundation.Clientdll Additonal information : The underlying connection was closed. Cound not establish trust relationship for the SSL/TSL secure channel"
I am trying to execute my Coded UI Scripts on QTP.
First I created a dll for my Coded UI Project later I am able to access the methods from that dll but i am not able to access Coded UI testing methods.
Example:
the below script is in C# in VSTS
namespace TestProject1
{
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Input;
using System.Windows.Forms;
using System.CodeDom.Compiler;
using System.Text.RegularExpressions;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
using MouseButtons = System.Windows.Forms.MouseButtons;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
using Microsoft.VisualStudio.TestTools.UITesting.WpfControls;
public partial class UIMap
{
public int MyInteger()
{
return 9;
}
public string testDll()
{
return "Test DLL Factory";
}
public void add1()
{
MessageBox.Show("Sravan");
}
public void DeletePhoto()
{
WinWindow window = new WinWindow();
window.SearchProperties[WinWindow.PropertyNames.Name] = "Cyramed";
window.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains));
WinWindow c_window = new WinWindow(window);
c_window.SearchProperties[WinWindow.PropertyNames.ControlName] = "PICTUREBOX1";
c_window.WindowTitles.Add("Cyramed");
c_window.DrawHighlight();
WinClient c_client = new WinClient(c_window);
c_client.WindowTitles.Add("Cyramed");
c_client.DrawHighlight();
Mouse.Click(c_client, MouseButtons.Right);
Keyboard.SendKeys("{DOWN}");
Keyboard.SendKeys("{DOWN}");
Keyboard.SendKeys("{DOWN}");
Keyboard.SendKeys("{ENTER}");
}
}
}
I can call MyInteger and testDll methods but when I call the DeletePhoto method it throws an error: "Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified."
My primary concern: I want to execute Coded UI scripts on QTP too.
You'll likely have to install Visual Studio Test Agents on your QTP test agents. These will drop the binaries on the machine.
VS 2010 Test Agents
VS 2010 SP1