error building user control... anybody got this to work? 
Author Message
 error building user control... anybody got this to work?

I have a usercontrol that is pretty basic right now... doesn't do much at
all. I added both that project and a test project to my Solution, built them
both, then ran it. However, I get an "unhandled exception of
TypeLoadException" or something like that. I put a stop statement in my
control and stepped through all the code and it works just fine.... I
enclosed the statement "Dim MyControl as New MyProject.MyControl" in a
Try...Finally block, but it still comes back with an unhandled exception.

So... anybody got UserControls working? Any ideas/suggestions?

--

--------
Russ



Thu, 29 May 2003 11:35:04 GMT  
 error building user control... anybody got this to work?
Update:

It appears that the error is related to my control raising events. For
example:

In my control I do this: "Public Event FixMenuState(ByVal NewState as
Integer)", then i use "RaiseEvent FixMenuState(Mystate.ToInt32)"

In my form code, I have a "Public Sub FMM1_FixMenuState(ByVal NewState as
Integer) Handles FMM1.FixMenuState"

If I comment out the "Public Sub FMM1...." lines, everything works properly.
The error I get says "Could not load class 'FixMenuStateEventHandler'"

Any clues / hints would be appreciated.

-- russ



Quote:
> I have a usercontrol that is pretty basic right now... doesn't do much at
> all. I added both that project and a test project to my Solution, built
them
> both, then ran it. However, I get an "unhandled exception of
> TypeLoadException" or something like that. I put a stop statement in my
> control and stepped through all the code and it works just fine.... I
> enclosed the statement "Dim MyControl as New MyProject.MyControl" in a
> Try...Finally block, but it still comes back with an unhandled exception.

> So... anybody got UserControls working? Any ideas/suggestions?

> --

> --------
> Russ



Thu, 29 May 2003 12:55:02 GMT  
 error building user control... anybody got this to work?
I doubt this is directly related to you're problem, but shouldn't you be
using the standard event arguments?

--
Jonathan Allen



Quote:
> Update:

> It appears that the error is related to my control raising events. For
> example:

> In my control I do this: "Public Event FixMenuState(ByVal NewState as
> Integer)", then i use "RaiseEvent FixMenuState(Mystate.ToInt32)"

> In my form code, I have a "Public Sub FMM1_FixMenuState(ByVal NewState as
> Integer) Handles FMM1.FixMenuState"

> If I comment out the "Public Sub FMM1...." lines, everything works
properly.
> The error I get says "Could not load class 'FixMenuStateEventHandler'"

> Any clues / hints would be appreciated.

> -- russ



> > I have a usercontrol that is pretty basic right now... doesn't do much
at
> > all. I added both that project and a test project to my Solution, built
> them
> > both, then ran it. However, I get an "unhandled exception of
> > TypeLoadException" or something like that. I put a stop statement in my
> > control and stepped through all the code and it works just fine.... I
> > enclosed the statement "Dim MyControl as New MyProject.MyControl" in a
> > Try...Finally block, but it still comes back with an unhandled
exception.

> > So... anybody got UserControls working? Any ideas/suggestions?

> > --

> > --------
> > Russ



Thu, 29 May 2003 12:18:48 GMT  
 error building user control... anybody got this to work?
Why? I don't need them, as far as I am aware. A simple Integer is it.

If there were more Docs on the new event model, I'd read up on them. If you
know of a REALLY good site about the subject, I would love to take a look.

--------
Russ


Quote:
> I doubt this is directly related to you're problem, but shouldn't you be
> using the standard event arguments?

> --
> Jonathan Allen



> > Update:

> > It appears that the error is related to my control raising events. For
> > example:

> > In my control I do this: "Public Event FixMenuState(ByVal NewState as
> > Integer)", then i use "RaiseEvent FixMenuState(Mystate.ToInt32)"

> > In my form code, I have a "Public Sub FMM1_FixMenuState(ByVal NewState
as
> > Integer) Handles FMM1.FixMenuState"

> > If I comment out the "Public Sub FMM1...." lines, everything works
> properly.
> > The error I get says "Could not load class 'FixMenuStateEventHandler'"

> > Any clues / hints would be appreciated.

> > -- russ



> > > I have a usercontrol that is pretty basic right now... doesn't do much
> at
> > > all. I added both that project and a test project to my Solution,
built
> > them
> > > both, then ran it. However, I get an "unhandled exception of
> > > TypeLoadException" or something like that. I put a stop statement in
my
> > > control and stepped through all the code and it works just fine.... I
> > > enclosed the statement "Dim MyControl as New MyProject.MyControl" in a
> > > Try...Finally block, but it still comes back with an unhandled
> exception.

> > > So... anybody got UserControls working? Any ideas/suggestions?

> > > --

> > > --------
> > > Russ



Thu, 29 May 2003 14:43:33 GMT  
 error building user control... anybody got this to work?
Your right, you don't *need* to use the full syntax. For now, all you need
is a integer. What if next week you decide you also want the sender or a
second integer?

What I really like about the Sender/EventArgs syntax is that it's easy to
change. If you add another argument, you don't have to rewrite all the
existing event handlers.

--
Jonathan Allen



Quote:
> Why? I don't need them, as far as I am aware. A simple Integer is it.

> If there were more Docs on the new event model, I'd read up on them. If
you
> know of a REALLY good site about the subject, I would love to take a look.

> --------
> Russ



> > I doubt this is directly related to you're problem, but shouldn't you be
> > using the standard event arguments?

> > --
> > Jonathan Allen



> > > Update:

> > > It appears that the error is related to my control raising events. For
> > > example:

> > > In my control I do this: "Public Event FixMenuState(ByVal NewState as
> > > Integer)", then i use "RaiseEvent FixMenuState(Mystate.ToInt32)"

> > > In my form code, I have a "Public Sub FMM1_FixMenuState(ByVal NewState
> as
> > > Integer) Handles FMM1.FixMenuState"

> > > If I comment out the "Public Sub FMM1...." lines, everything works
> > properly.
> > > The error I get says "Could not load class 'FixMenuStateEventHandler'"

> > > Any clues / hints would be appreciated.

> > > -- russ



> > > > I have a usercontrol that is pretty basic right now... doesn't do
much
> > at
> > > > all. I added both that project and a test project to my Solution,
> built
> > > them
> > > > both, then ran it. However, I get an "unhandled exception of
> > > > TypeLoadException" or something like that. I put a stop statement in
> my
> > > > control and stepped through all the code and it works just fine....
I
> > > > enclosed the statement "Dim MyControl as New MyProject.MyControl" in
a
> > > > Try...Finally block, but it still comes back with an unhandled
> > exception.

> > > > So... anybody got UserControls working? Any ideas/suggestions?

> > > > --

> > > > --------
> > > > Russ



Thu, 29 May 2003 15:10:36 GMT  
 error building user control... anybody got this to work?
I still need some more info about events.... I've checked the SDK docs, but
they are all in C# on the subject of events. I can sort of read them, but I
have done what is required and I still can't seem to get this working.
Events have become a real PITA.

Here is what I have (basically... some parts snipped.)

Public Class MyControl
    Inherits System.Winforms.UserControl

    Public Event FixState(Byval sender as Object, ByVal ev as
System.EventArgs)
    [snip]
    Protected Overridable Sub OnFixState(Byval e as System.EventArgs)
        RaiseEvent FixState(Me, e)
    End Sub

End Class

Public Class FixMenuStateEventArgs
    Inherits System.EventArgs
End Class

Now in my form I do this (abbreviated)

Private WithEvents Control1 as MyControl
Me.Control1 = New MyControl()
'^ -- error happens right after this line
[snip]
Public Sub Control1_FixState(Byval sender as Object, ByVal e as
System.EventArgs) Handles Control1.FixState
End Sub
^-- if i comment out these two lines, I don't get the error.

The error is "Can't load class 'FixStateEventArgs'"

-- russ


Quote:
> Your right, you don't *need* to use the full syntax. For now, all you need
> is a integer. What if next week you decide you also want the sender or a
> second integer?

> What I really like about the Sender/EventArgs syntax is that it's easy to
> change. If you add another argument, you don't have to rewrite all the
> existing event handlers.

> --
> Jonathan Allen



> > Why? I don't need them, as far as I am aware. A simple Integer is it.

> > If there were more Docs on the new event model, I'd read up on them. If
> you
> > know of a REALLY good site about the subject, I would love to take a
look.

> > --------
> > Russ



> > > I doubt this is directly related to you're problem, but shouldn't you
be
> > > using the standard event arguments?

> > > --
> > > Jonathan Allen



> > > > Update:

> > > > It appears that the error is related to my control raising events.
For
> > > > example:

> > > > In my control I do this: "Public Event FixMenuState(ByVal NewState
as
> > > > Integer)", then i use "RaiseEvent FixMenuState(Mystate.ToInt32)"

> > > > In my form code, I have a "Public Sub FMM1_FixMenuState(ByVal
NewState
> > as
> > > > Integer) Handles FMM1.FixMenuState"

> > > > If I comment out the "Public Sub FMM1...." lines, everything works
> > > properly.
> > > > The error I get says "Could not load class

'FixMenuStateEventHandler'"

- Show quoted text -

Quote:

> > > > Any clues / hints would be appreciated.

> > > > -- russ



> > > > > I have a usercontrol that is pretty basic right now... doesn't do
> much
> > > at
> > > > > all. I added both that project and a test project to my Solution,
> > built
> > > > them
> > > > > both, then ran it. However, I get an "unhandled exception of
> > > > > TypeLoadException" or something like that. I put a stop statement
in
> > my
> > > > > control and stepped through all the code and it works just
fine....
> I
> > > > > enclosed the statement "Dim MyControl as New MyProject.MyControl"
in
> a
> > > > > Try...Finally block, but it still comes back with an unhandled
> > > exception.

> > > > > So... anybody got UserControls working? Any ideas/suggestions?

> > > > > --

> > > > > --------
> > > > > Russ



Thu, 29 May 2003 17:35:44 GMT  
 error building user control... anybody got this to work?
Russ,

Are you sure everything is up to date? It sounds like your client and
control source are out of sync.

I just tried a relatively simple case and it worked for me

imports system
public delegate sub FooEvt(i as integer)
public class Foo
    public event Evt as FooEvt
    public sub RaiseEvt(i as integer)
            raiseevent Evt(i)
    end sub
end class

public class Bar
    private withevents MyFoo as Foo

    public sub New()
        MyFoo = new Foo()
    end sub

    private sub GotFooEvt(val as integer) handles MyFoo.Evt
        console.writeline("got evt {0}", val)
    end sub
    shared sub Main()
        dim b as Bar = new Bar()
        b.MyFoo.RaiseEvt(5)
    end sub
end class



Quote:
> I still need some more info about events.... I've checked the SDK docs,
but
> they are all in C# on the subject of events. I can sort of read them, but
I
> have done what is required and I still can't seem to get this working.
> Events have become a real PITA.

> Here is what I have (basically... some parts snipped.)



Thu, 29 May 2003 18:14:01 GMT  
 error building user control... anybody got this to work?
Russ,

I managed to reproduce the same problem.  It seems to be related to the
Delegate being nested within MyControl.  When you declare the Event...

    Public Event FixState(Byval sender as Object, ByVal ev as
System.EventArgs)

It is really just a shortcut for...

    Public Delegate Sub FixStateEventHandler(Byval sender as Object, ByVal
ev as System.EventArgs)
    Public Event FixState As FixStateEventHandler

Since Delegates are a sort of type (like Structures or Classes), you are
defining a nested "MyControl.FixStateEventHandler" delegate type.  This
seems to be causing VB some confusion in the test project that Handles the
event (using WithEvents/Handles OR AddHandler).  I found that you can avoid
the error if you declare the Delegate *outside* the class (unnesting it), as
in...

    Public Delegate Sub FixStateEventHandler(Byval sender as Object, ByVal
ev as System.EventArgs)

    Public Class MyControl
        Inherits System.Winforms.UserControl

        Public Event FixState As FixStateEventHandler
        '[...]

    End Class

I imagine this is a bug with multiple-project solutions.

--
David.



Quote:
> I still need some more info about events.... I've checked the SDK docs,
but
> they are all in C# on the subject of events. I can sort of read them, but
I
> have done what is required and I still can't seem to get this working.
> Events have become a real PITA.

> Here is what I have (basically... some parts snipped.)

> Public Class MyControl
>     Inherits System.Winforms.UserControl

>     Public Event FixState(Byval sender as Object, ByVal ev as
> System.EventArgs)
>     [snip]
>     Protected Overridable Sub OnFixState(Byval e as System.EventArgs)
>         RaiseEvent FixState(Me, e)
>     End Sub

> End Class

> Public Class FixMenuStateEventArgs
>     Inherits System.EventArgs
> End Class

> Now in my form I do this (abbreviated)

> Private WithEvents Control1 as MyControl
> Me.Control1 = New MyControl()
> '^ -- error happens right after this line
> [snip]
> Public Sub Control1_FixState(Byval sender as Object, ByVal e as
> System.EventArgs) Handles Control1.FixState
> End Sub
> ^-- if i comment out these two lines, I don't get the error.

> The error is "Can't load class 'FixStateEventArgs'"

> -- russ



Fri, 30 May 2003 01:52:26 GMT  
 error building user control... anybody got this to work?
OK I figured maybe I totally screwed something up.... so I followed these
steps and am still getting the same errors:

1. Created blank project...
2. Added User control and changed project type to "Class Library"
3. Added another project to solution of type "Windows Application"
4. Opened design mode on User Control and placed command button on it.
5. Opened code for User Control and added this:

Public Class UserControl1
    Public Event MyEvent(ByVal sender as System.Object, ByVal e as
System.EventArgs)
    Public Sub New()
        MyBase.New
        [winforms designer code snipped]
        Dim e as New System.EventArgs()
        RaiseEvent MyEvent(Me, e)
    End Sub
        [snip winforsm designer dispose code]
End Class

6. Added reference of test user control project to Test windows form
project.
7. Changed startup project for solution to test windows form project.
8. Placed a UserControl1 onto Windows form.
9. Compiled and run... EVERYTHING WORKS.

Now we know that everything is OK... all references and other items seem to
be working. The event is declared, no problems. Now at the next step is
where it craps out:

10. Opened code view for test windows form project, and added this:
    Public Sub UserControl11_MyEvent(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles UserControl11.MyEvent

    End Sub

Now project errors out upon run with an unhandled exception. If I put my
Try, Catch,Finally code in there and do MsgBox(err.description) I get the
same ol' problem: "Could not load class 'MyEventEventHandler'"

I AM OFFICIALLY GOING INSANE >GRR<

-- russ



Fri, 30 May 2003 13:36:18 GMT  
 error building user control... anybody got this to work?
Thanks... that fixed it.

-- russ


Quote:
> Russ,

> I managed to reproduce the same problem.  It seems to be related to the
> Delegate being nested within MyControl.  When you declare the Event...

>     Public Event FixState(Byval sender as Object, ByVal ev as
> System.EventArgs)

> It is really just a shortcut for...

>     Public Delegate Sub FixStateEventHandler(Byval sender as Object, ByVal
> ev as System.EventArgs)
>     Public Event FixState As FixStateEventHandler

> Since Delegates are a sort of type (like Structures or Classes), you are
> defining a nested "MyControl.FixStateEventHandler" delegate type.  This
> seems to be causing VB some confusion in the test project that Handles the
> event (using WithEvents/Handles OR AddHandler).  I found that you can
avoid
> the error if you declare the Delegate *outside* the class (unnesting it),
as
> in...

>     Public Delegate Sub FixStateEventHandler(Byval sender as Object, ByVal
> ev as System.EventArgs)

>     Public Class MyControl
>         Inherits System.Winforms.UserControl

>         Public Event FixState As FixStateEventHandler
>         '[...]

>     End Class

> I imagine this is a bug with multiple-project solutions.

> --
> David.



> > I still need some more info about events.... I've checked the SDK docs,
> but
> > they are all in C# on the subject of events. I can sort of read them,
but
> I
> > have done what is required and I still can't seem to get this working.
> > Events have become a real PITA.

> > Here is what I have (basically... some parts snipped.)

> > Public Class MyControl
> >     Inherits System.Winforms.UserControl

> >     Public Event FixState(Byval sender as Object, ByVal ev as
> > System.EventArgs)
> >     [snip]
> >     Protected Overridable Sub OnFixState(Byval e as System.EventArgs)
> >         RaiseEvent FixState(Me, e)
> >     End Sub

> > End Class

> > Public Class FixMenuStateEventArgs
> >     Inherits System.EventArgs
> > End Class

> > Now in my form I do this (abbreviated)

> > Private WithEvents Control1 as MyControl
> > Me.Control1 = New MyControl()
> > '^ -- error happens right after this line
> > [snip]
> > Public Sub Control1_FixState(Byval sender as Object, ByVal e as
> > System.EventArgs) Handles Control1.FixState
> > End Sub
> > ^-- if i comment out these two lines, I don't get the error.

> > The error is "Can't load class 'FixStateEventArgs'"

> > -- russ



Sat, 31 May 2003 03:29:45 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Getting full list of Domain Users is not working properly - some users missing

2. License Error with OCX's anybody, anybody

3. getting run-time behavior of a contained control in a user control at design time

4. Difference between registering vb user control .ocx and building it on target machine

5. Resizing user built control

6. Anybody built custom parameter field dilogs

7. getting rid of read only error when working from a cd in Access 2000

8. Code works when run in VB6, gets error when compiled (Browse for Outlook Folder)

9. Code works when run in VB6, gets error when compiled (Browse for Outlook Folder)

10. Get User Name - getting error

11. Users getting error messages

12. Users getting error messages

 

 
Powered by phpBB® Forum Software