I am trying to create a graph with C# and the WPF chartingToolkit, I have the following code:
LineSeries lineSeries1 = new LineSeries();
lineSeries1.Title = region;
lineSeries1.DependentValuePath = "Value";
lineSeries1.IndependentValuePath = "Key";
lineSeries1.ItemsSource = points;
this.Graph.Series.Add(lineSeries1);
where points is a Dictionary<string, int> created in earlier code. This code compiles fine and runs fine until it reaches the line LineSeries lineSeries1 = new LineSeries();. Upon reaching this line it throws a Source Not Found: LineSeries.cs not found exception. I have tried putting it as System.Windows.Controls.DataVisualization.Charting.LineSeries lineseries1 = new System.Windows.Controls.DataVisualization.Charting.LineSeries(); but that failed to fix the issue. Everywhere I look for examples of how to do this it is written exactly how I have it.
EDIT:
It works perfectly without the debugger. The problem only exists with it.
The debugger was looking for a source file but was not able to find it. This will have been either because you don't have it available or because the version of the source you have does not exactly match the version which was compiled into your library.
If the latter is the case, you can work around it by going to Tools -> Options -> Debugging and unchecking the "Require source files to exactly match the original version" option.
Related
Recently, my application has crashed when trying to display a rather lengthy (but otherwise simple) HTML e-mail.
The crash was caused by mshtml.dll getting a stack overflow (exception code 0xc00000fd). Of note here is that this didn't throw an exception but it actually just crashed the program as a whole. The error was retrieved from the Windows event log.
In the process of debugging, I created a smaller sample solution to try and narrow down the issue. However, not only does it work fine in the sample solution, it behaves completely different from the main program despite running the same code even for the simplest of HTML strings.
The code is as follows:
var webBrowser1 = new System.Windows.Forms.WebBrowser();
webBrowser1.AllowNavigation = false;
webBrowser1.AllowWebBrowserDrop = false;
webBrowser1.Navigate("about:blank");
var doc = webBrowser1.Document.OpenNew(true);
doc.Write("<HTML><BODY>This is a new HTML document.</BODY></HTML>");
var count = doc.All.Count;
var html = doc.All[0].OuterHtml;
In the sample solution this evaluates to:
count = 4; // [HTML, HEAD, TITLE, BODY]
html = "<HTML><HEAD></HEAD>\r\n<BODY>This is a new HTML document.</BODY></HTML>";
Meanwhile in the main program it comes out to:
count = 3; // [HTML, HEAD, BODY]
html = "<html><head></head><body>This is a new HTML document.</body></html>";
These are small discrepancies but that is largely due to the simple HTML used. The one that causes the crash has rather significant differences.
I am absolutely stumped as to how the result can be so vastly different.
The documentation for HtmlDocument.Write(string) states that:
It is recommended that you write an entire valid HTML document using the Write method, including HTML and BODY tags. However, if you write just HTML elements, the Document Object Model (DOM) will supply these elements for you.
But I have no idea how the DomDocument is provided nor why they would be different in the first place. Both solutions are running in x64 Debug mode and Net-Framework 4.6.2.
Both load the module: C:\WINDOWS\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\Microsoft.mshtml.dll
How is it possible that these produce different results?!
Any and all help welcome.
Thanks in advance.
The difference in behavior stems from the registry entry as proposed by Jimi and linked here
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
To reiterate, in the above registry the main program had an entry "ApplicationFileName.exe"=dword:00002af9 while my new test-application didn't.
This, in and for itself, does not explain the crashing of mshtml.dll itself but since the question was about the difference in behavior I'll post this as the answer. The crash is most likely linked to the outdated version used by Visual Studio but I haven't yet had the chance to look into some of the proposed fixes for that.
I am writing a C# extension for Visual Studio and I am trying to use the new API for QuickInfos: https://github.com/Microsoft/vs-editor-api/wiki/Modern-Quick-Info-API. I am prototyping based on this sample: https://github.com/microsoft/VSSDK-Extensibility-Samples/tree/master/AsyncQuickInfo. It works fine as long as I don't change it.
The sample is only focusing on the whole line:
var line = triggerPoint.Value.GetContainingLine();
However, I need to get the hovered word. In the old API, I was using this and it was working fine:
var navigator = provider.NavigatorService.GetTextStructureNavigator(buffer);
var hoveredWord = navigator.GetExtentOfWord(triggerPoint.Value);
Unfortunately, Visual Studio will freeze as soon as I call GetExtentOfWord with the new API!!! More precisely, I will pass a few times and then it will freeze (quite shortly).
What should do I to be allowed to get the hovered word extent with the new IAsyncQuickInfoSource API?
Thanks!
If anyone is familiar with libSVM (https://www.csie.ntu.edu.tw/~cjlin/libsvm/), I am working with libSVMsharp, which is the same thing, in a C# wrapper, I believe.
On their github, they give the following example of how to write a simple classification, using the SVM:
SVMProblem problem = SVMProblemHelper.Load(#"dataset_path.txt");
SVMProblem testProblem = SVMProblemHelper.Load(#"test_dataset_path.txt");
SVMParameter parameter = new SVMParameter();
parameter.Type = SVMType.C_SVC;
parameter.Kernel = SVMKernelType.RBF;
parameter.C = 1;
parameter.Gamma = 1;
SVMModel model = SVM.Train(problem, parameter);
double target[] = new double[testProblem.Length];
for (int i = 0; i < testProblem.Length; i++)
target[i] = SVM.Predict(model, testProblem.X[i]);
double accuracy = SVMHelper.EvaluateClassificationProblem(testProblem, target);
That all makes perfect sense, loading in the training data with its path specified, and same with the test data...Well, that's where I run into problems.
I wanted to test this out in C# just to ensure my full understanding of how this works, before implementing it in a larger project that I've been working on. I have a small program called Program.cs (very original, I know), and in the SAME FOLDER, I have train.txt and test.txt. So we have a folder that contains Program.cs, train.txt, and test.txt, along with some other standard stuff that is created when you make a project in Visual Studio.
So that snippet of my code looks like this:
SVMProblem trainingSet = SVMProblemHelper.Load(#"train.txt");
SVMProblem testSet = SVMProblemHelper.Load(#"test.txt");
trainingSet = trainingSet.Normalize(SVMNormType.L2);
testSet = testSet.Normalize(SVMNormType.L2);
and so on. However, when I run this, it basically says that the variable "trainingSet" is null, because SVMProblemHelper never actually managed to load train.txt.
I feel like there is a glaringly obvious solution to this, but I'm completely lost. I'm not entirely sure what's going wrong, here. In the SVMProblemHelper.Load function, it basically says that it will set the variable (in this case, trainingSet) equal to null if it cannot find the file in question. But how is it not finding the file? It's in the same directory as the .cs file. I'm not sure what I'm missing but I can't figure it out.
Any help is gladly welcomed!
Me and some of my colleagues are working on a project together, and have encountered a weird issue we can't manage to fix.The project involves the creation of a VNC connection between a client and a server, and is written in C# (we're using Visual Studio 2010). We're using the VNCSharp library for the client.The issue I speak of is that once we start the connection with the server, an ArgumentException is thrown.
Some of the information supplied was this:
********** Exception Text **********
System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at VncSharp.RemoteDesktop.SetupDesktop()
at VncSharp.RemoteDesktop.Initialize()
at VncSharp.RemoteDesktop.Connect(String host, Int32 display, Boolean viewOnly, Boolean scaled)
at VncSharp.RemoteDesktop.Connect(String host)
at RemoteDesktopTest.Form2.startConnection()
Another weird thing about this is that it only occures some of the times, whereas in others it works perfectly well. Specifically, it always works when run in debug mode (i.e, when we run the program line-by-line using F11), and either works or doesn't work when run regularly (i.e Ctrl+F5), without any pattern we could recognize.
We would be really grateful for any and all help; if there are any details I can add that would assist in the answering of this question, please let me know.
Additionally, I apologize for any grammar/spelling mistakes; English is not my first language... and I also apologize if something about this question is not alright. We're all beginners and this is our first "big project", so this is also my first time asking a question in Stack Overflow.
EDIT:
There are some parts of the code that are potentially relevant.
These are the lines of code automatically generated after we added the VncSharp control to the form and customized its settings:
this.remoteDesktop1 = new VncSharp.RemoteDesktop();
this.remoteDesktop1.AutoScroll = true;
this.remoteDesktop1.AutoScrollMinSize = new System.Drawing.Size(608, 427);
this.remoteDesktop1.Dock = System.Windows.Forms.DockStyle.Fill;
this.remoteDesktop1.Location = new System.Drawing.Point(0, 0);
this.remoteDesktop1.Name = "remoteDesktop1";
this.remoteDesktop1.Size = new System.Drawing.Size(1113, 580);
this.remoteDesktop1.TabIndex = 1;
This is the line of code in which I call the Connect method, while IP is simply the string taken from a text box:
remoteDesktop1.Connect(this.IP);
These are from the method which handles the ConnectComplete event (e is the EventArgs object passed to the method):
this.Location = new Point(0,0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
this.remoteDesktop1.Size = new System.Drawing.Size(e.DesktopWidth, e.DesktopHeight);
Aside from the line in which the Disconnect method is called, we've written literally no other lines of code that deal with this object. If I'll realize I'd forgotten something, I'll edit again and add it. Also, if there's anything specific in the code I should add here, please let me know.
The issue was related to timing, it seems.
Out of debug mode, the program ran too fast and those width and height variable didn't have their values updated.
Luckily, VncSharp is open source, so I could add my own line and leave it in a loop as long as either of those two variables still has its default value, and now it works.
Thanks for the help, everyone :)
Had the same problem. For me it worked to compile the vncsharp solution in debug mode.
In RfbProtocol line 398 (first line of the ReadServerInit method), I transformed
int w = Reader.ReadUInt16();
to
int w = 0;
while (w == 0)
w = Reader.ReadUInt16();
I'm trying to do some simple DOM manipulation when a page is rendered as a PDF using ABCPdf. I followed what they document here: http://www.websupergoo.com/helppdf9net/source/5-abcpdf/xhtmloptions/2-properties/usescript.htm
But when I try something as simple as the following:
var doc = new Doc();
doc.HtmlOptions.UseScript = true;
doc.HtmlOptions.UseNoCache = true;
doc.HtmlOptions.PageCachePurge();
doc.HtmlOptions.OnLoadScript = #"var reportElms = document.getElementsByClassName(""report"");";
doc.Page = doc.AddPage();
doc.AddImageUrl(Url.Action("TestPdf", "Pdf", new { }, "http"));
I get the exception:
Unable to render HTML. Unable to apply JScript.
COM error 80020101.
Script 'var reportElms = document.getElementsByClassName("report");'.
Any thoughts as to what I'm doing wrong?
Not even the built in functions work
I'm even getting the same exception with the following script:
doc.HtmlOptions.OnLoadScript = #"
window.ABCpdf_RenderWait();
window.ABCpdf_RenderComplete();";
Btw, I'm using version 8 because that's what we have a licence for.
Edit:
I was missing the .external for the ABCpdf_RenderWait() and ABCpdf_RenderComplete() calls. It works if you reference them properly (imagine that):
doc.HtmlOptions.OnLoadScript = #"
window.external.ABCpdf_RenderWait();
window.external.ABCpdf_RenderComplete();";
Though as I mention in my answer, there are a lot of security hoops that need to be jumped through for IE also.
So I didn't actually get the IE engine to execute JavaScript the way I wanted but I was able to find a solution using the Gecko engine. The original NuGet install did not include the Gecko DLL, so I just downloaded the standalone install and added the DLLs manually.
After that everything worked exactly as expected.
I believe that the IE engine didn't work because it requires a lot of security configuration, because the FAQs spend a lot of time discussing debugging of security: http://www.websupergoo.com/support.htm#6.7