connecting to TFSAPI using C# - c#

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"

Related

System.InvalidProgramException Error C# when creating CIMSession

Trying to remotly connect to another PC's WMI but when creating the CimSession I get the following error
System.InvalidProgramException:'Common Launguage Runtime detexted an invalid program'
The code I am running is as follows
using System;
using System.Text;
using System.Threading;
using Microsoft.Management.Infrastructure;
using Microsoft.Management.Infrastructure.Options;
using System.Security;
namespace SMAPIQuery
{
class Program
{
static void Main()
{
string computer = "ComputerB";
DComSessionOptions DComOptions = new DComSessionOptions();
DComOptions.Impersonation = ImpersonationType.Impersonate;
CimSession Session = CimSession.Create(computer, DComOptions);
}
}
}
Unsure as to what throws this error or how to get around it
The issue was I was using .Net Core and not .Net Framework

SQLite Xamarin.Forms PCL errors on Android

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.

Windows.Storage error: the type of namespace Storage does not exist in namespace windows

I am very new to C#, visual studio, and related Microsoft work. So it is very likely that I messed something up and I hope some one can help me a bit on this.
I create an Console application and I am trying to run some tutorial C# code. There is a red line under when I try to load Windos.Storage.Pickers and all namespaces after it. I attempt to add the references, but I can't find what I need there.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.Graphics.Imaging;
using Windows.Media.FaceAnalysis;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Shapes;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
FaceDetector faceDetector;
IList<DetectedFace> detectedFaces;
FileOpenPicker photoPicker = new FileOpenPicker();
photoPicker.ViewMode = PickerViewMode.Thumbnail;
photoPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
photoPicker.FileTypeFilter.Add(".jpg");
photoPicker.FileTypeFilter.Add(".jpeg");
photoPicker.FileTypeFilter.Add(".png");
photoPicker.FileTypeFilter.Add(".bmp");
StorageFile photoFile = await photoPicker.PickSingleFileAsync();
if (photoFile == null)
{
return;
}
}
}
}
the namespace you are tying to use is use for UWP development.
The problem is that you are trying to use it in Console Development.
Read about it here

Lucene.Net Query Error

I've just installed Solr/Lucene on a Windows machine simply to test its capability. I've indexed a couple hundred files and I'm able to successfully query the indexed content through the web interface. Given that the web interface isn't too user friendly I thought I'd try to create a simple application to do a full text search over the indexed content. So far I have:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Lucene.Net;
namespace solrTest
{
class Program
{
static void Main(string[] args)
{
string indexFileLocation = #"C:\solr-5.3.1\server\solr\test\data\index";
Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.Open(indexFileLocation);
Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(dir);
Lucene.Net.Index.Term searchTerm = new Lucene.Net.Index.Term("ID", "1");
Lucene.Net.Search.Query query = new Lucene.Net.Search.TermQuery(searchTerm);
Lucene.Net.Search.TopDocs results = searcher.Search(query, null, 10);
foreach(Lucene.Net.Search.ScoreDoc test in results.ScoreDocs)
{
Console.WriteLine(test.ToString());
Console.ReadLine();
}
}
}
}
When running the code I receive an error stating:
An unhandled exception of type 'System.IO.IOException' occurred in Lucene.Net.dll
Additional information: read past EOF
I know I'm missing something obvious. Your help would be greatly appreciated.
Edit: I downloaded Luke.Net and received the same error.

Sharepoint authentication in C# not working

I'm trying to automate some menial tasks on sharepoint by creating C# code. I think the code is correct, however when running it, I get a 401 error stating that "The remote server returned an error: (401) Unauthorized."
The credentials of the user Im using in the code has full control access over the list in question, and can perform the tasks in the code through the UI. This is the first time im programming C# so any help would be greatly appreciated!
using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
namespace ConsoleApplication3
{
class Program
{
static void Main()
{
ClientContext context = new ClientContext("websiteURL");
context.Credentials = new NetworkCredential("user", "pasword", "domain");
List oList = context.Web.Lists.GetByTitle("TestBI");
ListItem oListItem = oList.GetItemById(0);
for (int i = 0; i < 3; i++)
{
oListItem = oList.GetItemById(i);
oListItem.BreakRoleInheritance(true, false);
}
context.ExecuteQuery();
}
}
}
Since you're not using a domain account, so the way to create a NetworkCredential should be:
context.Credentials = new NetworkCredential("user", "pasword");

Categories

Resources