Instantiating VisualStudio 2008 - c#

I'm trying to get a list of all projects within a specified VS2008 solution. (this is a stand-alone console app, it is not a Visual Studio add-in)
My code works with VS2005 solutions, but I get all sorts of ugly COM errors trying to use the VS2008 object.
What I mean is:
This:
Type _visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.8.0");
DTE _dte = Activator.CreateInstance(_visualStudioType) as DTE;
works and this:
Type _visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.9.0");
DTE _dte = Activator.CreateInstance(_visualStudioType) as DTE;
doesn't (currently throws COM error 8001010a)
I have both relevant classes registered in the registry, and all appropriate assemblies are referenced.
Edit: I'll go with basic parsing of the .sln file, even if I have to do a bit of rewriting, as text manipulation is bound to work without all the nasty interop stuff.
However, I can't seem to find a description of the .sln format, any resources?

You may want to look at this: Library for parsing Visual Studio Solution files? If parsing the .sln directly turns out to be your only option.
As to your current problem, some other people have had your issue. The KB246018 says check out your antivirus as the leading cause (example is word, but same applies to VS). Try excluding the VS directory entirely.

You are getting an RPC error: "server is busy". That might be because Visual Studio is actually busy, debugging your console mode program. Short from debugging with Console.WriteLine() statements, try another debugger. The Windows SDK has the clrdbg.exe and mdbg.exe debuggers. The .NET 2.0 SDK had a GUI debugger iirc.

Related

Error CS1583 intermittently appearing when building C#/WPF project

I have a C#/WPF project built on Visual Studio 2013 Professional for work.
This project was originally built on a Windows 10 platform, but has been moved to another computer running Windows 7.
I have found that the project can be successfully built when the program first opens, and I have chosen "clean solution" first. After any change is made, an error appears (Note that I have removed the company name from the line):
"CSC : error CS1583: 'd:[Removed company+project name]\obj\Debug\CSCB4E1285F65D54791A82C162F265D41AD.TMP' is not a valid Win32 resource file".
I have searched for solutions and a common thing suggested is that there may be problems with an .ico files. I completely removed my icon file from the project and it did not resolve the error.
The Microsoft information on this error is:
"This error occurs when you specify a filename with the /win32res compiler option that is not a valid or correctly formatted Win32 resource file. In Visual Studio, the filename is specified in the Application pane of the Project Designer." I've looked in the Application pane and I could not find any /win32res options...
The building process itself is prone to hanging - Stopping at different points. I stop, clean solution, and rebuild which often gets a different result.
What could I do to better diagnose the error? Are there any tools that allow me to see where something went wrong?
Is there something that I have overlooked?
Any input would be great.

"Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception": should I reinstall?

I suddenly get this error whenever I try to add a new item in VS 2013 Express:
Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception.
In addition, every .cs file is corrupt. VS was working correctly yesterday. I haven't made any configuration changes or installed any add-ons.
The discussions here, here and here recommended the following possible solutions:
launch Visual Studio in Safe Mode
run devenv /resetuserdata (in this case it's wdexpress), then restart the computer
uninstall various tools and add-ins (I don't have any installed)
None of these solutions worked for me; the error still occurs under all conditions.
This happens whenever I try to add a class or reference or any other new item.
Update: I reinstalled Visual Studio and the problem still occurs. However, it appears to be confined to a single project, as I can make a new project and add classes to it. So maybe that project is corrupt somehow?
I checked out the most recent commit versions of the corrupted files, and that seems to have alleviated the problem. I can add classes now. Interestingly, when I was in Git Bash and tried to read one of the corrupt .cs files using less, it informed me that it was a binary file.

Add C# code to exe file directly without using the build command from visual studio

I have an exe file for my application using visual c#.
Whenever I have to change, I go to visual studio, change or add the code and build the application.
So that my exe file will be updated.
Now what I want to do is I just want to add new changes c# script to exe directly.
I don't want to build the application from visual studio again and again whenever I have to change the code in application.
Because sometimes it's take too long to build for big application.
Is there any tools or way to do it?
Thanks.
Uhm no.
The most you can do is avoid visual studio, edit the source files using a lightweight editor, and re-compile the assembly using msbuild (e.g., msbuild.exe mysolution.sln).
If your project is large, building it can take some time. If you only need to change a small portion, you should seperate your project into smaller assemblies so your change in one assembly does not force a rebuild of your whole infrastructure.
If we're talking purely about building a project outside of visual studio then use an MSBuild scipt.
There is a decent tutorial here: http://goo.gl/MOseG
Note that you can reference static assemblies if you only want that project to be built, but be aware of stale references!
Now, let's have a look at the source of a your problem, large build that take a long time. I susggest you read here:
http://msdn.microsoft.com/en-us/library/ee817674.aspx
It may be wise to split you solution into several sub solutions.
Well you could seperate that file which you change often into an own assembly and just rebuild that assembly. Of course you need to make an reference to that assembly in your application.
Have you tried commandline compiling? It can be faster then Vs cause you dont have to open Vs (if you changed you code in notepad for example). Otherwise it nearly takes the same time (or longer cause you have to type in paths).
csc /out:YournewExe.exe YourFile.cs
Csc is the c# compiler and can be found at C:\Windows\Microsoft.NET\Framework\Version
Further information can be found here Click
Why don't you just save your project file everytime instead of building it? And when you finish working on it for today,just build the app then.
You don't have to test the app everytime through the .exe file,do you?

Visual Studio "Rebuild all failed"

Why does Rebuild fail with no errors?
Since this morning, this error keeps showing up. I build the entire solution (25 C# managed projects) and a "Rebuild All failed" appears, but without any errors! (I have 13 warnings about COM not supporting Generics, but it's "normal" because one dll is exposed as COM.)
Not an answer per se - but you're better off looking at the output window and seeing what it says there.
Also, to help with that you might want to look at your MSBuild verbosity - as shown on this screenshot (last two options):
Beware - the highest level generates a MASSIVE amount of information.
Finally - running msbuild from the solution folder in a command prompt will really nail the issue - because error messages and warnings come up in red and yellow respectively.
I found my own solution and it is simple:
When this error occurs, save the project and close VS 2013. After that, re-open VS2013 and open the last project.
It works like a charm. But it is very annoying every time!
Many people reported this problem in VS2010, VS2012 and VS2013.
Could be a corrupt Solution User Options file.
Close the solution, delete its .suo (.v12.suo for VS2012+), reopen the solution, and Visual Studio will build a new one. You will lose the StartUp Project, breakpoints, bookmarks, which files are open, which projects/folders are expanded, etc. But that's all minor compared to the solution not building!
I had the same problem. I was trying to refrence a higher .net framework version(4.5.2) to lower .net framework version(4.5) which was causing build error. I made the version same in both projects and it worked.
Check the Output Window (View -> Output) as that will tell you what's going wrong. Sometimes a reference might be missing or there is an issue with the targeted version of .NET for one project in a solution.
Have you tried to clean the solution befor rebiuld it?
This is the list of checks & things I would do if I were you (try to build after each step):
Is error list activated? (Sometimes I forgot to activate and I can see only warnings & messages)
Check output window for error messages..
Clean solution.
Double check after clean that everything is deleted from debug folders.
Build it in release mode.
Build solution project to project until you isolate problematic project.
Remove COM and comment code to see if is this the source of problem.
Restart VS2010.
Restart windows.
Few moments ago I fix it with repair of .NET Framework installation (.NET Framework v4.0 Extended in my case).
I had the same issue in VS 2015. I tried the following with no success:
Close VS project and reopen
Close all open VS projects and reopen just the project that had the issue
Clean solution
Rebuild solution
Delete all files in bin\debug and bin\release
Lastly I tried Keith Robertson's answer, delete .suo (\Visual Studio 2015\Projects\[ProjectName]\.vs\[ProjectName]\v14\.suo). Although this didn't get me a good build, it did finally give me an error message stating that I had two entry points to my application. I went to application properties (Alt + Enter) and select a Startup object from the drop down.
This error seems a bit generic to me. I also went through this situation, but I managed to solve it differently than any of the ones mentioned here.
I have a project and several dependencies. And one of these dependencies has undergone a change.
When compiling the main project in debug mode, I verified that everything was ok.
However, switching to release mode and recompiling the problem occurred.Rebuild all failed and 0 Errors
By analyzing the debug output, I encountered an error:
Although the build dependencies are configured correctly. When compiling in release mode, the main project did not find the new method created in the secondary project.
So I had to recompile each secondary project one by one in release mode. After that, I recompiled the main project and everything worked.
Hope it helps someone!
I just had the same thing. For me, it helped to restart VS and run it as Administrator.
Select the appropriate target framework
- Right click on project
- Properties
- In application tab, Select the target framework
clean the solution
Try and build each project and see where the issue is.
Check each of the references (of each project) to make sure not have the yellow warning sign
Has the solution ever built?
I just had this happen to me, and realized that I left a '#error' line in my code and forgot about it. When I tried to build, the build failed but the #error line didn't show up in my errors.
Try searching all for '#error'
I fixed it on my new implementation of Visual Studio 2013 by going to the database project / Project Settings and noticing that the Target Platform was SQL Server 2014 instead of 2012 like it should be.
Once chance of getting this error is when we try re naming the service reference name, we give some other name in the service reference, but in the namespace some where it will be referring the old name, so if you delete and add a service reference then keep the same name, else we may face this error, but we can see the error in the Output window.
There are apparently many causes of this. I just found the cause of my issue: the .NET version of a new project I created was higher than the version of the top-level project. (4.5.2 vs 4.0)
I got a similar issue today, and fixed it with repair.
Start
Run…
Appwiz.cpl
(Find your installed Visual Studio version)
Right click
Change
Repair
In my case it was the wrong date and time of computer.
I was getting no feedback/messages/errors. Just that all projects failed to build.
I closed and tried again--I noticed an error saying "you are not authorized to access..."
I clicked on my account, re-entered my credentials, and rebuilt the solution.
Voila! I got what I am used to seeing when I build a solution -- plenty of errors in all their glory.
Hope this helps someone.
Here's yet another reason which may sound familiar to some. I had integrated some code into my solution that wrapped a DLL. The C# code file that came with it offered a nice managed API and handled the low-level LoadLibrary stuff to access the DLL. Both had the same base name, so I had SomeName.cs and SomeName.dll. I could just drop it into any project and it would work.
This wasn't so nice after a while as I started using it in different projects. I got copies of both the DLL and the wrapper code in multiple projects. So I figured it would be better to drop the wrapper code and the DLL into a new class library project and then reference that new project from other projects.
After I had done that, I started to get this issue. The build went well up until the very last stage and then failed without error. Output showed nothing but successes.
The problem was the name of the wrapping class library project. I used the same base name (SomeName) for this. By default the assembly name would be SomeName.dll and I already had one such file (the DLL to be wrapped), thus I had a conflict with output files.
After renaming the wrapping project and its output assembly to SomeNameWrapper, the problem went away.
This may not be your exact cause but it seems likely you have some name clash or deployment issue as well. And it is not surprising the compiler won't give you an error because there is no problem in the compilation phase, the trouble starts with deployment and apparently this does not come out in an obvious way.
I had the same problem the original poster was displaying with 0 errors and Rebuild all succeeded. The Output tab showed a message that a referenced dll was built with a higher version of the .NET Framework.
Changing the .NET framework to match resolved the issue I was having with 0 Errors and Rebuild All succeeded.
The solution:
Because Prerequisites not set for debug set only for release
01-Change solution configuration ( in main screen )
set (debug to release)
set solution platform to (Any CPU)
02-Set Prerequisites for debug ( If you want to continue in debug mode )
03-set target platform version for all Projects
Some of the files included in your solution are not in the correct directories, or you have changed the name of one or more directories in your application. In the solution explorer under Setup review the list of all files and remove those that are not properly listed in the SourcePath Property.
One of my dependency in View file caused this. Check your view files for any dependencies which is not injected yet.

"The source file is different...." message in Visual Studio 2008 is result of debugging x32 apps on x64 Windows

I'm writing ADO.NET provider. For debugging I use class DbProviderFactories.GetFactory method. This method constructs my inherited DbProviderFactory class that i use for create DbConnection inheritor of my provider and etc.. When I try set breakpoint in my provider code I sow it isn't work - execution doesn't stopped. When I throw exception in my code VS2008 showed message box describing "The source file is different...".
Debugging works good before day before tomorrow, but it isn't now. Does somebody know "magic checkbox" for resolve my trouble? Any idea?
Update1: Provider assembly is adding to GAC on post build step. Compiler didn't find errors in solution.
Update2: Source code of static referenced assemblies is "different" too.
Update3 and last: I've found source of trouble. I use x64 version of Windows 7. My application use some COM servers (usual native x32 COM Servers) that can't be loaded in x64 context. So I decided run it as x32 app using WOW so I set platform target as x32. But debugger started show messages like "The source file is different....". I don't understand why it works as works. I will write to microsoft support team.
You can tell it to ignore the problem by going to Tools, Options, going to the Debugger section, and unchecking Require source files to exactly match the original version.
To solve the problem, check your assembly locations. Your program is probably referencing a different version of your provider DLL than the one in the debugger. Try removing the reference and adding a Project Reference.
EDIT: Try removing the provider from the GAC (manually or at the beginning of the post-build step)
“The source file is different…” message in Visual Studio 2008 is result of debugging x32 apps on x64 Windows. See new thread
If you are using Visual Studio Express, you probably don't have Build->Clean Solution.
Try to remove the pdb debug file located in C:\Users\yourusername\Documents\Visual Studio 2010\Projects\yourproject\yournamespace\bin\Debug.
If you are afraid to delete the file completely, i would move it to a temporary folder.
Then try Debug->Start Debugging(F5)
Happy coding!
Try doing a clean (Build-> Clean Solution), and then rebuilding All (Rebuild Solution).

Categories

Resources