SpecsFor.Mvc Build failed - msbuild

Attempting to test out SpecsFor.Mvc, unforunitly I'm getting this strange build error when I try to run a test.
Running in both my own project and the SpecsFor latest source I get a "Build failed." ApplicationException from the IISTestRunnerAction class. The following is from the log file but its beyond my understanding.
Using visual studio 2012 pro and IIS Express 8.0
The following is from the log file:
Using "VSMSDeploy" task from assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.Tasks.dll".
Task "VSMSDeploy"
Package/Publish task Microsoft.Web.Publishing.Tasks.VSMSDeploy load assembly Microsoft.Web.Deployment, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Package/Publish task Microsoft.Web.Publishing.Tasks.VSMSDeploy load assembly Microsoft.Web.Delegation, Version=7.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Starting Web deployment task from source: manifest(C:\Users\Chris\Desktop\SpecsFor-master\SpecsFor.Mvc.Demo\obj\Test\Package\SpecsFor.Mvc.Demo.SourceManifest.xml) to Destination: package(C:\Users\Chris\Desktop\SpecsFor-master\SpecsFor.Mvc.Demo\obj\Test\Package\SpecsFor.Mvc.Demo.zip).
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(4007,5): error : Web deployment task failed. (The type initializer for 'Microsoft.Web.Deployment.DeploymentManager' threw an exception.)
Package failed.
Done executing task "VSMSDeploy" -- FAILED.
UPDATE
Here is the AssemblyStartup
[SetUpFixture]
public class AssemblyStartup
{
private SpecsForIntegrationHost _host;
[SetUp]
public void SetupTestRun()
{
var config = new SpecsForMvcConfig();
//SpecsFor.Mvc can spin up an instance of IIS Express to host your app
//while the specs are executing.
config.UseIISExpress()
//To do that, it needs to know the name of the project to test...
.With(Project.Named("SpecsForTesting"))
//And optionally, it can apply Web.config transformations if you want
//it to.
.ApplyWebConfigTransformForConfig("Debug");
//In order to leverage the strongly-typed helpers in SpecsFor.Mvc,
//you need to tell it about your routes. Here we are just calling
//the infrastructure class from our MVC app that builds the RouteTable.
config.BuildRoutesUsing(r => SpecsForTesting.RouteConfig.RegisterRoutes(r));
//SpecsFor.Mvc can use either Internet Explorer or Firefox. Support
//for Chrome is planned for a future release.
config.UseBrowser(BrowserDriver.Chrome);
//Does your application send E-mails? Well, SpecsFor.Mvc can intercept
//those while your specifications are executing, enabling you to write
//tests against the contents of sent messages.
config.InterceptEmailMessagesOnPort(13565);
//The host takes our configuration and performs all the magic. We
//need to keep a reference to it so we can shut it down after all
//the specifications have executed.
_host = new SpecsForIntegrationHost(config);
_host.Start();
}
//The TearDown method will be called once all the specs have executed.
//All we need to do is stop the integration host, and it will take
//care of shutting down the browser, IIS Express, etc.
[TearDown]
public void TearDownTestRun()
{
_host.Shutdown();
}
}

I had this error come up, and it turned out that I had added a new project to my solution. The new project did not include the same configurations i.e. the solution was running of "Test" but my new project only had the default ones of debug and release.
Go into the Configuration Manager and check that all the projects in your solution have the same configurations in place.

If you are looking for the build log, it is outputted to Console by default. Here is how to capture Console output:
var stringWriter = new StringWriter();
try
{
// Build log is sent to console, redirect output to StringWriter
Console.SetOut(stringWriter);
_host.Start();
}
catch (ApplicationException ex)
{
throw new Exception("Build failed. Output: " + stringWriter, ex);
}

It looks like the error is actually from MSDeploy, which SpecsFor.Mvc uses internally through MSBuild to publish your site for testing. Here's the same error directly from MSDeploy: Web deployment task failed. (The type initializer for 'Microsoft.Web.Deployment.DeploymentManager' threw an exception.). Unfortunately there doesn't seem to be a resolution.
Can you try deploying your site manually? This command line should do the trick:
msbuild /p:DeployOnBuild=true;DeployTarget=Package;_PackageTempDir=;AutoParameterizationWebConfigConnectionStrings=false;Platform=AnyCPU
Let me know if that works or if it blows up with a similar error.

I had exactly the same issue trying to get SpecsForMvc working on a Bamboo remote build agent. Matt Honeycutt's answer pointed me in the right direction. I just had to install MS Web Deploy 3.5 on the VM running the agent to fix this error.
I also needed to install IIS Express 8 on the same VM to allow the SpecsForIntegrationHost to spin up a site in.
arni's answer helped me better diagnose the problem, but also caused me some issues later down the line, when I was having trouble with permissions trying to connect to a remote SQL Server from the tested app. These exceptions were not caught by the ApplicationException catch block as they were of class SystemException. They got handled by the global exception handler, bypassing the end of test cleanup which was supposed to shut down the integration host. This left the IIS Express instance for each test running in the background. (As I can't comment on arni's answer, I've added my amended code here)
var stringWriter = new StringWriter();
try
{
// Build log is sent to console, redirect output to StringWriter
Console.SetOut(stringWriter);
_host.Start();
}
catch (Exception ex)
{
_integrationHost.Shutdown();
throw new Exception("Build failed. Output: " + stringWriter, ex);
}

Related

Can't start ASP.NET Core 6 app running as Windows Service

I have created a simple, stripped down project to try to get this to work: ASP.NET Core 6 WebAPI project, hosted as a Windows Service, just trying to get it up and running with the sample WeatherForecast controller. I have added NuGet package for Microsoft.Extensions.Hosting (6.0.1) and Microsoft.Extensions.Hosting.WindowsServices (6.0.0). My program.cs looks like:
using IRDSPrototype.Configuration;
using IRDSPrototype.Services;
using Microsoft.Extensions.Hosting.WindowsServices;
var webApplicationOptions = new WebApplicationOptions
{
Args = args,
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
};
var builder = WebApplication.CreateBuilder(webApplicationOptions);
builder.Services.AddHostedService<IRDSHostingService>();
builder.Host.UseWindowsService();
builder.WebHost.UseUrls(UriServices.GetBaseUri().AbsoluteUri);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
await app.RunAsync();
I created a background service as well:
public class IRDSHostingService : BackgroundService
{
public ILogger Logger { get; }
public IRDSHostingService(ILoggerFactory loggerFactory)
{
Logger = loggerFactory.CreateLogger<IRDSHostingService>();
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
Logger.LogInformation("IRDS Hosting Service is starting.");
stoppingToken.Register(() => Logger.LogInformation("IRDS Hosting Service is stopping."));
while (!stoppingToken.IsCancellationRequested)
{
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
}
Logger.LogInformation("IRDS Hosting Service has stopped.");
}
}
I also created a service installer via Wix. When I run the installer it gets to the point of "Starting services" and fails with a message 'Verify that you have sufficient privileges to start system services'. When I check Windows Application Log, I see that error and a also see an error for:
Application: IRDSPrototype.exe
CoreCLR Version: 6.0.822.36306
.NET Version: 6.0.8
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException: Could not load file or assembly 'System.ServiceProcess.ServiceController, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.ServiceProcess.ServiceController, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
My publish directory and Wix manifest do include the System.ServiceProcess.ServiceController.dll.
I installed the service via sc.exe and the install succeeded, but starting the service gives an Error 5: Access Denied message. Unlike with the installer, though, this didn't generate any messages in the Windows log. I checked permissions on the folder containing the executable, giving full permissions to NETWORK SERVICE and LOCAL SERVICE. That didn't help. So I'm kind of stuck on what to do now. All my internet searches basically guided me to the setup I have now and it still doesn't work. So I'm at a loss. Anyone have any suggestions of what I'm missing here?
Thanks,
Dennis
Edit: So I'm whittling down the problem. It turns out I needed the version of System.ServiceProcess.ServiceController.dll that was published to my 'runtimes' folder under the .Net 6.0.0 runtime. So that error no longer shows up in the Event Viewer. The only erro that shows in the Event Viewer now is:
Error 1920. Service 'IRDS Prototype' (IRDSPrototype) failed to start. Verify that you have sufficient privileges to start system services
I have it installing as a Local Service and I believe I've given Local Service full permissions on the proper folders but I will check that. Still looking for suggestions though.
Edit #2: Getting closer. The problem I had when installing through sc.exe was that my binPath was wrong. I wasn't including the exe file in the binPath. Now I can install my service through sc.exe and it starts and works properly. The service still won't start when installed via my Wix installer though. So now I'm down to a Wix issue. Anyone with experience installing Windows services via Wix?
OK, it turns out what I needed to do was publish as a single executable:
Notice the "Deployment Mode: Self-contained" choice and "Produce single file" checked. After publishing that way, I only had to add the executable (no other files) to my Wix manifest and the generated installer worked fine. I'm guessing I was missing a dependency somewhere that I didn't know about. But it's weird that I was able to install and start the service from the same publish directory as I was trying previously with Wix via sc.exe. Anyway, it works now. Thanks to Md Farid Uddin Kiron for redirecting me back to the official page, which I read a little more carefully this time and found the little blurb about this being recommended.

Network calls not working in EXE distribution build of Compose for Desktop Application

I have used Ktor JVM Client for doing network calls in Compose for Desktop Application.
Network calls are working fine in Debug build means when I am just running the application it's working fine.
But when I create the EXE distribution file, by executing the packageExe task in Gradle, it's creating an EXE file. I have installed it on my machine. Then I am running the application and I am seeing that network calls are not working. I have checked internet is working properly.
Please provide a solution to fix this issue. Thanks in advance.
Your question doesn't leave any details about the failure type (compile error? runtime exception? Empty data? etc.).
But if I had to speculate based on such limited information, I'd guess it's probably this: https://github.com/JetBrains/compose-jb/issues/429
Specifically, when packaging, you need to specify which JVM modules you want to be packed into your distributable app, and likely you are missing your crypto module. Try something like this:
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
modules("jdk.crypto.ec")
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "untitled"
}
}
}

ClassNotFoundException on weblogic cluster node

We have a web application(.war) deployed on a weblogic 10.3.4 cluster in 'staging' mode.
So,the .war is copied over to the staging directory of the nodes;and the application is responding to user requests fine.
However,we get a ClassNotFoundException when a processor class tries to invoke an action class dynamically.
(Note: Processor and action have nothing to do with any of the frameworks.It is just a nomenclature.)
protected Action getAction(String sActionName) throws ActionException {
Action action = null;
Object o = null;
try {
String sClassName = getActionClassName(sActionName);
Class actionClass = Class.forName(sClassName);
o = actionClass.newInstance();
} catch(Exception e) {
}
return action;
}
We have verified that the class exists within the war and can be instantiated just fine through an independent application.
Why cant the node not find it then?
Do we need to point the application .war from the staging directory to weblogic classpath explicitly?
That would be quite odd.
You can try to check if your Classpath is correct using Weblogic CAT tool.
https://docs.oracle.com/cd/E24329_01/web.1211/e24368/classloading.htm#WLPRG495
CAT is a Web-based class analysis tool which simplifies filtering classloader configuration and aids you in analyzing classloading issues, such as detecting conflicts, debugging application classpaths and class conflicts, and proposes solutions to help you resolve them

Hot re-deployment of a RESTlet

I'm interested in setting up a super lightweight web server with Restlet mostly for proofs-of-concept and low impedance collaboration with other developers. A full servlet container feels too heavy. Literally, I'm starting with something pulled directly from the "Getting Started" guide.
public class Dummy extends ServerResource {
public static void main(String[] args) throws Exception {
new Server(Protocol.HTTP, 8182, Dummy.class).start();
}
#Get("json")
public String hello() {
ST hello = new ST();
hello.add("name", "World");
return "{ \"hello\": \"World\"}";
}
}
However, I'd like to be able to watch for changes and redeploy automatically as I change code. I know Jetty can do this with some config. Has anyone done this without setting up a full servlet container? Is there something simpler?
I use Eclipse as my IDE to edit the code and launch the app, but the ideal solution wouldn't rely on that.
This what I call Continuous Delivery.
In a nutshell:
I usually use
SVN or Git to store and version source code
Jenkins to schedule the build and deployment
Gradle or Maven to build and test
The SCM plugin is able to poll the repository and invoke the process only if there is changes, or you can trigger the build with a hook.
There are plugins to copy your artifact to the target server and restart the application.

WCF service not working after program update

I have recently added a WCF service reference to my program. When I perform a clean install of this program, everything seems to work as expected. But, when I install the program on a client which already has a previous version (without the new service reference) installed, I get a exception telling me the default endpoint for this particular service could not be found.
It seems that the appname.exe.config is not being updated with the new endpoint settings. Is there any reason for this and how can I force the installer to overwrite the config file? I'm using the default Visual Studio 2008 installer project with RemovePreviousVersions set to True.
Update:
My program encrypts the settings section after the first run with the following code
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSection section = config.GetSection(sectionKey);
if (section != null)
{
if (!section.SectionInformation.IsProtected)
{
if (!section.ElementInformation.IsLocked)
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
section.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
}
}
When I do not run the program before installing the new version the app.config gets updated.
You are right that it is the config file that is not updated.
There are several possibilities:
The installer has the old version of the config file
The installer does not have a config file and the program is using the old one on the machine
Try uninstalling the project first, then install and check that the config file has been copied in.