This question already has an answer here:
Show an HTML file of my Project in WebBrowser control at run-time
(1 answer)
Closed 3 years ago.
I'm working on a Winforms project and want to display the About page content from an HTML file.
I used the WebBrowser control for that but even though it works, I still get the following error message upon opening the solution or building the project:
Error Message
Is there any way to fix it or ignore it?
Here's the method call from the About page class:
private void displayAboutContent()
{
this.labelVersion.Text = string.Format(#"Version: {0}",BoostEngine.r_CurrentVersion);
UITools.displayHTMLPage(m_WebBrowser, m_ResourceName);
}
and the UI Tools static class:
public static class UITools
{
public static void displayHTMLPage(WebBrowser i_WebBrowser, string i_ResourceName)
{
Uri uri = new Uri(getFilepath(i_ResourceName));
i_WebBrowser.ScriptErrorsSuppressed = true;
i_WebBrowser.Navigate(uri);
}
private static string getFilepath(string i_ResourceName)
{
string projectPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
string filePath = Path.Combine(projectPath, string.Format("Resources\\{0}.html", i_ResourceName));
return filePath;
}
}
P.S.
I'm using this code on another form but receive the error only for the About page.
Also important to note, I'm using a Parallels VM on Mac.
Thanks!
I don't know what is running code during solution load or compile, you might look in your project file for any targets that have been added.
But to simply get around the problem you could choose to not Navigate if the file doesn't exist:
if(System.IO.File.Exists("c:\\whatever"))
{
i_WebBrowser.Navigate(uri);
}
If you do that you might consider loading a page that is guaranteed to be there or load a string of html to make it a little more user friendly with an appropriate message.
Related
I have recorded web performance test in VS 2015 and added Form Post parameter in one web performance project.
I have one more C# class library project already exists in my solution. Now I wish to read this Form Post Parameter value in a C# class file so that I can make it dynamic.
Can anyone suggest how can I read that.
Currently it is being read hard coded as
public override void PreWebTest(object sender, PreWebTestEventArgs e)
{
Object obj = null;
obj = e.WebTest.Context["XXXX"];
...
}
Here I wish to put the value of the object from Form Post Parameter set in my recorded Webtest
I am trying to build a simple Python Editor with ScintillaNET and am now trying to return the input.
I have a class PythonScriptView:
public class PythonScriptView : Scintilla
{
// setup python syntax highlighting
}
and a Form which consists of a PythonScriptView component and an OK button. Inside this class I want to build a function which shows the form and returns the Text property of my PythonScriptView. I did this for another small dialog window which uses a textbox as input field and are now trying the same with the scintilla editor:
public string GetUserInput()
{
ShowDialog();
return ScriptView.Text; // ScriptView is of Type PythonScriptView
}
When I am running the app I get the following error message:
An unhandled exception of type 'System.AccessViolationException' occurred in ScintillaNET.dll
Does anyone know how to solve this? How else can I read the Text property?
Edit:
Seems like I cannot access any properties or methods from this class
I was having this same issue and it appears that due to the way ScintillaNET works you are not able to access any properties once the element is disposed do to the form closing. I found a work around by adding the following event and property to my Form.
private void FormClosing(object sender, FormClosingEventArgs e)
{
CachedText = scintilla.Text;
}
public string CachedText { get; private set; }
VS2012 for desktop .net framework 4.5 normal windows forms applications, not WPF
Hello, I tried to search for an answer, but I'm not sure of the correct terminology. I've managed to break my code, and can't understand what I've done wrong. (i didn't think i had changed anything, but ...)
I have a solution which contains 2 projects. The first project is an executable program, and the second is a DLL, which is loaded at run time and used by the first project.
the first project contains a form, and a static class with public static strings in the same namespace. (and some other unconnected classes). specifically:
namespace project1_namespace
{
static class settings
{
public static string some_words = "some words in a string";
}
class dll_callback{
//.. some public methods here
}
dll_callback dllcallback; // instance is initialised in the code (not shown)
Form form;
public partial class frm_splash : Form
{
private void frm_splash_FormClosing(object sender, FormClosingEventArgs e)
{
// this function actually loads the DLL, ensuring its the last step
//... some error checking code removed for brevity
Assembly assembly = Assembly.LoadFrom("c:\dllpath\project2.dll");
Type type_init = assembly.GetType("project2_class");
object init = Activator.CreateInstance(type_init, form, dllcallback);
//... some error checking code removed for brevity
}// end method
}// end form class
}// end namespace
when the form is closing, the method shown above is called which calls the second projects class project2_class constructor.
in project 2, the DLL, there is:
namespace project2_namespace
{
// how did i get this working to reference "settings" class from project 1??
public class project2_class
{
public project2_class(project2_namespace.Form1 form_ref, object callback)
{
settings.some_words = "the words have changed";
//... some more stuff
}
}
}
Now, i was experimenting with some code in an entirely different part of project2, and VS2012 suddenly started refusing to compile stating:
error CS0103: The name 'settings' does not exist in the current context
the standard solution to this appears to be to add a reference to project2, but that would create circular dependencies because project 1 calls 2 as a DLL.
I really honestly don't think i had changed anything relevant to this, but also clearly I have.
looking at it, i cant see how project 2 would have access to a class in project 1 without a reference, but the list of arguments to the project2_class constructor doesn't include one, and I am absolutely positive that it hasn't changed (and I cant change it for backwards compatibility reasons).
would really appreciate help with this, as its been a lot of work to get this working.
as a side note, I've definitely learned my lesson about not using source control. and not making "how this works" comments instead of "what this does" comments.
may dynamic help you? You can not get the setting string at complie time.
I'm writing a game where I want to use ContentTypeReader. While loading my model like this:
terrain = Content.Load<Model>("Text/terrain");
I get following error:
Error loading "Text\terrain". Cannot find ContentTypeReader
AdventureGame.World.HeightMapInfoReader,AdventureGame,Version=1.0.0.0,Culture=neutral.
I've read that this kind of error can be caused by space's in assembly name so i've already removed them all but exception still occurs.
This is my content class:
[ContentTypeWriter]
public class HeightMapInfoWriter : ContentTypeWriter<HeightmapInfo>
{
protected override void Write(ContentWriter output, HeightmapInfo value)
{
output.Write(value.getTerrainScale);
output.Write(value.getHeight.GetLength(0));
output.Write(value.getHeight.GetLength(1));
foreach (float height in value.getHeight)
{
output.Write(height);
}
}
public override string GetRuntimeType(TargetPlatform targetPlatform)
{
return
"AdventureGame.World.Heightmap,AdventureGame,Version=1.0.0.0,Culture=neutral";
}
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
return
"AdventureGame.World.HeightMapInfoReader,AdventureGame,Version=1.0.0.0,Culture=neutral";
}
}
Does anyone meed that kind of error before?
I have been encountering the same problem for a week, and finally decided to do a quick check on the whole "assembly" part.
I found a fix!
Essentially, when you go into AssemblyInfo.cs, you will see all the properties(ie Title, Description, etc.)
The Title, sadly made by XNA, is NOT what your runtime reader refers to. Its actually getting the initial name of the project, which it uses to track back to your application (exe) file in your project. Try either re-making your project from scratch, making sure to keep your namespace the same as your project and never change it , or give a go at re-naming your exe file, found in the debug/obj folder in your project(i believe). hope I helped!
-Will
I have come across the most curious problem ever as .Net dev. I am compiling a library which has a newly added property DeviceID in the class of UserInfo. The library internally uses the type and it's new property just fine, but when I try and reference it from another library, the compiler kicks back a compiler error stating
'library.UserInfo' does not contain a definition for 'DeviceID' and no extension
method 'DeviceID' accepting a first argument of type 'library.UserInfo' could
be found
Even though my class definition looks like:
public class UserInfo
{
public static UserInfo Current
{
get
{
if (UserInfoPrincipal.Current != null)
{
return UserInfoPrincipal.Current.UserData;
}
else
{
return null;
}
}
}
public string UserID { get; set; }
public string DeviceID { get; set; }
public string MikeLiUserID { get; set; }
public string TransactionServer { get; set; }
public string ApplicationKey { get; set; }
public string IpAddress { get; set; }
}
The offending code reads as such:
internal LogDetail BuildLogDetail(LogType entryType, string message)
{
return new LogDetail
{
ActingUserID = UserInfo.Current.UserID,
ActingDeviceID = UserInfo.Current.DeviceID,
ApplicationKey = UserInfo.Current.ApplicationKey,
IpAddress = UserInfo.Current.IpAddress,
EntryType = entryType,
OwnerID = UserInfo.Current.UserID,
LogData = message
};
}
I'd like to note that all of the other members of the UserInfo class go through the compiler correctly and it is just the DeviceID, which was added today, is causing the issue. I've tried Clean All, I've tried refreshing everything from TFS, manually deleting the obj and bin directories of both projects... nothing yet has worked.
UPDATE: This code, which is part of the library, works correctly:
public class UserInfoPrincipal : IPrincipal
{
public static UserInfoPrincipal Current
{
get
{
if (Thread.CurrentPrincipal is UserInfoPrincipal)
return (UserInfoPrincipal)Thread.CurrentPrincipal;
else
return null;
}
}
...
internal UserInfo UserData
{
get { return _userInfo; }
}
public string DeviceID
{
get { return _userInfo.DeviceID; }
}
...
}
So my hail mary pass was to remove the project reference and then add it again. Then it compiled. Have no clue why that worked, but figured I'd post it here for other who might run into the same problem.
Is the other library using a project reference or a binary reference? If its a binary reference, are you sure its using the latest build?
Check the reference path of the project that's generating the error; make sure you're either referencing the library project (if it's part of your solution) or the most recent build of the library (if it's not.)
I've gotten stuck in a few situations like this before. Here's what worked for me:
Are those two samples of code in separate projects? If so, I would say to try rebuilding the first project (containing the UserInfo class), then take out the line that fails the compilation out and try rebuilding the second project. Then do a rebuild all. Then add the offending line back in and do a rebuild all.
May not work for you, but worth a shot. I know that situation is frustrating.
for me -- try to recreate the line that shows an issue. Write the name of the object period (.) and wait for VS to show you the list of available properi
I encountered a very similar problem.
In my case I have a piece of code that I only need to run a couple times a year. When I attempted to use it there was an error accessing a Member. Nothing should have changed since the last time I used the code. Intellisense was detecting the member when using the '.' in Visual Studio. I restarted Visual Studio and the computer but the problem stayed.
In the end to fix my problem, I created a new file, copied the code from the original to the new file, and that was it. No code modifications. I used Ctrl-C, Ctrl-V so the content wasn't corrected by a manual touch. This isn't the first time copy and paste has fixed a bug so it's worth keeping the idea in the tool chest. Sometimes a mysterious problem demands an equally mysterious solution.
In my case, it was a problem with the web application's project properties. To fix it, I did the following:
Right-click the project > click Properties.
On the Build tab, change the Output path value for all configurations to: bin\
Previously, my output path had been bin\Debug or bin\Release depending on which configuration I was looking at. I don't know why this screwed with my markup page's ability to see methods in my codebehind, but it did. Once I changed this, the error disappeared.
This was in VS2012 w/ update 2.
My solution: I was create another name method what set property. My problem was on VS2015 + Silverlight 5