You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[TestMethod]
[ExpectedException(typeof(ArgumentException), "A userId of null was inappropriately allowed.")]
public void NullUserIdInConstructor()
{
LogonInfo logonInfo = new LogonInfo(null, "P@ss0word");
}
Manual Compilation of Csharp code using Rosyln
Nuget package Microsoft.CodeAnalysis.CSharp
\\ A code.cs file has class "Greeter" and method "SayHello"
var code = File.readAllText("code.cs");
var tree = SyntaxFactory.ParseSyntaxTree(code);
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
var reference = new MetadataFileReference(typeof(object).Assembly.Location)
var compilation = CSharpCompilation.Create("test").WithOptions(options).AddSyntaxTrees(tree).AddReferences(reference);
var diagnostics = compilation.GetDiagnostics();
foreach (var diagnostic in diagnostics )
{
System.Console.WriteLine(diagnostic.ToString());
}
using stream(var stream = new MemoryStream())
{
compilation.Emit(stream);
var assembly = Assembly.Load(stream.GetBuffer());
var type = assembly.GetType("Greeter");
var greeter = Activator.CreateInstance(type);
var method = type.GetMethod("SayHello");
method.Invoke(greeter, null);
}