extent reports not generating reports - c#

I am using extentent reports to generate report but the test excution fails on extent.flush() method. I am using
extentreports 3.1.3
Specflow.xunit 2.2.1
This code use to work previously but not working anymore. Error returned :
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Source=RazorEngine
StackTrace:
at RazorEngine.Compilation.CSharp.CSharpDirectCompilerService..ctor(Boolean strictMode, Func1 markupParserFactory)
at RazorEngine.Compilation.DefaultCompilerServiceFactory.CreateCompilerService(Language language)
at RazorEngine.Templating.RazorEngineCore.CreateTemplateType(ITemplateSource razorTemplate, Type modelType)
at RazorEngine.Templating.RazorEngineCore.Compile(ITemplateKey key, Type modelType)
at RazorEngine.Templating.RazorEngineService.CompileAndCacheInternal(ITemplateKey key, Type modelType)
at RazorEngine.Templating.RazorEngineService.GetCompiledTemplate(ITemplateKey key, Type modelType, Boolean compileOnCacheMiss)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action1 withWriter)
at AventStack.ExtentReports.Reporter.ExtentHtmlReporter.Flush()
at AventStack.ExtentReports.Model.Report.<>c.b__29_1(IExtentReporter x)
at System.Collections.Generic.List1.ForEach(Action1 action)
at AventStack.ExtentReports.Model.Report.NotifyReporters()
at AventStack.ExtentReports.Model.Report.Flush()
at AventStack.ExtentReports.ExtentReports.Flush()
at XUnitTestProject5.UnitTest1.Test1() in C:\Users\kotar\source\repos\XUnitTestProject5\XUnitTestProject5\UnitTest1.cs:line 25
var HTMLReporter = new ExtentHtmlReporter(#"C:\test\TestReport.html");
HTMLReporter.Configuration().Theme = AventStack.ExtentReports.Reporter.Configuration.Theme.Dark;
var extent = new ExtentReports();
extent.AttachReporter(HTMLReporter);
var featurename = extent.CreateTest<Feature>("login feature");
var scenario= featurename.CreateNode<Scenario>("Login as a user ");
scenario.CreateNode<Given>("user has access to the methos ");
extent.Flush();

If you are using .net core, you have to use "ExtentReports.Core" NuGet package instead of "ExtentReports" and initialize your extent object like this :
public AventStack.ExtentReports.ExtentReports _extent = new
AventStack.ExtentReports.ExtentReports();

Related

C# Unable to load types from dll at runtime

I need to get types of older dlls of my application.
I copied them to a local folder.
By running following code I always get a System.TypeLoadException
var dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
var subDir = Path.Combine(dir.FullName, "LegacyDlls");
var aggregateRootDlls = Directory.GetFiles(subDir, "*.dll", SearchOption.AllDirectories);
var types= aggregateRootDlls.SelectMany(x => Assembly.LoadFile(x).GetTypes());
return types.Where(t => t.BaseType?.Name == "AggregateRoot");
The type that cannot be loaded is declared in one of these dlls, though. I don't understand the error message.
Note that some of the loaded dlls still exist in my application with a newer version!
Is this causing the trouble? How do I workaround this?
UPDATE:
loading into another AppDomain did not help:
var tempDomain = AppDomain.CreateDomain("temp");
var types = rootDlls.SelectMany(x =>
{
var assemblyName = AssemblyName.GetAssemblyName(x);
return tempDomain.Load(assemblyName).GetTypes();
});
return types.Where(t => t.BaseType?.Name == "AggregateRoot");
Errormessage says
System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
----> System.TypeLoadException : Could not load type 'Domain.SharedKernel.EventStreamer' from assembly 'Domain.SharedKernel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
----> System.TypeLoadException : Could not load type 'Domain.SharedKernel.EventStreamer' from assembly 'Domain.SharedKernel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()

Using Fonet to Convert XSL-FO to PDF Getting System Exception: Unknown enumerated value for property 'text-decoration': no-underline

I'm using Fonet to convert XSL-FO to Pdf. Below is the code I'm using C# on Visual Studio
FonetDriver driver = FonetDriver.Make();
driver.Render("C:\\XSLT\\Input\\input.fo", "C:\\XSLT\\Output\\result.pdf");
Getting Exception:
System.SystemException: **'System.SystemException: Unknown enumerated value for property 'text-decoration': no-underline**
at Fonet.FonetDriver.FireFonetError(String message)
at Fonet.Fo.EnumProperty.Maker.CheckEnumValues(String value)
at Fonet.Fo.Properties.TextDecorationMaker.CheckEnumValues(String value)
at Fonet.Fo.PropertyMaker.Make(PropertyList propertyList, String value, FObj fo)
at Fonet.Fo.PropertyListBuilder.MakeList(String ns, String elementName, Attributes attributes, FObj parentFO)
at Fonet.Fo.FOTreeBuilder.StartElement(String uri, String localName, Attributes attlist)
at Fonet.Fo.FOTreeBuilder.Parse(XmlReader reader)'
Example <fo:block> in my input.fo
Help!

I got a runtime error in PodioApi C# System.IO.FileNotFoundException

Code
using System;
using PodioAPI;
namespace TestPodio
{
class Program
{
static void Main(string[] args)
{
string clientId = clientIdValue;
string clientSecret = clientSecretValue;
int appId = appIdValue;
string appSecret = appSecretValue;
var podio = new Podio(clientId, clientSecret);
podio.AuthenticateWithApp(appId, appSecret);
var items = podio.ItemService.FilterItems(appId);
Console.WriteLine("My app has " + items.Total + " items");
//Console.WriteLine("Hello World!");
}
}
}
clientIdValue and clientSecretValue are the client id and client secret i'm using
appIdValue and appSecretValueare the respective app id and its secret
Runtime error:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'System.Security.Permissions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Den angivne fil blev ikke fundet.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.Serialization.JsonTypeReflector.get_DynamicCodeGeneration()
at Newtonsoft.Json.Serialization.JsonTypeReflector.get_ReflectionDelegateFactory()
at Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator(Type createdType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonConverter[] converters)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at PodioAPI.Podio.Request[T](RequestMethod requestMethod, String url, Object requestData, Object options)
at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
at PodioAPI.Podio.Post[T](String url, Object requestData, Object options)
at PodioAPI.Podio.Authenticate(String grantType, Dictionary`2 attributes)
at PodioAPI.Podio.AuthenticateWithApp(Int32 appId, String appToken)
at TestPodio.Program.Main(String[] args) in C:\Users\HHM\Documents\Visual Studio 2017\Projects\TestPodio\TestPodio\Program.cs:line 16
Error list:
Severity Code Description Project File Line Suppression State
Warning NU1701 Package 'Newtonsoft.Json 5.0.8' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project. TestPodio C:\Users\HHM\Documents\Visual Studio 2017\Projects\TestPodio\TestPodio\TestPodio.csproj 1
Warning NU1701 Package 'Podio 1.5.9' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project. TestPodio C:\Users\HHM\Documents\Visual Studio 2017\Projects\TestPodio\TestPodio\TestPodio.csproj 1
How do I solve these errors?
The problem is you've created a dotnet core project, but podio is a dotnet framework project. Try recreating your project as a dotnet framework project instead. Instead of Console App (.NET Core) choose Console App (.NET Framework) when you create new project.

Unable to find assembly with BinaryFormatter.Deserialize

i hope you can help me.
i'm de-serializing a custom object and i'm getting this error.
the type is in a dll which is loaded using a windows hook - thus, running under explorer.exe
i understand why this error occurs, this because the DLL doesnt reside "explorer.exe" process.
there are 2 solutions for this:
1. install the assembly in GAC
2. use the "Binder" of the binary formatter.
i don't want to use any of those, as the DLL is actually loaded in explorer.exe (when i'm attaching, i see that the DLL is indeed loaded).
i'm serializing a custom object - created in the same DLL that does the de-serializing
this is my code:
BinaryFormatter binaryFormatter = new BinaryFormatter();
byte[] serializedObject;
using (MemoryStream memoryStream = new MemoryStream())
{
binaryFormatter.Serialize(memoryStream, new MyCustomObject());
serializedObject = memoryStream.ToArray();
}
BinaryFormatter binaryFormatter2 = new BinaryFormatter();
object deserializedObject;
using (MemoryStream memoryStream2 = new MemoryStream(serializedObject))
{
deserializedObject = binaryFormatte2r.Deserialize(memoryStream2); // Unable to find this assembly
}
by the way. i've looked a bit in the binary formatter code, somehow it does tries to load the DLL.. but it's already loaded to the process..
error:
Unable to find assembly 'AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=Key'.
stack trace:
at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
at System.Runtime.Serialization.Formatters.Binary.BinaryConverter.TypeFromInfo(BinaryTypeEnum binaryTypeEnum, Object typeInformation, ObjectReader objectReader, BinaryAssemblyInfo assemblyInfo, InternalPrimitiveTypeE& primitiveTypeEnum, String& typeString, Type& type, Boolean& isVariant)
at
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadArray(BinaryHeaderEnum binaryHeaderEnum)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
-- edit--
i'm using namespace extensions (so the OS hooks to my dlls)
It's too late, but my solution is shown below. The implementation of BindToType is overridden to solve your issue.
[Serializable]
public class YourClass : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
Type tyType = null;
string sShortAssemblyName = assemblyName.Split(',')[0];
Assembly[] ayAssemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly ayAssembly in ayAssemblies)
{
if (sShortAssemblyName == ayAssembly.FullName.Split(',')[0])
{
tyType = ayAssembly.GetType(typeName);
break;
}
}
return tyType;
}
...
This link helped me

IronPython Sandboxing with CAS

I am trying to integrate IronPython into a C# application for scripting purposes. I would also like the scripts to run under a set of security policies that restrict their access to the file system/network/sensitive system resources.
Research indicates that the most popular approach is to use CAS. This works very well and it does not allow the user to use sockets, access the file system, etc. However, when I try to inject variables for the scrip to interact with, I get a security exception every time I access certain parameters. This only happens with variables I define in my assembly. If I use a standard .NET type (like Dictionary) it works just fine.
My Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Security.Policy;
using System.Security.Permissions;
using System.Security;
using System.IO;
using Microsoft.Scripting.Hosting;
using IronPython.Hosting;
using System.Runtime.Remoting;
using System.Net;
namespace python_in_appdomain
{
[Serializable]
public class Whatever
{
public int i;
public Whatever(int i)
{
this.i = i;
}
}
class Program
{
static void Main(string[] args)
{
Remoting();
}
public static void Remoting()
{
AppDomainSetup setup = new AppDomainSetup();
Assembly thisAssembly = Assembly.GetExecutingAssembly();
setup.ApplicationBase = Path.GetDirectoryName(thisAssembly.Location);
AssemblyName name = typeof(Program).Assembly.GetName();
StrongName sn = new StrongName(
new StrongNamePublicKeyBlob(name.GetPublicKey()),
name.Name,
name.Version
);
PermissionSet pset = new PermissionSet(PermissionState.None);
pset.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
pset.AddPermission(new ReflectionPermission(PermissionState.Unrestricted));
setup.PartialTrustVisibleAssemblies = new[] { sn.Name + ", PublicKey=" + sn.PublicKey.ToString() };
AppDomain domain = AppDomain.CreateDomain("Sandbox", AppDomain.CurrentDomain.Evidence, setup, pset, sn);
String script = #"
d.Add('hello', 1)
w.i = 5
";
Whatever w = new Whatever(4);
Dictionary<string, int> d = new Dictionary<string,int>();
ScriptRuntime py = Python.CreateRuntime(domain);
ScriptEngine engine = py.GetEngine("py");
ScriptScope scope = engine.CreateScope();
scope.SetVariable("w", w);
scope.SetVariable("d", d);
int result;
Console.WriteLine(w.i);
d.TryGetValue("hello", out result);
Console.WriteLine(result);
Console.WriteLine("-----");
try
{
engine.Execute(script, scope);
}
catch (Exception exc)
{
Console.WriteLine(exc.ToString());
}
w = scope.GetVariable<Whatever>("w");
d = scope.GetVariable<Dictionary<string,int>>("d");
Console.WriteLine("-----");
Console.WriteLine(w.i);
d.TryGetValue("hello", out result);
Console.WriteLine(result);
}
}
}
Commenting out the "w.i=5" on line 55 causes the program to execute normally under restricted security settings. Setting the PermissionState to Unrestricted on line 47 allows both lines of the script to execute normally. The following is the error message I receive:
System.Security.SecurityException: Request failed.
at System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(IRuntimeMethodInfo method)
at System.Reflection.Emit.DynamicMethod.CreateDelegate(Type delegateType, Object target)
at System.Dynamic.Utils.TypeExtensions.CreateDelegate(MethodInfo methodInfo, Type delegateType, Object target)
at System.Linq.Expressions.Compiler.LambdaCompiler.CreateDelegate()
at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda, DebugInfoGenerator debugInfoGenerator)
at System.Linq.Expressions.Expression`1.Compile()
at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at Microsoft.Scripting.Hosting.ScriptEngine.Execute(String expression, ScriptScope scope)
at Microsoft.Scripting.Hosting.ScriptEngine.Execute(String expression, ScriptScope scope)
at python_in_appdomain.Program.Remoting() in C:\Users\dave\Documents\Visual Studio 2010\Projects\IronPythonTest\IronPythonTest\Program.cs:line 7
6
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.PermissionSet
The demand was for:
<PermissionSet class="System.Security.PermissionSet"
version="1"
Unrestricted="true"/>
The granted set of the failing assembly was:
<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Unrestricted="true"/>
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="Execution"/>
</PermissionSet>
The assembly or AppDomain that failed was:
Microsoft.Dynamic, Version=1.1.0.20, Culture=neutral, PublicKeyToken=7f709c5b713576e1
The method that caused the failure was:
Int32 Run(Microsoft.Scripting.Interpreter.InterpretedFrame)
The Zone of the assembly that failed was:
Internet
The Url of the assembly that failed was:
file:///C:/Users/dave/Documents/Visual Studio 2010/Projects/IronPythonTest/IronPythonTest/bin/Debug/Microsoft.Dynamic.DLL
Unhandled Exception: System.Security.SecurityException: Request failed.
at System.Delegate.BindToMethodInfo(Object target, IRuntimeMethodInfo method, RuntimeType methodType, DelegateBindingFlags flags)
at System.Delegate.CreateDelegate(Type type, MethodInfo method, Boolean throwOnBindFailure)
at System.Dynamic.Utils.TypeExtensions.CreateDelegate(MethodInfo methodInfo, Type delegateType)
at System.Runtime.CompilerServices.CallSite`1.MakeUpdateDelegate()
at System.Runtime.CompilerServices.CallSite`1.GetUpdateDelegate(T& addr)
at System.Runtime.CompilerServices.CallSite`1.GetUpdateDelegate()
at System.Runtime.CompilerServices.CallSite`1.Create(CallSiteBinder binder)
at System.Func`2.Invoke(T arg)
at Microsoft.Scripting.Runtime.DynamicOperations.GetOrCreateSite[T](CallSiteBinder siteBinder, Func`2 factory)
at Microsoft.Scripting.Runtime.DynamicOperations.GetOrCreateSite[T1,TResult](CallSiteBinder siteBinder)
at Microsoft.Scripting.Runtime.DynamicOperations.ConvertTo[T](Object obj)
at IronPython.Runtime.PythonContext.ScopeGetVariable[T](Scope scope, String name)
at Microsoft.Scripting.Hosting.ScriptScope.GetVariable[T](String name)
at Microsoft.Scripting.Hosting.ScriptScope.GetVariable[T](String name)
at python_in_appdomain.Program.Remoting() in C:\Users\dave\Documents\Visual Studio 2010\Projects\IronPythonTest\IronPythonTest\Program.cs:line 8
3
at python_in_appdomain.Program.Main(String[] args) in C:\Users\dave\Documents\Visual Studio 2010\Projects\IronPythonTest\IronPythonTest\Program.
cs:line 31
The error is shockingly straight forward. It says that it is expecting to have totally unrestricted access for this kind of action. Is there any way around this? Why does the dictionary work but my variable does not? Is there a way for me to make IronPython treat my variable like the Dictionary? Am I missing something very obvious?
Thank you very much for you help.
Update 12/21/2012
I kept messing around and came up with a solution that worked. Creating the AppDomain like this (with the same permission object) allows everything to work.
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = System.Environment.CurrentDirectory;
AppDomain domain = AppDomain.CreateDomain("IPyEngine", new Evidence(), setup, pset);
I can't say I totally understand why, though I can see that I'm not providing my assembly's Evidence nor am I adding any Assemblies to the trust list. I don't want to mark this as the answer until I know for certain I'm not doing anything monumentally stupid.
This is suspicious:
The Zone of the assembly that failed was:
Internet
The Url of the assembly that failed was:
file:///C:/Users/dave/Documents/Visual Studio 2010/Projects/IronPythonTest/IronPythonTest/bin/Debug/Microsoft.Dynamic.DLL
I wonder if the file has a zone identifier. Can you check the file properties, and Unblock it if necessary?

Categories

Resources