WCF Deployment on windows server 2012 - asp.net

I have made an WCF service application and a MVC4 web application.my service uses my web membership provider functions to validate user and my provider uses entity framework to facilitate this validation.Locally when I run multiple projects as starup and use my application with services, it works perfectly.Now I have deployed this web service on windows 2012 server following these steps :
Enable Wcf on windows server 2012.But the problem is that I am getting the following error:
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 system cannot find the file specified.
I have even added system.web.razor in my references of web service but still the problem is there. Any help would be appreciated.

Right click on System.Web.WebPages and select properties. Set Copy local to true. Then publish again and the dll will be copied to the bin folder of the target.

Related

Graph API working in ASP.Net, but DLL assembly error in Windows service

I have an ASP.Net application which uses the Microsoft Graph API (Nuget packages Microsoft.Graph and Microsoft.Identity.Client). The application has two execution modes. In one mode it will run the Graph API calls in the ASP.Net web context. In its other mode, it offloads the process to a Windows service running on the same server, with ASP.Net calling the service asynchronously.
The Graph API calls are working fine in ASP.Net, but when I go to test the Windows service, I'm getting DLL load errors.
System.IO.FileLoadException: 'Could not load file or assembly
'Microsoft.Graph.Core, Version=2.0.3.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)'
The relevant Nuget package versions are:
Microsoft.Graph: 4.3.0
Microsoft.Graph.Core: 2.0.4.0
The windows service executes up to the point where it instantiates the class that contains the Graph service client. Then it goes looking for Microsoft.Graph.Core 2.0.3.0 and throws an exception because the only version available is 2.0.4.0.
I don't know why it's looking for 2.0.3.0. I can't find any reference to 2.0.3.0 anywhere in my project.
It might be worth mentioning that as a post build step I'm copying the Windows service .exe and all .dll files in the service project "bin" folder to a separate folder that the service executes from. I'm wondering if this is the cause of the problem, and there's some other dll that Asp.Net can access, but isn't being copied to the bin folder. I still don't know why the Windows service tries to load an old copy of the dll instead of using the version installed by Nuget.
To summerise:
Asp.Net correctly runs with dll version 2.0.4.0
Windows service fails to load after trying to access 2.0.3.0, which it doesn't have
Both Asp.Net and Windows service are running exactly the same code base. Neither are configured in Nuget to have a dependency on Graph. They both reference a separate project that has the Graph dependencies.
Asp.Net loads the dll at the same point in the code as the Windows service, but the logs indicate its plucking the dll out of the ASP.Net temporary files in C:\windows. The version it pulls is still 2.0.4.0 though, so I don't see any issues here.
Been stuck on this one for several hours. Are there any tools for analysing DLL issues in .Net? I want to know what's trying to access version 2.0.3.0 and why.
Edit:
Here's the assembly binding info. It looks like the service might be ignoring my app.config file for some reason, as it says "no application configuration file found". If that's the case, then it would be ignoring the binding redirect telling it to use v2.0.4.0.
FusionLog "=== Pre-bind state information ===\r\n LOG: DisplayName =
Microsoft.Graph.Core, Version=2.0.3.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35\n (Fully-specified)\r\n LOG: Appbase
= file:///C:/inetpub/SurewayImsDev/ImsServiceBin/\r\n LOG: Initial PrivatePath = NULL\r\n Calling assembly : Microsoft.Graph,
Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.\r\n
===\r\n LOG: This bind starts in default load context.\r\n LOG: No
application configuration file found.\r\n LOG: Using host
configuration file: \r\n LOG: Using machine configuration file from
C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.\r\n
LOG: Post-policy reference: Microsoft.Graph.Core, Version=2.0.3.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35\r\n LOG: Attempting
download of new URL
file:///C:/inetpub/SurewayImsDev/ImsServiceBin/Microsoft.Graph.Core.DLL.\r\n
WRN: Comparing the assembly name resulted in the mismatch: Build
Number\r\n ERR: Failed to complete setup of assembly (hr =
0x80131040). Probing terminated.\r\n" string
Turns out the problem was I hadn't copied the app.config files over. This was causing the windows service to run without knowing how to map the dll files. All working now.

Resolving .NET TypeLoadExceptions in Azure App Service

I have an Azure App Service where I published my .NET application (.NET Framework 4.7.2). The application works fine on local Visual Studio IIS Express.
When I run it in the App Service I get TypeLoadExceptions. The interesting parts are, for example, these errors:
- System.IO.FileLoadException: Could not load file or assembly 'EPiServer.Forms, Version=3.0.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'EPiServer.Forms, Version=3.0.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7'
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Now, in any virtual server case I could just enable the EnableLog registry value and see more about what dependency I am missing. I tried to change the registry value thru PowerShell but got access denied. I haven't found any Fusion Log viewer in Azure either.
What is the correct way to debug Assembly binding errors in Azure App Service?
Browsing through this: How to enable assembly bind failure logging (Fusion) in .NET but it does not say anything about doing it in Azure App Service.
Just wanted to post an update to say that Fusion logging on an Azure App service can now be enabled, there's an article on it here.
Basically all you have to do is add an application setting called WEBSITE_FUSIONLOGGING_ENABLED and set it to 1.
There is no way to get Fusion logging in Azure App service now. Because it's required to modify registry to enable it. But modifying registry is not allowed in Azure App Service. Refer to here for more info.
The error "The located assembly's manifest definition does not match the assembly reference." usually means the assembly the runtime finds does not match that you specified in application.
In Azure web app, you can check the dll via FTP. Check "Accessing files via ftp". The dlls usually locates in \wwwroot\bin. Confirm the dll info matches the dll you use in the solution. You may check web.config and package.config whether you specified different version for this assembly.
Also refer to here to understand how .net runtime locates dll.

Umbraco 7 - moving site getting a Microsoft.IdentityModel Error when trying to login

I've developed a site using the Umbraco 7 CMS system, all works great and I've been able to copy and deploy this to numerous other machines and severs without any issues.
However now that we have tried deploying this to the live server, we are unable to login to the backend Umbraco section. The error is as follows:
Received an error from the server
Server call failed for getting current user
Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Access is denied.
Exception Details:
System.IO.FileLoadException: Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Access is denied.
The only different here is that the live server is administered by a Plesk control panel. So the actual site within IIS were created using this. However we have full Remote Desktop access and have set all the required "full control" permissions. And have checked that we have the correct .NET versions installed. But with no luck.
Has anyone experienced this or have a fix, I've searched Google and can't find anything that works.
Thanks
I haven't run into this myself, but it sounds like the server where you are trying to run your live site does not have the Windows Identity Foundation installed. I'd try installing that on your production server. Alternatively, you could find Microsoft.IdentityModel.dll reference in your solution right click it, open its properties and set Copy Local to true. That will cause the referenced dll to actually be dumped into the bin on compile. If you then deploy those dlls from the bin, your live site should be able to find them. You might have to go through that a couple of times until you find all of the Windows Identity Foundation dlls you need to get to.
It sounds like WIF has been integrated into the .NET 4.5 framework. It is depreciated and you shouldn't use it unless you are developing with .NET 3.5 or 4. I wouldn't expect you to be having this problem on .NET 4.5. What version of .NET framework are you using?
See What is Windows Identity Foundation for more info on WIF
Was any of that helpful?

How to set up IIS6 to host ASP .NET 4 MVC4 application

I'm having a hard time configuring my server to host MVC4 application. Here's my situation:
I have Windows 2003 server SP2
Until now, all my hosted applications are targeted to .NET Framework 3.5, thus using ASP .NET 2. I use single web site to host web application
Now, I want to host very first application targeted to ASP .NET 4
What I did is:
I've installed .NET Framework 4
I've added new new application pool
I've added new virtual directory to my web site (the same web site that hosts ASP .NET 2 web apps) and converted it to web application. Next, I've selected ASP .NET version 4 on ASP .NET tab
So, I thought that it would be enough. But when I access my application with root url, the first thing I get is 403. I've checked security options and they seem to be all right.
Next, I tried to access one of my controller actions, eg:
http://servername/home/index
and now I get 404 error. Ok, so I've enabled browsing of files and I tried to access web.config, for to check what happens, and I received error:
Could not load file or assembly 'System.Core, Version=2.0.5.0,
Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or
one of its dependencies. The given assembly name or codebase was
invalid. (Exception from HRESULT: 0x80131047)
I've also run regiis command:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis.exe -s W3SVC/2049612577/root/cip-new/
but still in vain. Bottom line, it's something wrong, but I have not idea what is happening.
EDIT 1:
I've made some testing. What I did, is I'd created a basic MVC4 application from Basic template and simply published it to the server. And it worked. However when I published it to the server to the same directory, I got the error:
The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load file or assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047).]
2 things I've had to do in the past to get v4 working on IIS6...
Make sure the site using .Net version 4.x runs in it's own app pool, separate to sites using .Net version 2.x
If you are using Razor I've noticed that IIS6 doesn't immediately know what to do. So you need to configure the Application Extensions Mappings. Add an extension mapping for .cshtml or .vbhtml depending on whether using C# or VB. I think that's why you're getting your 404 errors.
Restart IIS or recycle relevant app pools once above applied if you can to make sure changes are in effect.

ServiceStack FileNotFoundException Deploying on IIS7

I developed a web service using ServiceStack (great framework, btw -- had fun using it) on .Net 3.5. The service runs fine on the dev box under IIS6. But when I try to deploy to a prod server running IIS7, I get the error:
[FileNotFoundException: Could not load file or assembly 'ServiceStack' or one of its dependencies. The system cannot find the file specified.]
I tried deployment via both xcopy (which I thought was sufficient for ServiceStack) and MSDeploy -- same error. The IIS7 virtual directory passes both authentication and authorization tests.
As mentioned, I'm not an IIS or ServiceStack expert. Might this be a registration or GAC issue? Any thoughts would be appreciated.

Resources