Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: Method not found: 'Void System.AppDomainSetup.set_ApplicationBase(System.String)' #44

Open
PHuhn opened this issue Feb 20, 2022 · 1 comment

Comments

@PHuhn
Copy link

PHuhn commented Feb 20, 2022

Test Code

        [Test()]
        public async Task EmailConfirmation_Page_Test()
        {
            // given
            Smock.Run(async context =>
            {
                EmailTestPageModel _testConfirmation = new EmailTestPageModel(userManager, _emailSender.Object);
                _testConfirmation.PageContext = MockHelpers.CreatePageContext(NSG_Helpers.User_Name2, "User", "/Register/", "/Account");
                context.Setup(() => UrlHelperExtensions.Page(It.IsAny<IUrlHelper>(), "/Account/ConfirmEmail", null, It.IsAny<object>(), It.IsAny<string>())).Returns("https://localhost/Account/ConfirmEmail/");
                // when
                IActionResult _results = await _testConfirmation.OnPostAsync();
                // then
                Assert.AreEqual(_results, "https://localhost/Account/ConfirmEmail");
            });
        }

Error Message

Message: 
System.MissingMethodException : Method not found: 'Void System.AppDomainSetup.set_ApplicationBase(System.String)'.

Stack Trace: 
AppDomainContext.ctor(IAssemblyLoaderFactory assemblyLoaderFactory, ISerializer serializer, Logger logger, ISerializableLambdaFilter[] lambdaFilters)
AppDomainContext.ctor(IAssemblyRewriter assemblyRewriter, Logger logger)
Smock.RunAction(Action1 action, Configuration configuration) Smock.Run(Configuration configuration, Action1 action)
Smock.Run(Action1 action) EmailConfirmation_UnitTests.EmailConfirmation_Page_Test() line 59 GenericAdapter1.GetResult()
AsyncToSyncAdapter.Await(Func`1 invoke)
TestMethodCommand.RunTestMethod(TestExecutionContext context)
TestMethodCommand.Execute(TestExecutionContext context)
<>c__DisplayClass1_0.b__0()
BeforeAndAfterTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)

Error Occurs

The error occurs on the execution of the first line:

Smock.Run(async context =>

You Say

Strong-named assemblies

To intercept calls to targeted methods and properties, Smocks rewrites assemblies and subsequently loads the modified copies. Should the original assembly be strong-named, the assembly will need to be signed again after modification to restore the strong-naming. Smocks currently does not support rewriting strong-named assemblies.

Assumption

This is the first time I have used SMocks and I am assuming that the above is from Microsoft strongly named assemblies.

@chrisjohnson2134
Copy link

chrisjohnson2134 commented Mar 3, 2022

Seeing the same Issue. using .net core 3.1 I believe that Smocks is not fully compatible with .net core because the nugget package error indicates that it's targeting .net framework 4.7. Can you confirm that this is the issue.

code:

Smock.Run(async context =>
			{
				Mock<ILogger<PropertySetRepository>> loggerMock = new Mock<ILogger<PropertySetRepository>>();
				Mock<ISqlServerDatabase> sqlServerDatabaseMock = new Mock<ISqlServerDatabase>();

				PropertySetRepository prop = new PropertySetRepository(sqlServerDatabaseMock.Object, loggerMock.Object);

				var storedProc = "[dbo].[GetAuditHistoryApprovalsByPropertySetId]";
				IStoredProcedure procedure = new InlineStoredProcedure(storedProc)
				{
					{ "PropertySetId", 1234 }
				};
				IReadOnlyList<ApprovalModel> approvals = new List<ApprovalModel>();
				context.Setup(() => sqlServerDatabaseMock.Object.ExtractAsync(procedure, new ApprovalExtractor(), CancellationToken.None)).Returns(Task.FromResult(approvals));

				//sqlServerDatabaseMock.Setup(t => t.ExtractAsync(procedure, new ApprovalExtractor(), CancellationToken.None));

				var res = prop.GetCompSetAuditHistoryApprovals(1234);
			});


stack trace:
   at Smocks.AppDomains.AppDomainContext..ctor(IAssemblyLoaderFactory assemblyLoaderFactory, ISerializer serializer, Logger logger, ISerializableLambdaFilter[] lambdaFilters)
   at Smocks.AppDomains.AppDomainContext..ctor(IAssemblyRewriter assemblyRewriter, Logger logger)
   at Smocks.Smock.RunAction(Action`1 action, Configuration configuration)
   at Smocks.Smock.Run(Configuration configuration, Action`1 action)
   at Smocks.Smock.Run(Action`1 action)
   at PropertySetData.Tests.Repositories.PropertySetRepositoryTest.a() in C:\Users\cjohnson2\source\repos\services-external-hospitality-property-set-api\Source\tests\PropertySetData.Tests\Repositories\PropertySetRepository.cs:line 25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants