Open smhmhmd opened 3 months ago
.NET Framework reference assemblies probably need to be added. If VSharp can have a command-line parameter to point to reference assemblies, that may help.
Getting method body does work with Mono.Cecil.
using System.Collections.Immutable;
using System.IO;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.CompilerServices;
using Microsoft.Win32.SafeHandles;
using System.Reflection.PortableExecutable;
using System.Xml;
using System.Diagnostics;
using System.Xml.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
class Program
{
static void Main(string[] args)
{
var inputAssembly =
@"D:\Users\samiull\Documents\2024\nopCommerce-release-3.80\src\Libraries\Nop.Core\bin\Debug\Nop.Core.dll";
var path = Path.GetDirectoryName(inputAssembly);
var assemblyResolver = new DefaultAssemblyResolver();
var assemblyLocation = Path.GetDirectoryName(inputAssembly);
assemblyResolver.AddSearchDirectory(assemblyLocation);
var readerParameters = new ReaderParameters { AssemblyResolver = assemblyResolver };
var assemblyDefinition = Mono.Cecil.AssemblyDefinition.ReadAssembly(
@"D:\Users\samiull\Documents\2024\nopCommerce-release-3.80\src\Libraries\Nop.Core\bin\Debug\Nop.Core.dll",
readerParameters);
var module = assemblyDefinition.MainModule;
foreach (var typeDefinition in module.Types)
{
Console.WriteLine("Type = " + typeDefinition.ToString());
}
var methods = assemblyDefinition.MainModule
.GetTypes()
.SelectMany(t => t.Methods
.Where(m => m.HasBody)
.Select(m => m ));
foreach (var m in methods)
{
var count = m.Body.Instructions.Count;
Console.WriteLine("Method " + m.Name + " has " + count + " instructions");
}
}
}
Hi @smhmhmd
Before running V#, you should do dotnet publish --self-contained -r (RID) -c Release
. You can find your RID in this paper https://learn.microsoft.com/ru-ru/dotnet/core/rid-catalog.
This command will create folder 'publish', in which all dependency assemblies will be.
Example of needed folder path: /Users/michael/Documents/Work/VSharp/VSharp.TestGenerator/bin/Release/net7.0/osx-arm64/publish/
.
After that you need to use that path inside V# running command.
Example: --all-public-methods /Users/michael/Documents/Work/VSharp/VSharp.TestGenerator/bin/Release/net7.0/osx-arm64/publish/VSharp.TestGenerator.dll ...
.
This will help V# to find dependencies.
Hi @MchKosticyn
I published VSharp to a folder using Visual Studio and also published NopCommerce-3.80 to a folder. The error is still there, will using Mono.Cecil instead of System.Reflection work better ?
samiull@DESKTOP-OS5I16B MINGW64 /d/Users/samiull/Documents/2024/vsharp-publish
$ dotnet VSharp.Runner.dll --all-public-methods /d/Users/samiull/Documents/2024/nopcommerce-publish/bin/Nop.Web.dll -o ../out/ -t 30
Unhandled exception: System.TypeLoadException: Could not load type 'System.Web.HttpContextBase' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
at System.RuntimeMethodHandle.GetMethodBody(IRuntimeMethodInfo method, RuntimeType declaringType)
at System.Reflection.RuntimeMeth
Hi @MchKosticyn
Nopcommerce-release-3.80 uses the older Windows-based .NET Framework (VS upgrades to .NET Framework 4.8), can VSharp generate tests for such code, I got this error while running VSharp from Visual Studio on Windows-10:
Command in Visual Studio is
--all-public-methods D:\Users\samiull\Documents\2024\nopCommerce-release-3.80\src\Presentation\Nop.Web\bin\Nop.Core.dll -t 30 -o ..\out -v Trace