csharpcodeprovider: Can't use Process.Start() - c#

So I'm making a WPF application where I'm using CSharpCodeProvider to compile code stored in string. Everything works great except for one part. When I try to use Process.Start(), it gives me "Metadata file 'System.Diagnostics.dll' could not be found" error. I don't know what that means.
using Microsoft.CSharp;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Dynamically_compile_codes
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
CSharpCodeProvider codeProvider = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", txtFrameWork.Text } });
Button button = (Button)sender;
CompilerParameters parameters = new CompilerParameters(new[] { "mscorlib.dll","System.Core.dll","System.Diagnostics.dll"}, txtOutput.Text,true);
//generate exe, not dll
parameters.GenerateExecutable = true;
CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, textBox.Text);
if (results.Errors.HasErrors)
{
results.Errors.Cast<CompilerError>().ToList().ForEach(error=> txtStatus.Text+=error.ErrorText+"/r/n");
}
else
{
//If we clicked run then launch our EXE
Process.Start(txtOutput.Text);
}
}
}
}
And here is the code that is stored in the string:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace Hidden_Console_Application
{
class Program
{
static void Main(string[] args)
{
Process.Start("explorer.exe");
}
}
}

System.Diagnostics is a namespace that resides in the System.dll assembly. The CompilerParameters constructor expects a string collection of assembly names and is therefore looking for a loaded assembly named System.Diagnostics which does not exist.
Should be:
CompilerParameters parameters = new CompilerParameters(new[] { "mscorlib.dll","System.Core.dll","System.dll"}, txtOutput.Text,true);

Related

ChromiumWebBrowser.IsLoaded is not available

Below is my code extract relative to the problem
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Timers;
using System.Threading.Tasks;
using System.Web.UI.Design;
using System.Windows;
using System.Windows.Forms;
using cef;
using CefSharp;
using CefSharp.WinForms;
public partial class Form1 : Form
{
//browser variables
public ChromiumWebBrowser chrome;
public Form1()
{
InitializeComponent(); InitBrowser(); this.WindowState =System.Windows.Forms.FormWindowState.Maximized;
}
public void InitBrowser()
{
chromeheight = this.Height-100;
chromewidth = this.Width;
Cef.Initialize(new CefSettings()); chrome = new ChromiumWebBrowser("correct url here");
this.Controls.Add(chrome); chrome.Anchor = AnchorStyles.Left;
chrome.Size = new Size(chromewidth, chromeheight);
chrome.Location = new Point(0, 100);
chrome.LoadingStateChanged += chrome_LoadingStateChanged;
}
public void chrome_LoadingStateChanged(object sender,LoadingStateChangedEventArgs e)
{
//the problem!!!
chrome....
}
}
the problem is at the last line. When I type chrome.IsLoaded, the IsLoaded option is not available. Everything else works fine.
below is the error I get.
Error 17 'CefSharp.WinForms.ChromiumWebBrowser' does not contain a
definition for 'IsLoaded' method 'IsLoaded' accepting a first argument of
type 'CefSharp.WinForms.ChromiumWebBrowser' could be found (are you missing
a using directive or an assembly reference?)
What am I doing wrong?

I thought only usercontrol can navigate page inside a window frame in WPF app, is there any workarounds?

I am trying to jump to an error page if reading data fails, although I thought only if usercontrol activates(eg. button pressed) can successfully navigate, but is there anyway to do it automactally?
Window
|--Page
|--Page
Windows
--Page
--Page
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
namespace Launcher
{
/// <summary>
/// Interaction logic for BootPage.xaml
/// </summary>
public partial class BootPage : Page
{
public BootPage()
{
InitializeComponent();
readConfig();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
bootError(1001); **//This works**
}
void readConfig()
{
string gamePath;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("e:\\bootstrap.xml");
XmlNodeList boot = xmlDoc.DocumentElement.SelectNodes("/config/startup/arkkdmca/boot");
foreach (XmlNode node in boot)
{
try
{
gamePath = node.SelectSingleNode("drive").InnerText + ":\\" + node.SelectSingleNode("directory").InnerText;
MessageBox.Show(gamePath);
}
catch(Exception)
{
gamePath = "null";
bootError(1001); **//This Failed**
return;
}
}
}
void bootError(int errorCode)
{
this.NavigationService.Navigate(new ErrorPage(errorCode));
}
}
}

C# Trying to find the RobloxPlayerBeta

Here is my code: I am trying to find the roblox PlayerBeta but its not working
I am not the best in coding but I found out how to find it but cant implent it right into the code
( EDIT ) The program works if I use the PID but that changes everytime I open up a new RobloxPlayerBeta ! so I cannot use that
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Memory;
using System.Diagnostics;
namespace ForceField
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Mem MemLib = new Mem();
private void button1_Click(object sender, EventArgs e)
{
if (System.Diagnostics.Process.GetProcesses().Any((p) => p.ProcessName.Contains("RobloxPlayerBeta")))
{
int robloxPid = System.Diagnostics.Process.GetProcessesByName("RobloxPlayerBeta").FirstOrDefault().Id;
}
Console.WriteLine(robloxPid);
MemLib.writeMemory("0x184C3A98", "string", "PlsNoBan ");
Console.WriteLine(MemLib.readString("0x184C3A98"));
}
}
}
Omg I am stupid.. xD
I needed to do MemLib.OpenGameProcess(robloxPid)

Access ViewModel of a wpf dll

I have a wpf MultiROIStats.dll with mode, view, ViewModel. Here is the C# of the view:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace MultiROIStats
{
using ViewModel;
//xmlns:dg="clr-namespace:Microsoft.Windows.Controls;assembly=WpfToolkit"
/// <summary>
/// Interaction logic for MultiROIStats.xaml
/// </summary>
public partial class MultiROIStats : Window
{
public MultiROIStats()
{
InitializeComponent();
DataContext = new MultiROIStatsViewModel();
}
}
}
To use this MultiROIStats,dll, I insert it info the reference of another project. Now I need to access the ViewModel (some methods there) of the inserted MultiROIStats.dll. I am wondering how should I do this? I initiated an object of the inserted MultiROIStats.dll, but cannot find the method I want to use in its ViewModel:
private void btnSave_Click(object sender, RoutedEventArgs e)
{
MultiROIStats mroi = new MultiROIStats();
mroi.Show();
// here should be mroi.viewmode.dothings() ... but I don't know how to access it
}
You should be able to get to it by casting the DataContext to the view-model type:
MultiROIStats mroi = new MultiROIStats();
mroi.Show();
var viewmodel = mroi.DataContext as MultiROIStatsViewModel;
if (viewmodel != null)
viewmodel.dothings();
var window = new MultiROIStats();
window.Show();
var vm = window.DataConntext as MultiROIStatsViewModel;
vm.DoThings();

System.Windows.Media.Animation.AnimationTimeline)' is inaccessible due to its protection level

Hi I am trying to programmatically control a WPF animation but am getting the error above, could someone help with the error - not very familiar with c# - thanks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
namespace WpfApplication10
{
///
/// Interaction logic for Window1.xaml
///
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
AnimationClock clock;
void StartAnimation()
{
DoubleAnimation animate = new DoubleAnimation();
animate.To = 300;
animate.Duration = new Duration(TimeSpan.FromSeconds(5));
animate.RepeatBehavior = RepeatBehavior.Forever;
clock = animate.CreateClock();
test.ApplyAnimationClock(Ellipse.WidthProperty, clock);
}
void PauseAnimation()
{
clock = new AnimationClock();
clock.Controller.Pause();
}
void ResumeAnimation()
{
clock.Controller.Resume();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
PauseAnimation();
}
}
}
It means you cannot create an instance of the "clock" object using "new". You can do it using the animation.CreateClock() method like the one in your StartAnimation() method. Anyway, a little tweak on your code should make it work. Hope the code below gives you an idea:
using System;
using System.Windows.Media.Animation;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
namespace WpfApplication10 { /// /// Interaction logic for Window1.xaml ///
public partial class Window1: Window
{
public Window1()
{
InitializeComponent();
DoubleAnimation animate = new DoubleAnimation();
animate.To = 300;
animate.Duration = new Duration(TimeSpan.FromSeconds(5));
animate.RepeatBehavior = RepeatBehavior.Forever;
clock = animate.CreateClock();
}
AnimationClock clock;
void StartAnimation()
{
test.ApplyAnimationClock(Ellipse.WidthProperty, clock);
}
void PauseAnimation()
{
clock.Controller.Pause();
}
void ResumeAnimation()
{
clock.Controller.Resume();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
StartAnimation();
}
}
}

Categories

Resources