Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. UserControl and interface implementation

UserControl and interface implementation

Scheduled Pinned Locked Moved C#
helpcsharpvisual-studioannouncementworkspace
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Corneliu Tusnea
    wrote on last edited by
    #1

    Hi, I've found a very strange problem and I badly need a fix for it. I have a simple interface defined in one class library, let's say WindowsLibrary1: [code] namespace WindowsLibrary1 { public interface ITest { void Test(); } } [/code] I reference this class library from another project that is a WindowsApplication, lets say: WindowsApplication1. In the WindowsApplication1 I create a simple usercontrol: UserControl1: [code] public class UserControl1 : System.Windows.Forms.UserControl, WindowsLibrary1.ITest { .... public void Test() { // implementation of the WindowsLibrary1.ITest.Test() } } [/code] Ofcourse all compiles fine, but I can not use this usercontol at all. Whenever I try to drop the control on a form I get the following error message: --------------------------- Microsoft Development Environment --------------------------- The user control 'WindowsApplication3.UserControl1' could not be loaded. Ensure that the library containing the control has been built and a project reference has been made to the library containing the control. If you have changed the name of the user control, close and re-open the control's designer to update the toolbox item. --------------------------- OK --------------------------- I badly need this to make it work, so any help is greatly appreciated. Thanks, Corneliu. PS>> Environment: VS.Net 2003, WinXP.

    H 1 Reply Last reply
    0
    • C Corneliu Tusnea

      Hi, I've found a very strange problem and I badly need a fix for it. I have a simple interface defined in one class library, let's say WindowsLibrary1: [code] namespace WindowsLibrary1 { public interface ITest { void Test(); } } [/code] I reference this class library from another project that is a WindowsApplication, lets say: WindowsApplication1. In the WindowsApplication1 I create a simple usercontrol: UserControl1: [code] public class UserControl1 : System.Windows.Forms.UserControl, WindowsLibrary1.ITest { .... public void Test() { // implementation of the WindowsLibrary1.ITest.Test() } } [/code] Ofcourse all compiles fine, but I can not use this usercontol at all. Whenever I try to drop the control on a form I get the following error message: --------------------------- Microsoft Development Environment --------------------------- The user control 'WindowsApplication3.UserControl1' could not be loaded. Ensure that the library containing the control has been built and a project reference has been made to the library containing the control. If you have changed the name of the user control, close and re-open the control's designer to update the toolbox item. --------------------------- OK --------------------------- I badly need this to make it work, so any help is greatly appreciated. Thanks, Corneliu. PS>> Environment: VS.Net 2003, WinXP.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Sounds like a version problem. With .NET assemblies and the CLR, version numbers are VERY important (unlike version numbers with native DLLs, which are basically there for reference and for decent installers so they don't copy over newer versions). When you work with multiple projects in a solution, you really should not use automatic versioning, i.e. using an asterisk in the [assembly:AssemblyVersionAttribute], typically found in your AssemblyInfo.cs file. The problem seems to be that the version your first project is referencing references one version while the component you added to the toolbox is of a different version. One other way you can help this is to use a project reference instead of an assembly refernece. When you add a reference to your project (right click, Add Reference...), click on the Project tab and add the project that you want to reference. This establishes a build dependency (making sure that any changes in the dependency prompt a rebuild so the referencing assembly has the latest code) and make sure that the assemblies that are referenced are the correct version. As far as the toolbox goes, don't explicitly add components to it that you develop and are currently developing in the open solution. Third-party controls and controls that you've build stables version of and deployed should be used there. VS.NET - though not all the time - will automatically add a reference to any UserControl that you open in the VS.NET designer to the toolbox. If it doesn't, switch to code view, define your field, and instantiate it in the InitializeComponent method that the designer uses. This will make sure it can be designed if you need that sort of thing. You can then continue setting properties and adding event handlers like you normally would on a control using the designer.

      Microsoft MVP, Visual C# My Articles

      C 1 Reply Last reply
      0
      • H Heath Stewart

        Sounds like a version problem. With .NET assemblies and the CLR, version numbers are VERY important (unlike version numbers with native DLLs, which are basically there for reference and for decent installers so they don't copy over newer versions). When you work with multiple projects in a solution, you really should not use automatic versioning, i.e. using an asterisk in the [assembly:AssemblyVersionAttribute], typically found in your AssemblyInfo.cs file. The problem seems to be that the version your first project is referencing references one version while the component you added to the toolbox is of a different version. One other way you can help this is to use a project reference instead of an assembly refernece. When you add a reference to your project (right click, Add Reference...), click on the Project tab and add the project that you want to reference. This establishes a build dependency (making sure that any changes in the dependency prompt a rebuild so the referencing assembly has the latest code) and make sure that the assemblies that are referenced are the correct version. As far as the toolbox goes, don't explicitly add components to it that you develop and are currently developing in the open solution. Third-party controls and controls that you've build stables version of and deployed should be used there. VS.NET - though not all the time - will automatically add a reference to any UserControl that you open in the VS.NET designer to the toolbox. If it doesn't, switch to code view, define your field, and instantiate it in the InitializeComponent method that the designer uses. This will make sure it can be designed if you need that sort of thing. You can then continue setting properties and adding event handlers like you normally would on a control using the designer.

        Microsoft MVP, Visual C# My Articles

        C Offline
        C Offline
        Corneliu Tusnea
        wrote on last edited by
        #3

        Thanks for the answer. Unfortunatelly it does not help as none of your recomandations apply. I've already tried most of them before posting the question. I have the feeling that something has happend with my VS.Net after I've un-intalled some addin (I think it was ReShape or something like that). Since then VS behaves sometimes strange. I've just discovered that my example works perfectly on another sistem, thus I think I'll spend my day with reinstalling VS.Net with the hope that this will solve my problem. Thanks alot, Corneliu.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups