Hi I am trying to analyze my CsProj using Roslyn. I'm having issues finding my solution. This is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.MSBuild;
namespace Test
{
class Programm
{
static async Task Main(string[] args)
{
SourceAnalyzer sa = new SourceAnalyzer();
string path = #"C:\Users\lhafer\source\repos\Farm\Farm\Farm.csproj";
using (var workspace = MSBuildWorkspace.Create())
{
var project = await workspace.OpenProjectAsync(path);
var compilation = await project.GetCompilationAsync();
}
//sa.Analyze(path).Wait();
}
}
}
the Exception says:
System.Reflection.ReflectionTypeLoadException: "Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Thank you for your help!
Related
c# File handler error.I can't find it.
use SafeFileHandle filehandle -> error
I tried to copy it, but it didn't work out well.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Microsoft.Win32.SafeHandles;
namespace test
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("검색할 경로를 입력하세요.");
string result1 = Console.ReadLine();
Console.WriteLine("파일 확장자를 입력하세요.");
string result2 = Console.ReadLine();
Filehandle file1 = new Filehandle();
file1.FileCheck(result1,result2);
}
}
You need to install the package in your project before you can use it.
dotnet add package Microsoft.Win32.SafeHandles
Full Script (More details below)
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using System.IO;
using System.Windows.Forms;
namespace BuildShare
{
class BuildSaveHandler
{
public static void ExportSaveToFile(Build.BuildSave save)
{
SaveFileDialog SaveToFile = new SaveFileDialog();
SaveToFile.FileName = save.saveName + ".txt";
SaveToFile.Filter = "Text File | *.txt";
SaveToFile.ShowDialog();
if (SaveToFile.ShowDialog() == DialogResult.OK)
{
StreamWriter writer = new StreamWriter(SaveToFile.OpenFile());
writer.WriteLine(JsonUtility.ToJson(save));
writer.Dispose();
writer.Close();
}
}
}
}
When I run ExportSaveFile, I get "Could not load type 'ThreadContext' from assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'". I simply run it by calling ExportSaveFile(etc.). Might I be missing required assemblies? The folder I'm running the application from only has access to the System.Windows.Forms.dll + other required assemblies.
This is an individial C# project and is being compiled into a dll. It uses the 4.61 .Net Framework.
You can't use SaveFileDialog (or any System.Windows.Forms dialogs) in Unity3D.
Instead, use EditorUtility.SaveFilePanel.
I’m running Visual Studio 2015 and Windows 8.1. I am struggling with a console application project.
The solution works fine in Visual Studio 2015, but when I try to compile it with mcs-compiler I get two errors (Kattis codetest use mcs-kompiler). Two external classes can not be found.
I'm getting the following error:
Program.cs(28,13): error CS0246: The type or namespace name Graph'
could not be found. Are you missing an assembly reference?
Program.cs(58,34): error CS0246: The type or namespace nameSolver'
could not b e found. Are you missing an assembly reference?
Compilation failed: 2 error(s), 0 warnings
The code is large so a I have pasted in just parts of it:
The Program class, where main is and the calls to ”Graph” and ”Solver” are made from:
Call in Program.cs:
-----------------------------------------------------------------------------
// first call:
var edges = CliquesToEdges(cliques);
sudokuColour.Graph graph = new Graph(81, edges);
string line = "";
string storeLine = "";
string puzzle = "";
.
.
.
// second call:
for (int i = 0; i < store.Count(); i++)
{
puzzle = store.ElementAt(i);
sudokuColour.Solver solver = new Solver(graph, 9);
int node = -1;
foreach (char c in puzzle)
{
----------------------------------------------------------------------------
//Beginning of "Graph" class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using sudokuColour;
namespace sudokuColour
{
public class Graph
{
.
.
----------------------------------------------------------------------------
//Beginning of "Solver" class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using sudokuColour;
namespace sudokuColour
{
public class Solver
{
private enum Result { Solved, Unsolved, Busted }
private readonly Graph graph;
----------------------------------------------------------------------------
What can the error be?
sudokuColour.Solver solver = new Solver(graph, 9);
The fact that you had to namespace-qualify it on the left probably means you should namespace-qualify it on the right too:
sudokuColour.Solver solver = new sudokuColour.Solver(graph, 9);
Alternatively, add a using directive at the top of the code file:
using sudokuColour;
or:
using Solver = sudokuColour.Solver;
likewise for:
sudokuColour.Graph graph = new Graph(81, edges);
If that still doesn't work: you're probably missing a project reference (or package reference, or assembly reference - but a project reference seems the most appropriate) between the two projects.
In the below code for selenium webdriver , I get an error for wait.until
when running the program in debug mode
the reference are as follows
IEEXECRemote
nunit.framework
Selenium.Webdriverbackedselenium
System
System.data
System.xml
Thoughtworks.selenium.core
webdriver
webdriver.support
The error I get is like this
Error 4 The type 'System.Func`2<T0,T1>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. F:\AutomationProjects\Selenium\Webautomate\Webautomate\DragandDropWebElement.cs 37 1 Webautomate
How do I solve this error ?. Can I get any reference to add to the solution
I tried to add System.core , but it said that it is already present and was not accepting it
I did some research on Google but could not solve the problem and hence I am asking here .
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
using System.Collections.ObjectModel;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Interactions.Internal;
namespace Automation
{
class DragandDropWebElement
{
static void Main(string[] args)
{
IWebDriver driver=null;
try
{
driver = new FirefoxDriver();
driver.Url = "http://www.google.co.in";
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(10));
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.TitleContains("Google"));
string title = driver.Title;
System.Console.WriteLine("Title is :" +title);
Actions builder = new Actions(driver);
IWebElement e1 = driver.FindElement(By.CssSelector("#gbqfq"));
IWebElement e2 = driver.FindElement(By.PartialLinkText("Hindi"));
bool displayed = e1.Displayed;
bool enabled = e1.Enabled;
string text = e1.Text;
System.Console.WriteLine(" The inner Text of e1 is : " +enabled );
}
catch(Exception e){
Console.WriteLine("Exception ******"+e.ToString());
}
finally{
Thread.Sleep(2000);
driver.Quit();
Console.ReadLine();
}
}
}
}
I'm new to C# and I'm new to Speech.Recognition.
I searched very long for tutorials but didn't find that much, I'm even not quiet sure whether I included everything correctly.
I downloaded:
SDK
Runtime
Languages
I'm programming local, I have Windows XP, .net framework 3.5.
Now I just want to get started with some simple lines of code, like to say "hello world" or say one or two words as input.
I tried following, and of course it doesn't work :>
error:
"The Typ- or Namespacename "SpeechSynthesizer" couldn't be found (Is a Using-Direktive or a Assemblyverweis missing?)"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SpeechSynthesizer foo = new SpeechSynthesizer();
foo.Speak("Test");
}
}
}
edit:
hello,
i tried you code,but
using SpeechLib;
couldn't be found :>
well now i wrote:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.SpeechLib;
namespace System.SpeechLib { }
namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }
but I get an error with:
numericUpDown1,SpVoice,SpeechVoiceSpeakFlags,textBox1 and Timeout
Project + Add Reference, .NET tab, select "System.Speech".
A project template pre-selects several .NET assemblies. But only common ones, like System.dll, System.Core.dll, etcetera. You have to add the 'unusual' ones yourself.
you can try this:
get Interop.SpeechLib.dll
using SpeechLib;
private void ReadText(string readText)
{
int iCounter = 0;
while (Convert.ToInt32(numericUpDown1.Value) > iCounter)
{
SpVoice spVoice = new SpVoice();
spVoice.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
spVoice.WaitUntilDone(Timeout.Infinite);
iCounter = iCounter + 1;
}
}