Compiling ASP.NET project versus NET4.0 with NET4.5 installed - asp.net

I have an ASP.NET project that was working correctly compiled with Visual Studio 2010 and NET4.0.
Then I have installed VS Express 2012 and NET4.5 and I always get an Exception trying to open a SqlConnection.
Can I have some chance to recompile my project targeting NET4.0 (so without disinstalling 4.5) and have it working?
In VS Express 2012 I have this web.config:
<system.web>
<compilation debug="true" targetFramework="4.0"/>
The referenced assemblies correctly target the v4.0, for example:
Assembly System.Data
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll
EDIT 2
As this blog http://blogs.msdn.com/b/msbuild/archive/2007/04/12/new-reference-assemblies-location.aspx and also this answer https://stackoverflow.com/a/8543850/1012244 explains very well, there is a BIG difference betweeen Referenced Assemblies (folder contains those assemblies that ship with the x.xx Framework which are useful for referencing during the design and build of new components) and Runtime scenario (At runtime, these components will still be loaded from the GAC in most cases).
However, when I run the project I always get the Exception, as if the project actually was using NET4.5... Why?
PS. If I deploy this project on a production server machine with only NET4.0 installed, the connection is fine.
(This is clear now: Installing Net4.5 essentially replaces Net4.0)
UPDATED QUESTION -
Can I have some chance to recompile my project targeting an OLD NET4.0 .dll (System.Data.dll in my case) instead of the new Net4.5 dll?
EDIT - Additional info
At this MSDN link http://msdn.microsoft.com/en-us/library/ff602939.aspx I found:
If you determine that a change in the .NET Framework 4.5 has broken your application, check the Runtime Settings Schema to determine whether you can use a runtime setting in your application configuration file to restore the previous behavior.
Could this help me? And how?

Related

error when deployed to azure

When i Publish my project i m getting this error:
error CS0009: Metadata file
'D:\home\site\approot\packages\Microsoft.ApplicationInsights\1.1.1-beta\lib\net45\Microsoft.ApplicationInsights.dll'
could not be opened -- Invalid COR20 header signature.
(I m using asp.net core 1)
Did Someone knows or has experienced the same problem?
Thanks
This problem can occur when you have added a third-party DLL to your application and have not properly added it to your compiler’s project file or references list.
If that's the case this might work:
Open your project in Visual Studio .NET. Make sure the DLL exists and has been properly added to the reference list. If you are using VBC or CSC to compile your project, check your application’s CompileApplication.rsp file to make sure the DLL is in the /references list like the other DLLs.
Your DLL may not be compatible with .NET or with .NET’s 32-bit mode. Ensure that your DLL is .NET compatible.
If your project still won’t compile properly, try switching your application’s compiler selection in Iron Speed Designer’s Application Wizard from 'vbc.exe' or ‘csc.exe’ to Visual Studio .NET or vice versa. Using Visual Studio .NET will take longer to build than .NET’s VBC or CSC built-in compilers, but Visual Studio .NET will resolve all of the references properly without having to change your application’s CompileApplication.rsp file.

How to install ASP.NET MVC 5 on a server?

I just updated my website from MVC 4 to MVC 5.
Now when I want to run it on my web server instead of my development machine it does not work.
It think it is because I need to install the MVC 5 libraries on the server but I can't find them.
I downloaded WebMatrix 3 hoping it would provide a way to install it but it only gives me the ability to install MVC 4.
What should I install to be able to run a ASP.NET MVC 5 application?
(without installing Visual Studio 2013)
EDIT:
I disabled custom errors and eror what I have:
Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
EDIT 2:
I found out that the problem was due to one of my dependencies which was using the version 2.0.0.0 of razor.
When you deploy your app just make sure that all the assemblies are being deployed to your production environment in the bin folder. ASP.NET MVC is an xCopy deployment, so you don't have to install anything.
You might want to check that your Production environment has ASP.NET 4.0 and 4.5 registered.
MVC5 and future version of MVC doesn't require to installed on Windows Server. MVC5 app have everything as packages. You didn't need anything to install it.
What is required on server is copy of every library and assembly that you have used in your app. For fix this, Just make sure that everything on your bin folder is called same on server instead of server is looking for it's own GAC for assembly used in your app.
If you didn't found all the packages then you can install nuget packages on server by cmd.
The best is to do a Publish, right click on your project in Solution Explorer and select 'Publish'. Basically it will compile your solution and dump all the assemblies/artifacts to either your webserver, ftp or a local folder.
Make sure all your assembly references are being copied to the deployment directory. To do this you can change the <Reference...> tag in your .project file. Optionally, you can use visual studio's property setter to set the "Copy Local" property of each dll reference to "True".

VS2012 / IIS7 building website causing conflicts

I have an old website (asp.net 2.0) that is running on IIS7 on a server happily.
I want to make a change to the code, so I have copied all the source code and appropriate binaries to my desktop (running VS 2012).
However whether I am using IIS or the inbuilt webserver I am getting the following error;
The type 'foo' in 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\livesite\169c38ce\cc32b84b\App_Web_qbel5zk4.28.cs' conflicts with the imported type 'foo' in 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\livesite\169c38ce\cc32b84b\App_Web_m030ztdd.dll'. Using the one in 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\livesite\169c38ce\cc32b84b\App_Web_qbel5zk4.28.cs'.
This same code worked fine on an older XP PC running VS 2005. I am assuming that this is down to the .net framework, the app pool in iis is set to run as asp.net 2 classic, but the assemblies are being generated under v4 of the framework.
I have tried deleting temporary asp.net files and I am still getting the same issue.
There is only one instance of each of the classes it is objecting about in the project. So how do I fix it so that this works in VS 2012, but still using .net 2.0 ?
Maybe it is a matter of dynamic compilation. By default the "batch" attribute of the "compilation" element in your web.config is true. Something like this :
<compilation defaultLanguage="c#" debug="false" batch="true" targetFramework="4.0" />
With batch="true", whenever a control has to be compiled in a directory, the server compiles all controls (everything?) in its directory.
That may results in conflicts for elements referenced from different locations in your site.
You should try to set batch="false" and to remove your temporary files.
If you still encounter problems, try to do a dummy edit-and-save on the corresponding ascx/cs files.
Hope this will help

ASP.Net build error - assembly not referenced

I am getting a build error when I attempt to build my asp.net application. The error is:
The type 'MediCare.Framework.Authentication.IUserAuthenticate' is defined in an assembly that is not referenced. You must add a reference to assembly 'MediCare.Framework, Version=1.0.1.95, Culture=neutral, PublicKeyToken=1999fa3c42b9'.
I can see the class in the library which is in the references folder. How do I debug this issue?
My intention is to point the references folder to the library source code's bin directory (since the pdb file is lcoated there and any updates to the library will reflect in the application). However, when I point the references folder to the bin directory of the source code, I get the error message above.
Update The application was originally developed in VS 2008 and I am modifying it in 2010. I think I am confused about where the GAC assemblies would be, if I am using VS 2010 (2.0 framework location or 4.0 framework location) ? .NET 4.0 has a new GAC, why?
Update (06-26-2012)
The file in the GAC ("C:\Windows\assembly\") has been deleted. But this error is still occuring.
This could possibly be caused by version inconsistencies. Meaning, in order to fix this, I would do a complete clean build of your assemblies (and also an assemblies that might be nested inside an assembly). Just go out cold and do a new build on all assemblies. That should work.
Go into windows explorer, right click on the DLL file that your project is using that contains this class, and look at the version tab. Make sure version number matches what you see in the error message. My guess is that it won't.
If it does match, then check the GAC and make sure there isn't a different version of the DLL there that it could be picking up. To do that, go to windows explorer, and navigate to c:\windows\assembly. See if that assembly is in there with a different version number. If it is, you may need to delete it from the GAC (use caution though because other apps may depend on it being there).

Where does ASP.NET look for binaries when you compile an ASP.NET 4 web project under x86 (32-bit)?

I'm developing an ASP.NET MVC 4/Web Api application in VS 2010 on my 64-bit dev machine. I have IIS installed and am running the project under IIS. Because I need to interface with a third party component, I have to change the project build configuration to x86 (I'm currently in the Debug build).
In IIS, I configured the application to use an application pool that allows 32-bit processes. However, when I ran my site, I noticed that code changes I was making were not showing. It turns out that the assemblies being used were those found in the \bin folder. After changing the configuration, the compiler's assembly output goes to the \bin\x86\debug folder; it didn't look like IIS was looking there.
I temporarily switched the configuration back to "Any CPU", right-clicked the project node, and selected the Clean option. This removed all the stale assemblies in the \bin folder. I then switched back to the x86 configuration -- rebuilt the project for good measure -- and tried to run the project again. Now it wasn't finding any assemblies at all. I'm getting errors like:
Could not load file or assembly 'System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies
System.Web.Providers -- and all the rest of the assemblies -- reside in \bin\x86\debug.
Is IIS supposed to know to look there?
Is Visual Studio supposed to copy the assemblies up two levels to the \bin folder?
If the latter, that is clearly not happening. Thanks for any insight.
The solution was simply to set the Output Path to bin in the Build tab of the project properties. :-)

Resources