Reverse engineering a .Net web app. Errors after deploying - asp.net

I'm attempting to do an update to something that I have no code for. I have pulled the source using Reflector, created a new project and can build it successfully after my changes. I can run a local copy pointed at the proper database with no issues.
However, when I deploy to the site I keep receiving the error.
Could not load file or assembly 'xxxxxxxx' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
I don't see anything in the web.config that would make me think it's looking for a specific version, and I saw nothing in the GAC.
Where do I go from here?

Related

Partial ASP.net deployment issue - "Could not load assembly "App_Web_xxx.dll", make sure that it is compiled before accessing the page"

I am using Visual Studio 2017, and the application target .net framework is 4.5.2.
This application ABC (to which I am providing an enhancement) is already deployed and functioning pretty well.
Now that I have to only perform changes on 1 page (a simple condition change), I am planning to deploy only App_Web_xxxx in the ".\bin" folder.
After publishing the application using the "Precompiled" configuration, I was able to identify the respective App_web_xxx.dll file and copied in App. Server bin folder. Renamed it according to existing requestEdit.aspx file. All looks good till now, and interestingly, this App_Web_xxx.dll is common for multiple aspx files available under a common folder (users/request).
Once I try executing this code by accessing the website (respective aspx.cs UI file), it gives the error:
"Could not load assembly "App_Web_xxx.dll", make sure that it is compiled before accessing the page".
But the issue is This dll file doesn't break for any other aspx page available under the User/request folder, it is failing only for feature I modified.
What I have done apart from above mentioned way (considering usual way of partial deployment process):
Replaced requestEdit.aspx page and added new dll, by keeping old dll as is (which can be used by other aspx pages in deployment folder)
Error changed to:
Could not load assembly 'App_Web_xxx.dll, version=0.0.0.0, Culture=neutral, Publickey Token=null' or one of its dependencies.The system cannot find the file specified.
Replaced requestEdit.aspx page and added new dll, by removing old dll and renaming App_Web_xxx.dll in "Imports = Default.aspx, App_Web_xxx.dll" in all required aspx files (for which the old dll was removed)
If I am replacing the whole solution (except web.config) the solution works fine with no issues, the only problem comes when I am replacing only 1 .dll file.
All the solutions I found are providing information of IIS version or dll copying from Server to Dev, but my problem is I'm publishing on dev env (local machine) and partially deploying on the server.
Need help to resolve this issue as this is really inconvenient to deploy the whole solution just for 1 condition change!
Additional Info:
Page Properties --> MSBuild Options --> Allow this Precompiled site to be updatable (checked)

Where Does ASP.NET Store Assembly References Other Than web.config?

I am getting the classic exception
Could not load file or assembly 'XXX.Base, Version=11.0.0.0, Culture=neutral, >PublicKeyToken=xxxxxxxxx' or one of its dependencies. The located assembly's >manifest definition does not match the assembly reference. (Exception from >HRESULT: 0x80131040)
The assembly D:\xxx\xxxx\xxx\bin\xxx.xxx.xxx.xxx.dll was found but could not >be loaded.
It might have the same name as the referenced one but different version, >culture or public key token.
I know there are tons of these posts on SO and all over the web, but I have one question to which I have not been able to find an answer. Where else, other than web.config, does an ASP.NET get these version numbers from? In the references section of my app, the version is listed as 9.0.0.0. However, when I compile the app and put into IIS, I'm getting exceptions for the wrong version number.
I have already tried:
recompiling the app,
restarting the server,
restarting IIS,
clearing the ASP.NET temp files
restarting the app pool,
putting a newly recompiled version of the app onto the server,
checking the web.config (I can't even find some of these dlls referenced at all in the web.config file)
checking the packages.config file (it's not in here either)
Are there any other spots where these references are stored? I know that in visual studio I can expand references, but I'm assuming that list is stored in a file somewhere and I'm wondering where that file might be?
Where does my app get the idea that it needs version 11.0.0.0 of the assembly when it's listed as 9.0.0.0 in references?

Could not load file or assembly 'NuGet.Server, Version=2.11.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies

So I have created a NuGet Server via an ASP.Net Web Application following this tutorial: http://nugetserver.net/ which is hosted in IIS. I have placed the files on my D: drive on my server along with my packages.
IIS Sites Virtual Path:
I get the following error when I navigate to the url:
In case the picture is not clear enough, please see below:
Could not load file or assembly 'NuGet.Server, Version=2.11.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Here is my project's web.config file along with my publishing profile:
My target .NET Framework version is 4.6 but the packages themselves are those of an earlier version of .NET. Could this be the problem? I took the project folder and put it on my physical path on my local machine and it works just fine when I run the project in debug mode. Please see screenshot below:
NOTE: I have to hide the package names due to organizational confidentiality policies.
I am pointing to these package files:
D:\Backup\Dropbox\vox_server_01\nuget\Packages
The reason I am creating this NuGet server is because the existing one is buggy.
Could this be a permissions thing to the users group in IIS? This link Could not load file or assembly 'someProject' or one of its dependencies. Access is denied lead me to that question. Any suggestions on how I can get around this?
Update: Here are my package sources below:
I could not replicate your error, but here are some notes how nuget server problems can be solved:
The packagesPath key in web.config can be left blank, as you are already using the default folder \Packages.
When deploying to the server, you might find an error in the line of Access to the path server.cache.bin is denied. Just create a blank file with that name on your server.
Came here because of the same problem. Funny enough, I had my solution named "Nuget.Server" as well. Changing my Assembly name (under project properties) fixed it. Renamed it to "NugetServer"
If in your Web.config you have a reference to this NuGet.Server package, delete it from the file and try running again. Fairly similar to a BadImageFormatException from a bad reference in the web.config

Using SMO on web server with ASP.NET

Is it required to have anything SQL Server related installed on a web server in order to make use of SMO? I've built a web app that programmatically creates a SQL Agent job, adds a step (which ultimately fires of dtexec to run an SSIS package), and executes.
This works fine on my local machine which has SQL client tools installed, however when I move to a web server, I get reference issues and I'm starting to think it's due to something not being installed.
Could not load file or assembly 'Microsoft.SqlServer.SqlClrProvider, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies.
This is a rat hole.
The problem is that once you locate that assembly and copy it to the bin folder of your application it will complain about a completely different one.. or even the same file simply due to missing dependencies.
For more information read this: http://www.sqldbadiaries.com/2010/10/20/how-i-fixed-could-not-load-file-or-assembly-microsoft-sqlserver-smo-version10-0-0-0-issue/
That site lists the files you need and the fact you need to register and gac a few files. Quite frankly, you are much better off just biting the bullet and install the client tools on your web server.
Yes, your application requires this assembly in its bin directory to function. This error means that the server doesn't have the SMO (and its dependant) assemblies.
Back in your solution in Visual Studio, right click on the assembly above, and select/change the "Copy Local" to "True". Copy this for each SMO assembly that you've referenced.
When you publish your application, this will bring those .DLLs on your development machine along in your published bin directory.
Check your web.config file for any references as well
search your code for SqlClrProvider

Is there a way to include an assembly referenced using Unity when using publish website?

I'm a using the repository pattern and Unity to manage the dependency to my concrete repository objects. In itself this is not an issue however I am running into a problem when using publish website in both VS and the TFS build process.
I believe the problem is being caused by the fact that although the project which contains the concrete repository objects is referenced in my application, the classes that it contains are never used directly. This is because I am using Unity to create instances of the concrete objects at runtime using the Unity config held in my web.config.
The repository project is being compiled when and included in the output when built but when publish website is used in either VS of TFS the repository assembly is missing. Therefore when the web application is deployed to the web server it is not possible to use it as you are greeted with the error:
The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
This is because Unity cannot find the missing assembly as you would expect.
So my specific question is; Is there a way to ensure that repository assembly is copied to the output directly when publishing the website in VS and TFS without directly using one of the concrete classes in the project?
So with some digging around I have found a solution to my problem. This soltuion only fixes the problm when building with TFS but to be honest with continuos integration I'm not bothered about publishing from VS.
My inspiration came from an answer given by Mike Hadlow
What's the best way to get TFS to output each project to its own directory?
Basically the solution is to modify the build script for web project so that it copies the missing assembly to the publish website output folder.
Here is what I did:
I right clicked on my web project in the solution explorer and clicked 'Unload Project'.
I then right clicked on the unloaded project and clicked 'Edit [Project Name]'
Scrolling right down to the bottom of the file I found the following commented out build target:
<Target Name="AfterBuild">
</Target>
I modified this adding the command to copy the missing assembly:
<Target Name="AfterBuild">
<Copy SourceFiles="$(OutDir)[Missing Assembly Name]" DestinationFolder="$(OutDir)_PublishedWebsites\$(MSBuildProjectName)\bin" SkipUnchangedFiles="true" />
</Target>
Now when building the solution in TFS the missing assembly is included in the bin folder of the published website output.
This solution could be used to copy any other missing content to the published website output. As the files that you want to copy are likely to be different for each project doing it in this way is probably the best option. I am however thinking about creating a custom version of Microsoft.WebApplication.targets which copies minified CSS and script files.

Resources