WiX Custom Action Project - BadImageFormatException - deployment

I'm developing my first custom action but I can't get the resulting .CA.dll file to load. Heres the process at its simplest, and the result:
I create a custom action project and keep all the defaults. The class looks like this:
using Microsoft.Deployment.WindowsInstaller;
namespace CustomAction
{
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
session.Log("Begin CustomAction1");
return ActionResult.Success;
}
}
}
I then build the assembly (either in debug or release) which creates me a CustomAction.CA.dll file. I then try to run this test:
[TestMethod]
public void LoadAssembly()
{
Assembly.LoadFrom(#"D:\CustomAction\bin\Debug\CustomAction.CA.dll");
}
And get the error:
System.BadImageFormatException: Could not load file or assembly 'file:///D:\CustomAction\bin\Debug\CustomAction.CA.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
Neither can I reference the custom action from my WiX project. Getting really frustrated!
Edit:
Had a look and when I run through VS test manager I'm getting the following in the application event log:
TmiDataManager.TryConvertPropertyValueToDisplayText: Failed to convert property value using the property descriptor's type converter. System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider Provider)
at System.String.System.IConvertible.ToType(Type type, IFormatProvider provider)
at System.ComponentModel.EnumConverter.ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType)
at System.ComponentModel.TypeConverter.ConvertToString(Object value)"
Further edit: I can load the normal CustomAction.dll via Assembly.LoadFrom, so maybe this is a different issue to the BadImageFormat thing? Could there be any reason a blank action with no further dependencies wouldn't load into my WiX project?

CustomAction.CA.dll is a native-code DLL that contains the managed-code assembly and knows how to run as a custom action inside MSI. The managed-code assembly is "CustomAction.dll."

Related

Custom Razor component a NuGet library behaves differently?

I created 3 components which have the exact same implementation with only 1 difference:
The 1st component (MyTest) is implemented in the same project as its parent component
The 2nd one (Component1) is from a different (but same solution)
The 3rd (CSInput) is imported from a NuGet package. Below are the invokation of all 3 in the same parent.
The razor component implementation is as followed:
<input disabled="#Disabled">
#code {
[Parameter]
public bool Disabled { get; set; }
}
The snippet of the parent implementation:
// The Disabled property is coded as boolean
<MyTest Disabled="#DisableMyTest"/>
<RazorClassLibrary1.Component1 Disabled="#DisableMyTest" />
<CSInput Disabled="#DisableMyTest"/>
#code{
private bool DisableMyTest = false;
}
For an unknown reason, the compiler issued a CS1503 (cannot convert from 'bool' to 'string') on the Disabled property from CSInput. Any idea why? Many Thanks!
figured it out. The weird behavior is caused by me not incrementing the version of the nuget. Whenever you install a Nuget, VS keeps a copy of it in the .nuget\packages directory. If you don't clean up that directory, VS will keep use what it has. Now, where can I get wig....

Log aspect in PostSharp 5.0.23 not applied at assembly level

I am following the steps mentioned in http://doc.postsharp.net/add-logging . The Visual studio version is 2017 and PostSharp 5.0.28 extension is installed. When the log aspect for console backend is added to the whole project, the GlobalAspect.cs file is added but the output shows no log trace. But when I apply the [Log] attribute to the method the log trace is seen. Why is the definition in GlobalAspect not applied?
using PostSharp.Patterns.Diagnostics;
namespace ConsoleApp1
{
[Log(AttributeExclude = true)]
public class Program
{
static void Main(string[] args)
{
LoggingServices.DefaultBackend = new PostSharp.Patterns.Diagnostics.Backends.Console.ConsoleLoggingBackend();
}
public static void f()
{
}
}
}
I have the following entry in GlobalAspects.cs file of console and dll. While in dll it works, the console it doesn't.
[assembly: Log(AttributeTargetTypeAttributes=MulticastAttributes.Public‌​, AttributeTargetMemberAttributes=MulticastAttributes.Public)]
Unfortunately, GlobalAspect seems to have no impact on Console application. On a class library, it does work neat.
When you apply the [Log] aspect on the assembly level, it is propagated to the methods in the assembly according to the specified rules.
You can set properties such AttributeTargetTypeAttributes, AttributeTargetMemberAttributes to specify whether you want to target public,private, instance, static methods etc. You can also specify the namespace, type and member names.
The defaults for these properties may not correspond with what you want. You need to make sure that the specified properties match the characteristics of the desired target methods.
[Log(AttributeTargetTypeAttributes = MulticastAttributes.Public, AttributeTargetMemberAttributes = MulticastAttributes.AnyVisibility)]
You can find more details on this documentation page: http://doc.postsharp.net/attribute-multicasting

Can we fetch selenium test result Passed or failed in selenium Ide or selenium RC using API

Actually I am executing my selenium test by reading test case data from excel.I wanted to fetch whether the test result is Passed or failed after execution of my first test case and write it in front of test case then y second test case and write it in front of test case and so on .
Before execution of my test case excelsheet screenshoot
http://i.stack.imgur.com/L2LNz.png
after execution of my test cases excelsheet screenshoot
http://i.stack.imgur.com/mMivW.png
You can fetch the results using TestNG. TestNG contains default listeners which reads if your test passed/failed/was skipped.
To set this data in excelsheet you need to create a class that implements from ITestListener
public class ExcelListener implements ITestListener
If you use any IDE, you should see a warning about need of creating unimplemented methods. Allow system to create them and you should see methods like
#Override
public void onTestSuccess(ITestResult result) {
// TODO Auto-generated method stub
}
Then all you have to code is
1. Open excel file
2. Find the right column
3. Insert status
To do that I recommend using Java Excel API.
To read existing excelsheet you need to provide absolute path, workbook name and a sheetname. Here's my code for method getExcel
public void getExcel(String filePath, String sheetName, String fileName) throws BiffException, IOException {
String absolutePath = filePath.concat("/").concat(fileName);
file = new FileInputStream(new File(absolutePath));
workbook = Workbook.getWorkbook(file);
worksheet = workbook.getSheet(sheetName);
}
After getting an excel file, you need to iterate through data.
You can provide exact column and row.
Hope it helps!
EDIT:
Place a listener like this
#Listeners(MyExcelListener.class)
public class MyTestClass {
}

How do I create a custom content type as part of an Orchard module?

I would like to create a custom Package content type in Orchard 1.6. I already have a content part that represents the whole db record and UI for a Package, but now I'm wondering if I am going about this correctly.
It seems to me the next step is to use Orchard dashboard to create a new content type, and add my custom content part to the type. But, then the content type is internal to Orchard, with a dependency on my 'external' module that hosts the content part. How can I make it so that my content type is only available when my module is enabled?
For convenience, you could create the content type as part of one of the migrations in your module. This would only run when enabled. It would look something like this...
//Inside of your migration file...
public int UpdateFrom1(){
ContentDefinitionManager.AlterTypeDefinition("Package", cfg=> cfg
.Creatable()
.WithPart("YourCustomPart")
.WithPart("CommonPart")
.WithPart("Whatever other parts you want..."));
return 2;
}
Removing this content type when you disable your module would be the tricky part because it might be kind of unexpected by the user. Maybe "Package" is a type they still want to use with different parts attached. Also, if they manually delete your module without disabling, you can't really write code to respond to that event. The only reliable thing I know of is the IFeatureEventHandler. This would allow you to remove your content type if they disable the module in the admin...
public PackageRemover : IFeatureEventHandler {
private readonly IContentDefinitionManager _contentDefinitionManager;
public PackageRemover(IContentDefinitionManager contentDefinitionManager){
_contentDefinitionManager = contentDefinitionManager;
}
public void Installed(Feature feature){}
public void Enabling(Feature feature){}
public void Enabled(Feature feature){}
public void Disabling(Feature feature){
_contentDefinitionManager.DeleteTypeDefinition("Package");
}
public void Disabled(Feature feature){}
public void Uninstalling(Feature feature){}
public void Uninstalled(Feature feature){}
}

Injecting HttpContext.Current.Session in legacy code using Castle Windsor

tl;dr:
In a legacy app, culture info is stored in HttpContext.Current.Session["culture"]. How do I introduce DI with Windsor here, so that when running the application still gets and sets culture info there, but I can mock it in my tests?
Full background:
I have some legacy code for localization, that I wish to refactor to enable mocking and testing. Currently, a custom class Lang fetches localized strings based on a provided string key and on HttpContext.Current.Session["culture"] as CultureInfo.
My initial idea was to simply inject a CultureInfo instance using Windsor, and install it to get it from the same place as before when running the entire web application, but when testing I'd simply register a new CultureInfo("en-GB") instead. This is what I came up with for the installers:
public class CultureInfoFromSessionInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register( // exception here (see comments below)
Component.For<CultureInfo>()
.Instance(HttpContext.Current.Session["culture"] as CultureInfo)
.LifeStyle.PerWebSession());
}
}
class EnglishCultureInfoInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For<CultureInfo>()
.Instance(new CultureInfo("en-GB")));
}
}
But now when running the application I get a null reference exception on the indicated line. I suspect this is because I'm trying to hook this up too early - the container is initialized and the installer registered under Application_Start in Global.asax.cs, and I'm not sure HttpContext.Current.Session (or even HttpContext.Current) is set by then.
Is there a nice way to obtain what I'm trying to do here?
Delay the instantiation of the component:
container.Register(
Component.For<CultureInfo>()
.UsingFactoryMethod(() => HttpContext.Current.Session["culture"] as CultureInfo)
.LifeStyle.PerWebSession());