MDIParent designer screen is not loading - vb.net

When i try to view MDIParent screen in designer mode I’m getting below exception...
`Could not find endpoint element with name 'NetTcpBinding_IMyService' and contract 'ClientProxy.IMyService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.'
Little background to understand my question more clearly...
I've a WCF server which I’m trying to consume in my Winform application. So i've created a separate class library in which i added service reference and created a proxy. I've copied the client endpoint info from app.config in class library to UI app.config file.
When i run the application everything is working fine but when i try to open MDIParent screen in designer mode its throwing above exception.
Note: I think i'm getting error because i'm trying to create a proxy object on NEW method (form constractor) if i comment that line - i'm able to view designer screen.
Please help :)
Venky

If you instantiate the service in the form's constructor, this could be the source of your problem.
If this is the case, wrap the service initialization in a test for DesignMode:
If Not Me.DesignMode Then
' Initialize service
End If
Update
It turns out that DesignMode is not supported in the constructor.
There are a couple of workarounds to choose from:
1) Use the following instead of the designmode test:
If System.ComponentModel.LicenseManager.UsageMode <> System.ComponentModel.LicenseUsageMode.Designtime Then`
2) Move your initialization code from the constructor into the Form's _load event and then use the DesignMode test.
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not Me.DesignMode Then
' Initialize service
End If
End Sub

Related

How to make a global variable in Visual Basic

I have a Mysql login system in Visual Basic , and I want to store the username in a global variable after a succesful login but when the app will close I want that variable to be deleted.. can you show me some example? I'm a beginner at visual basic.
If you're developing on Windows, then use the Windows Registry to persist the value.
See http://msdn.microsoft.com/en-us/library/aa289494(v=vs.71).aspx for more details, and examples.
Take care if caching a password though; you'll need to encrypt that.
Just create a class (in your project) that will not be instantiated right...and then have a variable in that class with access modifier
Public Shared.
Like for me I made a class called Globals and in it was a variable called currentUser .
So to access the variable from any class I just had Globals.currentUser =txtUser.TextAnd declare it like Public Shared currentUser as String
Try this, in your form file outside of the main class, or in a separate module file:
Public Module Globals
Public UserName As String = ""
End Module
Now you can access it in any code throughout your project. It will dispose when the app is closed. If you wanted to make doubly sure, even though it would be redundant, add this to the main form that closes the whole app:
Private Sub Form1_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
UserName = ""
End Sub

How to handle the back key from ConnectionSettingstask called directly from a secondary tile

i have a small wp7 application with just a main page. The main page has 4 buttons and calls the ConnectionSettingstask for wifi, bluetooth, airplanemode and cellular data setting. I have also managed to create secondary tiles for any of these buttons. The OnNavigateTo event handles the secondary tiles using a key passed from the tile
Protected Overrides Sub OnNavigatedTo(ByVal e As System.Windows.Navigation.NavigationEventArgs)
If (Me.NavigationContext.QueryString.ContainsKey("_key")) Then
Dim Key As String = String.Empty
Key = Me.NavigationContext.QueryString("_key")
Select Key
Case "WiFi"
Dim NewTask As New ConnectionSettingsTask
NewTask.ConnectionSettingsType = ConnectionSettingsType.WiFi
NewTask.Show()
....
End Select
NavigationContext.QueryString.Remove("_key")
End If
End Sub
The problem ia that when the user uses the secondary tile to call a task, the application opens directly the connection settings page, but after that the back key, instead of opening the phone main menu, open the main page of my application
If you navigated to A then navigated to B, you can remove A from the backstack, but only if A and B is in your application.
A solution is to close your application when it detects you're coming back from the settings page. The only way to do this is to throw an exception and don't catch it. (A bit of a hack) The problem is that this kind of solution is not marketplace friendly, an unhandled exception means your app won't pass certification.
Unfortunately there is no marketplace friendly solution for this problem.

Silverlight VB AddHandler to dynamic object

We are migrating an application from C# to VB to meet our project's needs but stumbled upon a problem with event handling in VB.
The application uses a COM Wrapper access a scanner in Silverlight. The object is created dynamically in the code, and an event is added to "AcquirePage". This requires elevated trust of course.
Code in C#:
dynamic TwainSession;
(...)
TwainSession.AcquirePage += new AcquirePageDelegate(AcquirePageEventHandler);
As the only real "equivalent" of dynamic in VB is Object, we use:
Private TwainSession As Object
Everything is fine up to the point we want to handle an event of this Object. Because we are in Silverlight, we cannot have knowledge of the Object's structure or events, hence the need to create it dynamically. In C# we simply use "+=" to add a handler to an event but:
AddHandler TwainSession.AcquirePage, AddressOf AcquirePageEventHandler
In VB gives: 'AcquirePage' is not an event of 'Object'
Any way around that?
I think the answer is to compile with Option Strict Off but without being able to reproduce the problem I can't be sure.
See: Early and Late Binding
Unable to find a solution to do this within VB, we went about it this way:
Added a new project: Silverlight C# Class Library
The constructor takes two arguments, the dynamic object and the address of the event handler, and performs the C# method of adding handlers:
public TwainHandler(dynamic twainSession, Delegate eventHandler)
{
twainSession.AcquirePage += eventHandler;
}
The C# library was built and the dll added as a reference to the VB project.
Dim t as TwainHandler = New TwainHandler(TwainSession, New AcquirePageDelegate(AddressOf AcquirePageEventHandler))
This way the C# library adds the handler for the event (which points to a method in our VB application) dynamically. If anyone has a better solution please share.

Can't access my class from code-behind. Class is App_Code folder

I have a very simple class that is located within my App_Code folder in my VS2008 web application project. I am trying to instantiate an instance of this class from my code-behind file. Intellisense does not seem to be seeing my class and I am not sure why. I am using VB.NET which I am admittedly not that familiar with as compared to C#. Perhaps I am missing something. I would bet it has something to do with something I am missing in VB.NET.
Here is my simple class (for testing):
Public Class mySimpleClass
'Private member variables whose data is obtained from user input
Private mUserID as String
'Class Properties
Public Property UserID() as Integer
Get
Return mUserID
End Get
Set(ByVal Value as Integer)
mUserID = Value
End Set
End Property
'Class Methods
Public Function DisplayUserID() as String
Return this.UserID
End Function
End Class
Here is how I try an instantiate it from the codebehind ...
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim obj As New mySimpleClass()
End Sub
End Class
What I ended up doing was deleting my App_Code folder and creating a new "AppCode" folder. I also selected properties for the class file and set the Build Action property to "Compile". Once I did that and recompiled the project my class showed up.
you should change Return this.UserID to Return Me.UserID (VB.Net ;-))
rebuild the solution and see if it works
I'm not as familiar with the app_code folder and Websites in general, i'm always using WebApplications. I would suggest to convert it to a WebApplication too, here are further informations why: ASP.NET Web Site or ASP.NET Web Application?
Actually, I think if you add namespace to your project, it should work as well. I seem to remember having that problem every so often in C# asp.net as well. I could be way wrong though
Agree with Gustyn (sort of).
Add a "using namespace;" line to the web form code behind
Dave
Going to each file holding the "public" class(es) in the "App_Code" folder and setting Build Action from Content to Compile will do the trick.
It works for Web Application type projects.
All the stuff on whether to use a module(VB) or namespace or static(C#) won't help until you set your class files to compile (no matter what folder they are in).

Async call for WCF service hosted in windows service

I have hosted a WCF service in windows service. I have console app for which I added a WCF service reference and generated Client for it.
I can make Sync call to the service,but Async call doesn't seem to work. If i attach server process it doesn't hit the service at all.
client= new ServiceClient();
client.DoSomething();//Works fine
client.DoSomethingAsync()//Doesnot work
Is this a known problem?
The asynccall will probably be started in a background workerthread. So what could be happening is that your async thread is dieing out because the foreground thread has finished it's processing.
Unless you have some logic after you make this call to wait for the reponse, or continue with some other work on your main thread, the background thread may not have the time to get created before the application exits.
This can be easily tested by adding Thread.Sleep after the async call.
client.DoSomethingAsync();
Thread.Sleep(1000);
A symptom of this happening is that your service starts / stops unexpectedly and windows throws an error.
When you generated the client, did you tick the box to specify "Generate asynchronous operations"?
From the code posted, i'm assuming you have not set up handlers to deal with the response from the async method. You'll need something like the example at the bottom of this msdn post where you use AddHanlder to handle the response.
Something like the below before you make the async call:
AddHandler client.DoSomethingCompleted, AddressOf DoSomethingCallback
With a method to deal with the outome:
Private Shared Sub DoSomethingCallback(ByVal sender As Object, ByVal e As DoSomethingCompletedEventArgs)
'Do something with e.Result
MsgBox e.Result
End Sub
If you have a call to
client.DoSomethingAsync()//Doesnot work
then did you specify a handler for the callback completed event??
public event DoSomethingCompletedEventHandler DoSomethingCompleted;
What happens is that the async call goes off, but how would it send you back any results?? You'll need to provide a handler method for that - hook it up to the DoSomethingCompleted event handler! In that method, you'll get the results of the async call and you can do with them whatever you need to do.
Marc