1

I have created a windows form application in c# which loads video from hard disk and display them in the form using windows media player. After a 2-3 pc restarts when I am operning my project in visual studio I am receiving the following message and I can't enter to the designer:

enter image description here

Any idea how can I overcome this burden? Can I program my form elments without the designer? The weird is that windows media player is working fine when I am running my project but it just dont let me change the design of the form!

Community
  • 1
  • 1
christosh
  • 193
  • 8
  • 18

2 Answers2

1

You can check whether code is being executed at design time like this :

if(System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime)
//... do not execute the code that will crash at design time.
Timothy Groote
  • 8,614
  • 26
  • 52
  • where should I add this if loop ? – christosh Jan 15 '16 at 09:11
  • that's hard to tell without looking at your code. but i would gather that if there is a piece of code that explicitly loads the crash-causing activeX component, that would be the place. – Timothy Groote Jan 15 '16 at 09:12
  • I am receiving this message when I am trying to change the form instead of the form design! Not during the runing process. – christosh Jan 15 '16 at 09:14
  • when your form is loaded into the designer, a part of the code of the elements inside that form is executed in order to render the form properly. my guess is that code is causing the problems you're seeing. (again, this is hard to tell without seeing the actual code) – Timothy Groote Jan 15 '16 at 09:17
  • Is there a way to design my elements in the code, without using the form designer? – christosh Jan 15 '16 at 09:20
  • Yes. but if you're unaware of this possibility at the time, the way this is done is beyond the scope of this question i'm afraid. but you could make a new `UserControl`, and load the ActiveX element into that via code. (if you use the if-statement from this answer, you can keep using the designer for your other controls and forms.) – Timothy Groote Jan 15 '16 at 09:30
1
  • See the references of your project. Make sure there are no references with exclamation mark
  • Make sure that the AxWMPLIB ActiveX component is registered in Windows. If not, look for the corresponding .dll or .ocx files and register them with by the regsvr32 command.
  • If your project can be compiled, try to close and re-open the designer. It is a common issue in Visual Studio.
  • It seems that you use an AnyCPU build. The Visual Studio is executed in a 32-bit process (devenv.exe) even in a 64-bit Windows. It means that the designer is executed in a 32 bit environment as well. Sometimes this can lead to such errors if you use 3rd party components. Try to add the x86 configuration in the Configuration Manager, make a new build and try to open the designer afterwards. At the end you can build the AnyCPU version of you app, of course.
  • If nothing helps open the *.Designer.cs and configure your form manually...
György Kőszeg
  • 17,093
  • 6
  • 37
  • 65
  • My third party libs are 64bit how can I combine those two things? Is it feasuble firstly to design the form and then add my libs? – christosh Jan 15 '16 at 09:53
  • If they are available only in 64 bit that can be an explanation for your problems. How did you add the ActiveX component to your form? Did it work once? Of course, you can add ActiveX parts programmatically, out of the `InitializeComponent` method so you will able to open the form in the designerand add the Media Player-relevant things programmatically. – György Kőszeg Jan 15 '16 at 10:20
  • Sorry for the silly qustion but what do you mean with ActiveX? The gui element components? I add them with the designer and when I import my libs which are x64 automatically the problem risen. However I could again compile my code, however I cannot change the gui. – christosh Jan 15 '16 at 13:46