In my application, I use the ScintillaNET DLL and have created a class called BufferedScintilla where I am inheriting the control and double buffering it. Nothing unusual, just the normal C# inheritance... Than, I modified my form's Designer.cs file and switched from using ScintillaNET.Scintilla() to BufferedScintilla().
The app loads and works fine as expected BUT Visual Studio 2013 designer fails to load, telling me that "Unable to cast object of type BufferedScintilla to type ScintillaNET.Scintilla.
I tried everything, cleaned the solution and rebuild, rebuild only, debug, closing and restarting Visual Studio and even restarting the PC, but nothing helps at all... Visual Studio Designer refuses to let me design my form.
Again, the app runs FINE, and I am sure that the control on the form is the new BufferedScintilla, not ScintillaNET.Scintilla, because I can see the effects (it is double buffered, the custom graphics I am drawing over it do not flicker anymore), so I am 100% sure the app runs WITH the inherited component.
I am sure this is some kind of Visual Studio little flaw, so I am looking for a solution to have it let me design my app again.
EDIT: To clarify, the same thing happens in Visual Studio 2013 Update 1 and Visual Studio 2010 too. I checked the assembly, it is built as Any CPU, so there should be no problem with the Visual Studio designer...
EDIT: As it seems impossible to fix this (some kind of a bug), I am looking forwar to a way of replacing lines in the Designer.cs file automatically before building the project, and then after the project was built (or not). Is there any Visual Studio tool which will replace some text in the class automatically after pressing the Build button before the project is built, and after it has been built? I want to replace the constructor and declaration, so that at design time it is ScintillaNET.Scintilla, and at run time it is BufferedScintilla. Thanks!
Thanks in advance!
Vali
I've run into a problem very similar to this, In my case the designer still uses the constructors and the loaded events that are setup for the controls and forms. In my case, i was using a variable that was never set during design time, so to go around this you would have to modify you're code to do something like this...
if(this.DesignMode)
{
//DoSomething();
}
else
{
//DoSomethingElse();
}
Related
I migrated a silverlight 5 project from vs2013 to 2015 (both professionnal edition).
This is not even a real migration, because there is nothing to change in the code, or configuration, and Visual Studio say nothing when opening the project with 2015 instead of 2013.
The weird thing is, in VS 2015, my classes are not recognized in the code, and so, I cannot use completion.
As you can see in the code below, the word RivoliView is still black, because it is not recognized like DemView. The consequences are, I cannot use adresseBDUChild and access it's properties, while RivoliView is in the same namespace and a public page (the same way that DemView 'public partial class), and therefore, should berecognized.
In fact, all the classes that are not c# native (by native I mean like int, string List<T>, Boolean) are not recognized there, whle it was in studio 2013.
I cannot access properties from my classes, cannot have autocompletion.
What happened?
The project compile perfectly, and work perfectly when running in debug in the browser. It works excalty the same way it was in vs2013. But the problem here seems to come from visual studio.
I tried to get the project directly from Team Foundation server. Nothing.
Tried clean, rebuild, build, deleting .pdb files etc... No errors, but change Nothing. It always run as it should, without probems. Still not recognized.
Is it a vs2015 configuration problem?
The namespaces are well defined, and used in the page. This is weird since the same code recognized this classes in visual studio 2013.
Any idea?
I hope my question contains all useful details that I thinked about. If I forgot, tell me how I can be more specific.
Edit : still searching, and got no clue. I think I will go back in 2013 if I can't find an answer.
Now I also tried :
EDIT > IntelliSense > Refresh Remote References
removing and re-adding project references, such as Microsoft.CSharp.
Adding and removing the project from solution.
Creating new solution and then add the projects.
Thank you.
Try to refresh IntelliSense cache
EDIT > IntelliSense > Refresh Local Cache
and/or
EDIT > IntelliSense > Refresh Remote References
It sounds funny, but you might want to try removing and re-adding project references, such as Microsoft.CSharp.
That can often give VS2015 the kick it needs to re-analyse the project.
Edit:
When I say remove and re-adding, I mean via References under the Solution explorer.
Open references, right click on Microsoft.CSharp, and choose remove.
Add a new reference, go to Framework and find Microsoft.CSharp and add it.
It seems to make a difference for me when I do this manually without using Resharper or Visual Studio to resolve the reference for me.
I am working with winforms, .net 3.5 Visual Studio 2008.
The code is compiling, the winforms designer suddenly stops showing forms,
with different messages, for example
'Resco.Drawing.GradientColor' cannot be converted to type 'Resco.Drawing.GradientColor'
'Method not found: 'Void Resco.UIElements.UIControl.set_TextAlignment(Resco.Drawing.Alignment)'
The variable 'ucMessageBox1' is either undeclared or was never assigned.
Again, the code compiles and runs, and no changes habe been made to the form or usercontrol, that cannot be displayed, since it xold be displayed
Sometimes it helps to clean and rebuild, sometimes it help do delete the .suo file.
Sometimes it helps to shutdown and restart Visual Studio.
Sometimes I do not find a solution but somewhen it works again.
I have two solutions with identical Source code for two Platforms, windows and windows embedded, sometime the same control is shown without problems in one solution but not in the other.
I have this same issue with VS using DevExpress. I find if I close the designer mode and re-open it, it will work. At worse, I restart Visual Studio and appears to fix the problem.
That often happens when I work with Telerik, to resolve the issue I often have to do:
Repair the software library I installed for it.
Remove the reference, then Add the reference to the .dll again.
Ignore the designer mode and simply work in code behind.
Sadly, the last result is where I often find myself. Usually I'll simply code straight in code behind, as all the functionality exist but I don't have to deal with the issue every time I close / reopen Visual Studio. Since all the functionality exist in code behind, just unable to access the designer.
Honestly I'm not sure why it happens, but it happens often enough to where I avoid Telerik.
I'm getting the following error
Could not find type 'My.Special.UserControl'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU.
But what doesn't make any sense is that My.Special.UserControl is in the same assembly as the form. What's more, if I view code on the Designer.cs file, There are references to My.Special.UserControl that seem to be fine. The assembly builds fine, and runs fine as well. It's the just the designer that's having issues.
As such we have to do all our design work by making adjustments to the Designer.cs file by hand. How can I make the designer work again?
The following procedure has worked for me:
Delete the /bin and /obj folders in your source code directory.
Restart VS (be sure the offending Form Designer is closed)
Compile
Open the Form in Designer again. The problem should be resolved.
I'm sure deleting both /bin and /obj are not necessary, but I haven't been able to reproduce the error and come to a more specific solution. (My projects are typically small enough that re-compiling the whole thing is no big deal.)
Usually, this error seems to occur after refactoring / renaming objects of the offending class. So my guess is that there is a VS bug that doesn't recompile the appropriate object file after a User Control or Custom Control is refactored.
Change the project type temporarily to x86, compile and open the Designer. Visual Studio is a 32 bit application.
There is propably an exception happening in the Load or Initialize Part of your Form / UserControl. Can you try to comment out any code there and retry opening in designer?
You can use another instance of Visual Studio to attach a debugger to your Visual Studio instance not letting you open the Form. Once an exception occurs you will be able to pinpoint the location where something goes wrong.
I had similar problem when shifted from VS 2017 community edition to professional.
Close VS
Go to Project folder
Delete .vs folder. Back up if you need.
Start VS
This should solve the problem
I have experienced the exact same problem. I am fairly certain that it is connected to the platform target x64. Here is a related post mentioning it as a bug in Visual Studio:
https://stackoverflow.com/a/11582828/7665665
How I deal with it: Although my solution is actually only x64, I have created another platform target x86 for the projects just to be able to use the designer. Now I switch the target to x86 in order to see my controls in VS Designer. For everything else, I switch back to x64.
I had the same problem with a user control which was derived from the standard .NET control within my form.cs. Nothing of the above worked for me (my solution is compiled as x64 because of other unmanaged components which only support x64).
I finally ended up with creating a separate project "Utils" and moving the offending derived controls to this project. This worked like a charm !
In my case I just unload project and reload again
Switching the project target to x86 was the only possible solution for me
This happened to me today. Cleaning, Rebuilding, restarting Vs and even rebooting did not help. Everything ran as expected, the only thing that would not work was the designer in VS.
In my case, since nothing lese worked, I went to designer file, removed the faulty control and then added a new one. Renamed, re-assigned event listeners and it worked.
Designer now works, but if this must be some kind of VS bug, I don't know.
This is not the answer I'd like to read when coming to SO, but I'll post it in case it helps anyone later.
For me, I deleted the .resx file for the form, and it built and showed up in the designer, no problem. Go figure....
I had a similar experience when I sub-classed DataGridView. The following procedure has worked for me:
Close the Form Designer tab
Close VS (2015)
Delete the /bin and /obj folders of the project
Restart VS
Rebuild the solution
I don't know which steps could be skipped as I have not taken the time to refine the process.
On my project, it only worked if I made the custom user control in a separate project in the solution:
Add new project "Class Library (.NET Framework)"
Add references to System.Windows.Forms & System.Drawing
Add the source of the new user control in the new project
Build the solution
Open the designer
Drag the new user control in the form
In my case the designer automatically added a reference to the new project when I dragged the custom user control in my form.
Hope this help others who stumble upon this question.
This is a rather unusual question but here's the issue:
I have a WPF control created in Visual Studio C# 2008, map.xaml, created in the project Remote.
I want to add this to a Windows Form, also in Remote, using the ElementHost tool. Simple, right?
I created the ElementHost, went to select the HostedContent, but the only choice available is UserControl1.xaml, which is a file I created when testing in Remote earlier. This file, however, was completely deleted after I had finished with it. I have searched my entire system and the project and can find no references to it.
I would appreciate it greatly if anyone has any ideas as to why this might be happening; I just want to add map.xaml, but VS is refusing to recognise anything except this ghost file.
Thanks,
M
Your Map Control should be public, for starters.
And make sure you rebuild the lib, and reference the correct build/version.
I must have done something wrong. I have a C# project in Visual Studio 2008. All of a sudden I see a lock on my classes and when I hover the class names on the top tab I see the class name as : C:\Myprojects\Oder.cs[Read Only] !
Has something weird like that happened to you before?
In my case it was a ReSharper 9.0/9.1 related issue. After clearing the ReSharper cache, I was able to edit files in my solution again.
Clearing the ReSharper cache can be done here: ReSharper -> Options -> Environment -> General and click: Clear Caches and restart your visual studio.
(The image is contained within the first of the linked JetBrains articles).
JetBrains instructions:
Ultimate Guide to Speeding Up ReSharper (and Visual Studio) - Performance degradation after ReSharper upgrade
ReSharper Online Documentation
A couple of possibilities spring to mind:
Have you added the project to source control?
Have you marked the project folder (and all it's sub folders) as read only?
Of course, someone else may have done either of these things if they have had access to your machine.
One Possible stupid thing.
Your project is still running and you forgot that. Stop debugging (CTRL + F5)
How do I know. Guess..
Restarting my computer worked for me. My project became read only in between compiles - suddenly I couldn't save changes to files, Visual Studio started presenting me with 'save as' dialog boxes, and SVN couldn't commit or clean the project because "sqlite could not write to readonly database." Checking the file properties on the files in Windows Explorer showed that none of them were marked read-only. I was able to make a backup copy of the project, then I restarted and it was fine.
Restart your Visual Studio and add the project again. Worked for me.
Close, then reopen the file.
Still a pain, but at least it's less costly than completely closing visual studio.
You can try: file -> Source Control -> Go online
IDE-integrated source control?
Sounds like your source files are or have been under source control. Many source control systems will set files to read-only when they haven't been checked out for editing.
Total Commander makes it really easy to change file attributes recursively, but most likely Windows can also do this :)
Much in line with what Morten Mertner said, (if you by chance are using TFS Source Control like I am) I did a manual checkout of the file and it resolved the issue for me.
For me the problem is that the files are locked while the application is running.
In this state, Visual Studio 2013 displays the lock icon in the file tab and when you try to edit the file, a dialog box with this message appears:
Changes are not allowed for this module as it was not built for changes while debugging or the target .NET runtime version does not support it.
In Visual Studio 2015 as well, the lock icon appears in the file tab when the application is running. but the dialog box and message are not displayed.
Stopping the application causes the file to become unlocked.