Can someone please tell me how to display error message in C# during execution of AfterInstallEvent?
My project uses the Microsoft set-up and deployment project and then I have created a class that is called when the AfterInstall event is fired.
MessageBox.Show(); doesn't work..."The name 'MessageBox' does not appear in the current context".
If it was that simple, I wouldn't be asking!?
The real solution is to use scope. Something like this:
global::System.Windows.Forms.MessageBox.Show(ex,"Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
Cheers
This is very old but I'll answer anyway:
It's just a missing reference.
Add a reference to System.Windows.Forms to the project containing the class.
Also add "using System.Windows.Forms;" to the top of your class file.
As far as I know there shouldn't be any issues with displaying message boxes from a custom install action.
Related
I am working on WPF project, and after I made everything in Xaml file I wanted to start doing on my CS file.
Now, I was trying to add event using that little bolt in properties, but everytime i click on any event (for example I select button in XAML and try to add -> MyButton_Click) i get a pop-up message "UNABLE TO ADD EVENT HANDLER".
I hope you are able to help me.
yes, #will is right, I also suffered from the same problem,when i was new in WPF. Please check your x:Class in your XAML file, it should include the namespace used in code behind.
e.g.,
x:Class="MainWindow"
should be some thing like
x:class="namespace.MainWindow"
if it doesn't work,try to restart the VS or try to recreate the project with correct name, hope it will solve your problem.
I suffered from the same problem like you. Error occurs when you have any syntax error in your XAML file like misspell, missing tag, comma, lack of method/event handler or difficulties with references.
Exactly the same reason is when you are unable to add event or change any property in Property Window, but without any message or error. Check your syntax carefully.
Regards.
yes. I also face this problem, I fixed it. the problem is on x:Class="MainWindow". just like #Abdullah Said.
I had wrong namespace in XAML file after copying/pasting the code. Namespace in XAML and underlaying code must match.
This can also happen if a method already exists in the .cs file whose name is identical to the method name the IDE is attempting to create.
Once I added a name to the button, I was able to double click it the error went away, opening the code view to the event handler.
I have encountered an error that prevents me from uploading the webpage to the server. I managed to let it work without any errors when I am running visual studio.
Here's the error
However, when I removed Inherits="testconnect.index" , it can work but it cannot connect index.aspx.cs to index.aspx.
Like for example:
With lbl_test.Text inside the index.aspx
Does anyone knows how to fix the error?
You're trying to inherit from testconnect.index, but your class is named index1. Can you change the class name to index? Or, conversely, set the Inherits directive to inherit from testconnect.index1?
You have to specify the exact name of the class in order to reference it. "Close enough" isn't close enough.
(Note also that Visual Studio is trying to tell you in your index1 class that lbl_test doesn't exist. Supposedly perhaps the designer partial class is index? If that's the case, you'll probably want to just rename this partial class to index as well.)
Okay I have got it working by changing CodeBehind="index.master.cs" to CodeFile="index.master.cs". I learned that you will have to compile the file first if you want to use CodeBehind. Other than that, it is recommended not to name the aspx page exactly similar to masterpage.
I'm trying to create a customized Windows Forms control by following these MSDN instructions:
http://msdn.microsoft.com/en-us/library/7h62478z.aspx
(Article title: How to: Inherit from Existing Windows Forms Controls; the instructions are for Visual Studio 2010)
These instructions do seem to work, but if I change the name of the control from CustomControl1 to any other name (by changing the class name and constructor name), I receive the message:
"The name 'InitializeComponent' does not exist in the current context"
I've looked at the similar questions and answers here, and I don't think any of them answer this, but I could be wrong. If I am, then I didn't understand the answer.
I hope someone can help me on this. I've wasted a lot of time on it already.
Thanks.
A few minutes after posting this question, I figured out the answer. I imagine that for someone with even moderate experience with Visual Studio, the answer is obvious, but it wasn't for me, so maybe I can save somebody some time if they happen to read this.
To rename a newly created custom control which has been created by following the MSDN instructions in the link provided in the question:
Rename the generated source file from CustomControl1.cs (for C#) to the desired name
Say yes when Visual Studio asks you if you want to change all the references
That's it. The custom control name is changed, and no more error.
When changing the class name you'll notice that a red line appears under the end of the new class name.
Hover over it until a little box appears, then click on that box, and then click on "Rename...". (A shortcut to it is: Ctrl+. <-that's the period key.)
That's all.
The reason for the error is that the InitializeComponent method is in a separate file with the old class name. By choosing the "Rename..." as mentioned above - Visual Studio will rename the class in that file as well. It also changes the constructor's name.
I keep coming accross code samples online for ASP.net c#, however they never seem to list which namespaces they include, for example:
using System.Data.SqlClient;
etc etc
Am I missing something obvious or should I be expected to know exactly what namespaces each code example requires?
When I'm in that situation, typically I search for the class on MSDN. The documentation will tell you which namespaces contain the class.
If they don't include them, you can follow this list in order:
Find that they are in one of the namespaces listed in the "blank code file" template , or
In Visual Studio You can click the missing type and press shift+F10 or Ctrl+. To get the option to automatically add the using statement (if the assembly is referenced)
With Resharper, Select the type and hit alt+enter for Resharper to find the namespace for you, and add it to the usings (possibly even reference the assembly as well)
Go to MSDN and search the name.
Go to Google and search the name (honestly, I normally do this before hitting MSDN anyway)
Compain to the article author
If code samples use the assemblies that a project references by default, then you can hover on the class name and click shift+F10 which will add the using statement automatically. If the class is not in any of the referenced assemblies then you are out of luck and need to know in what assembly does the class resides.
A quick google search can help, and in time you will memorize the namespaces... Of course its best if samples included the namespace and reference info, but mostly they do not.
If you are viewing code in Visual studio, just hover mouse over class or object you want and you will get tool tip about it if assemly of that class is present or you can google for particular class.For example if you want to know more about 'DataTable'class, just google it and you will come to know that its part of Syste.Data namespace.
I'm with the OP on this one. Having to just magically "know" what namespaces are required seems supremely silly.
I spent some time before C# as a Java Developer, and the NetBeans IDE will resolve these for you automatically. Ctrl-Shift-I, and it will insert all the packages (ie, namespaces) you need. If more than one package defines the class you are resolving, a window pops up and lets you choose which one you want.
For as fine a product as VS is, I am incredulous that this feature is not included.
I got this error message when i want to create a page in the SharePoint Central Administration :
The base type 'xxxx' is not allowed for this page. The type is not registered as safe.
The .aspx page references a codebehind class. I checked the namespaces, i added the tag in the web.config, everything is fine, but it still doesn't work !
Can someone please tell me why i got this error message ?
Registering controls as safe via direct web.config is a method that will work, however things get complex when you have a farm. If you have a farm you will have to do this in every web.config for every WFE server you have. The preferred way is doing this via solution package, which is what we do in our environment. See this article which helped us.
Is the entry in the SafeControls correct? Does it reference the exact version number of the assembly? Is the public key token correct?
The one thing that often gets me into toruble is the namespace. Use .NET Reflector and open your assembly - navigate to the control and look at the namespace path for that control in the bottom left of the screen. Sometimes I put the name of the control in SafeControls with the wrong namespace path.