Visual Studio 2010 : Can't change target. Gives TargetFrameworkMoniker Error - visual-studio-2010

I have a console application which has target .NET 2.0
It is very short but full of unsafe code.
I converted it to VS 2010. I run it OK.
When I try to change "target framework" in properties to 3.5 or 4.0 it shows message box:
TargetFrameworkMoniker: Error parsing application configuration file at line 0. XML document must have a top level element.
the target then stays 2.0 anyway.

This happened to me because my project file was marked as "Read Only" in its properties. Changed it, and it was fine.
It also could be caused by read-only app.config/web.config

Found the solution. Simply opened app.config in text pad (it was empty for some reason) and pasted:
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

For me the problem was the web.config file located outside of the project directory.
I moved it back in, and was able to change the target framework.

I have same issue. I solved it by removing write protected attribute of web.config file. It was read only earlier.

For me, my project was using a web.config file that was a linked file back to a web.config in another project. I removed the link, changed the target, then added the link back.

I faced this problem , i solved it by click app.config to open it and leave it ,then go to properties and upgrade .NET version

I was trying to retarget from .NET 4.5.2 to .NET 4.5 In my app.config, I had to change
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
to
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
before the project properties page would let me retarget.

Related

Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code)

Visual Studio 2017 breaks in debug mode and displays the message:
Your app has entered a break state, but there is no code to show
because all threads were executing external code (typically system or
framework code).
The message is in the Break Mode Window.
What to do?
Click on "Continue execution"
Then you will have the stacktrace in the output tab
First check all your common exception setting run time in your visual studio so that you can get the actual error.
During loading you application check that is their any method which is throw new NotImplementedException();
In my case i use INavigationAware which was throw new NotImplementedException();
i just remove those
In you all project update all from nuget.
Clean and rebuild you project.
In my case I just need to restore the list of exception settings to the default settings.
I hit this earlier today with a C++ console application. Disabling "just my code" and selecting the Microsoft symbol server fixed this issue.
Tools → Options → Debugging → General → Untick "Enable Just My Code"
Tools → Options → Debugging → Symbols → Tick "Microsoft Symbol Servers"
I got this situation when my "Platform Target" in my Project Properties was set to "Any CPU" and "Prefer 32-bit" was selected.
I switched Platform Target to "x64" since I am using 64-bit assemblies and then I could run/debug normally.
This solution is for people who get this error in WPF application. I got this error when i moved mainwindow.xaml to view folder and forgot to update in App.Xaml. after updating as StartupUri="View/MainWindow.xaml" the main window loaded without warning.
For me, I received the error when my console application was set in Release Mode. Switching to Debug mode fixed the issue.
Check for any case of circular dependency while injecting dependencies.
This type of issue please check property and Accessories.
We should return correct field and check value field.
Example:
private string NameField;
public string Name
{
get
{
return NameField;
}
set
{
nameField=value;
}
}
Just had a similar issue in VS2019, I ended up needing to rebuild all in order to resolve the issue despite having manually built many times.
First drag the Break Mode Window to the Call Stack Window to get an overview again.
Then, check whether the Solution Explorer Window is in source mode.
The 4th button from the left has a drop-down. Make sure the *.sln, i.e. classic solution mode is selected.
I didn't know this and was surprised to find that in "source mode", i.e. the other possibility, the above mentioned message is displayed.
I got this when I accidentally set the startup project to a class library instead of the end project (in this case, a WPF application).
Observed same error and resolved it by:
Removing duplicate configs from section
Removing extra/unused characters (by mistakenly entered)
This occurred for me when I placed the connectionStrings config item in the wrong spot in app.config.
check your Ip address (it must be the same as the listening adress if you'r not using the loopbach address)
I got similar issue, after spending 2 days we figured out it was due to my application was terminated from out side at the same time I was debugging.
Error: IOException Cannot locate resource
Most of the time this error occur when using visual studio form applications.
To solve this error you can go to your App.xaml file and edit SratupUri to your current xaml form name.
<Application x:Class="AppName.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
You can also experience this issue if you've altered the build process with something like this to remove the PDB files. Typically I recommend if you want to remove the PDB files make the configuration specific to the "Release" configuration:
<Target Name="RemoveTranslationsAfterBuild" AfterTargets="AfterBuild" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<RemoveDir Directories="#(FluentValidationExcludedCultures->'$(OutputPath)%(Filename)')" />
<ItemGroup>
<PDBFilesToDelete Include="$(TargetDir)\*.pdb"/>
</ItemGroup>
<Delete Files="#(PDBFilesToDelete)" />
</Target>
Then Follow #Eric's recommendations when debugging run the build under the "Debug" configuration.
Had the same problem, this was due to having the build set to release build. Then when asked if I would like to debug, I accidentally clicked ignore always.
I changed it to debug mode in the properties settings but the error was still there.
You will also need to change this in the configuration manager from Build/configuration manager and set Configuration to Debug as well.
Same here. Reinstalling VS 2019 solved it.
Even though this is an older post, I thought the solution to my problem could help others looking for an answer to this problem.
Using the above suggestion from Led Machine - to see the stack trace, I found the following top lines.
Exception Info: System.NullReferenceException at System.Web.ThreadContext.AssociateWithCurrentThread(Boolean) at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean) at System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(System.Threading.SendOrPostCallback, System.Object)
Googling this stack trace, sent me to this page:
https://techcommunity.microsoft.com/t5/iis-support-blog/crash-at-system-web-legacyaspnetsynchronizationcontext/ba-p/1536553
Apparently, the problem was related to my application being configured to use Legacy ASP.NET Synchronization Context, and in certain parts of the code, I was using some new features, such as Tasks. The old (Legacy) context cannot handle some asynchronous calls properly and this leads to the crash as observed in the above.
The fix is to insert the following line in your web.config:
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
I had a similar issue when debugging a VSTO Excel add-in. After trying everything, I resolved the issue by disabling a realtime protection module on my antivirus software.

Using transformed Web.config with IIS Express during debug

I have a Visual Studio application that has multiple Solution Configurations. There is a Web.config transform file for each configuration. For example, Web.Debug.config, Web.Release.config, etc.
We also have a couple of developers working on this project that have nonstandard SQL Express instance names due to the way they installed SQL Express and rather than having them continually editing Web.Debug.config to run in their environment I have setup a Solution Configuration for each of them and added the following to the very bottom of the .csproj file. This code does work in that it triggers the creation of Web.config and MyWebApp.dll.config in the VS /obj/Debug-DeveloperName/ folder.
The transformed .config files are perfect, but IIS Express still uses the root Web.config (not transformed).
Is there a way to get IIS Express to use these transformed Web.config files while debugging locally?
<UsingTask
TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target
Name="AfterCompile"
Condition="exists('Web.$(Configuration).config')">
<!-- Generate transformed config in intermediate directory -->
<TransformXml
Source="Web.config"
Destination="$(IntermediateOutputPath)$(TargetFileName).config"
Transform="Web.$(Configuration).config"
/>
</Target>
Using the web application's Web.Debug.Config works for most of us, but not all.
There must be a way of getting IIS Express to use the transformed Web.Debug-DeveloperName.config during local debug?
Does the transformed Web.config have to be copied into a different folder?
I faced this problem before and I found a solution. Unfortunately, the solution is not based on forcing IIS to use different name of the config, but if you follow steps below, you will just select the configuration and run you app (which is ewhat you need I think). The Web.config transform will occur before build and it will replace the original Web.config by the transformad one. Then, when the deployment (to local IIS Express) begins, it will already use the transformed one.
Here is step by step how I did this in one project (VS2012):
Right click on the project and select Unload
Right click on it again and select Edit
Go to the bottom of the file and append the follwing to the right over the "</Project>" tag (it will be last item)
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets" />
<Target Name="BeforeBuild" Condition="'$(PublishProfileName)' == '' And '$(WebPublishProfileFile)' == ''">
<TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
</Target>
The condition there is to prevent duplicate transformation when publishing.
Save the file, right click on it and select Reload
Now, everytime you run a build, your Web.config will be transformed according to selected configuration.

error - One or more projects in the solution were not loaded correctly

In VisualStudio2010 I changed the name of the project and the name of the solution.
When I try to open the solution I get this error:
One or more projects in the solution were not loaded correctly.
Any idea why I get this error?And how to fix it?
Try opening the .csproj file in notepad and making sure all references and paths are correct.
In my situation, I had the GlobalSection duplicated in my solution.
I'm using TFS and sometimes it has trouble to merge configuration from multiple developers at the same time.
Open your Solution (.sln) in NotePad++ and look up for this tag and remove one from the duplicated.
GlobalSection(TeamFoundationVersionControl) = preSolution
You may need to readd the last projects to the solution though.
I got the same trouble when using VC2012. My steps for it are: Control Panel --> Program & Functions --> Right Click on VC2012 --> Select "Recover" --> restart Windows --> re-open the project. It works.
The trouble comes from the damage of VC2012 iteself.
Try to open the application as a website instead of project. In my case the project/application was created as website and when i was trying to open the solution it was giving me the error so i opened the application as a website and the application got loaded.
Check .sln and .csproj files to see if any unused references are added without knowledge
I got the same issue after the code merge. The issue was few closing XML tags were removed. Fix: Open the .csproj file in a notepad and correct the closing tags.
I had this problem, the path for the .csprog files in the solution some how changed, instead of \\server\folder it changed to \server\folder.
Try open the .sln file using the Notepad and check all the .csproj files path.

"application has failed to start ... configuration is incorrect" after upgrading?

I have a project in windows application than was in VS2008. Now I convert it to VS2010. When I want to run my project, I get this message:
"This application has failed to start because the application configuration is incorrect. Review the manifest file for possible error."
How to I can run my application?
Thanks.
I had the same problem where my entire C# solution was created in previous version and it did not work in new VS.Net version giving the same error. Here are a few things that will help you resolve the problem
Expand the References Item and check if any item has a warning symbol attached to it.
If (1) , click on References->Add Reference and try to add the reference which has the warning. Now the warning sign has to go away.
If the references displayed in 'Add reference' dialog box is grayed, you should probably get the reason by hovering next to the reference.
For me it was grayed and it clearly mentioned that the component is not compatible with the current .NET Target runtime. Right click on Project -> 'Properties' and try to change the .NET Runtime and give a shot by compiling the entire solution and try to execute it.
If it still fails , try looking at eventviewer logs by going to Start->Run->Eventvwr
This should be a good way to debug this problem.
Honestly...I deleted the App.config file and Re-build. And started working.
Without understanding what was going on, I was able to fix this issue for a Windows Forms project I had just converted from VS.Net 2008 to 2010.
After conversion the Target Framework was still .Net Framework 2. When I changed it to 4.0, my application could be started and debugged.
In then noticed a new line in app.config:
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
So, just for the sake of interest, I changed the Target Framework back to 2.0 and the line changed to:
<startup><supportedRuntime version="v2.0.50727"/></startup>
The application would still run.
Then, I removed the new line altogether and the application would still run!
Finally, I undid all my changes and started the conversion again. Now, the application would run immediately!
So, if you run into this issue, just try these steps and see if it helps you.
Check discussion here:
http://social.msdn.microsoft.com/forums/en-US/vbgeneral/thread/e60dcbf9-c6a0-47a6-bc37-68d4edc45276
In my case the reason for this error was an invalid app.config. R# renamed the root element from <configuration> to something else (probably because there was another variable that I renamed with the same name).
I found this by following Gopalakrishnan SA'S advice to look in the Event Viewer where I found:
Activation context generation failed for "my.exe".Error in manifest or policy file "my.exe.Config" on line 3. The application config file root element must be configuration.
In my case, I forgot just a simple note,
in the requestedPrivileges you should place one requestedExecutionLevel, NOT MORE
I checked the event viewer to find the error "The application config file root element must be configuration".
It turns out it was the namespace referenced in the app.config.
I had opened it in VS 2015 after it being created in VS 2008

generation of designer file failed

Every few days VS2008 decides to get mad at me and fails to generate a designer file claiming it cannot find the file specified and that it's missing an assembly. Here's the scenario:
The aspx page has a reference to a custom user control (inheriting UserControl) which references another assembly in the backend. There are many other references to this "missing" assembly in other places in code which don't throw errors. rebuilding, updating the source to the clean copy, shouting at the computer, punching the screen, etc all fail to work.
Any suggestions? This is quite annoying.
We've had similar problems before, unfortunately I don't remember the exact solution.
If your using a "Web Site" project (no project file) then start by checking that both your page and your control both set the ClassName property in the first line of your aspx/ascx file and that you specify the full name of the class including the namespace.
Example:
<#Control Language="VB" AutoEventWireup="false"
ClassName="YourProjectName.YourUserControl"
Inherits="YourProjectName.YourUserControl"
CodeFile="YourUserControl.ascx.vb"
%>
Many times not setting all of these will still work but you will get odd compiler errors and behavior in VS.
If you using a Web Site Application project try deleting the designer file manually and then right click on your project and choose "Convert from Web Application." This will should recreate the designer file for you.
My only other suggestion would be to recreate the page and/or the user control from scratch.
Jared, you've hit it. Using "Convert to Web Application" to manually generate the designer file solves my problem. I'm glad you posted this before i started reinstalling. Thanks.
You might try archiving a template of a new file with its designer equivalent. If VS coughs then you can do an "Add Existing" option with the file you already have.
It seems, however, to be an issue with your installation of VS2008 so you might try reinstalling it.
I found that using a custom control, you would need to add a reference to the .dll. This fixed it for me after migrating from a web site to web app.

Resources