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

Support projects with multiple target frameworks #76

Closed
maca88 opened this issue Dec 29, 2017 · 2 comments
Closed

Support projects with multiple target frameworks #76

maca88 opened this issue Dec 29, 2017 · 2 comments
Milestone

Comments

@maca88
Copy link
Owner

maca88 commented Dec 29, 2017

No description provided.

@maca88 maca88 closed this as completed in 5b1cf67 Dec 30, 2017
@maca88 maca88 added this to the 0.8.0 milestone Dec 30, 2017
@ngbrown
Copy link

ngbrown commented Jan 3, 2018

So this is almost working (sorry about the note earlier that I was getting the same error). However, it is generating invalid code in one instance:

NHibernate.Test.DynamicProxyTests.PeVerifyFixture is having it's functions transformed from:

		[Test]
		public void VerifyClassWithPublicConstructor()
		{
#if NETCOREAPP2_0
			Assert.Ignore("Not applicable for NETCOREAPP2_0");
#else
			var factory = new ProxyFactory(new SavingProxyAssemblyBuilder(assemblyName));
			var proxyType = factory.CreateProxyType(typeof(ClassWithPublicDefaultConstructor), null);

			wasCalled = false;
			Activator.CreateInstance(proxyType);

			Assert.That(wasCalled);
			new PeVerifier(assemblyFileName).AssertIsValid();
#endif
		}

to

		[Test]
		public Task VerifyClassWithPublicConstructorAsync()
		{
			try
			{
#if NETCOREAPP2_0
			Assert.Ignore("Not applicable for NETCOREAPP2_0");
#else
				var factory = new ProxyFactory(new SavingProxyAssemblyBuilder(assemblyName));
				var proxyType = factory.CreateProxyType(typeof(ClassWithPublicDefaultConstructor), null);

				wasCalled = false;
				Activator.CreateInstance(proxyType);

				Assert.That(wasCalled);
				return new PeVerifier(assemblyFileName).AssertIsValidAsync();
			}
			catch (Exception ex)
			{
				return Task.FromException<object>(ex);
			}
#endif
		}

The curly braces of the try/catch are unbalanced in the generated output. The compiler generates the following error:

10>Async\DynamicProxyTests\PeVerifyFixture.cs(53,3,53,4): error CS1524: Expected catch or finally

I would expect something like this:

		[Test]
		public Task VerifyClassWithPublicConstructorAsync()
		{
			try
			{
#if NETCOREAPP2_0
				Assert.Ignore("Not applicable for NETCOREAPP2_0");
				return Task.CompletedTask;
#else
				var factory = new ProxyFactory(new SavingProxyAssemblyBuilder(assemblyName));
				var proxyType = factory.CreateProxyType(typeof(ClassWithPublicDefaultConstructor), null);

				wasCalled = false;
				Activator.CreateInstance(proxyType);

				Assert.That(wasCalled);
				return new PeVerifier(assemblyFileName).AssertIsValidAsync();
#endif
			}
			catch (Exception ex)
			{
				return Task.FromException<object>(ex);
			}
		}

@maca88
Copy link
Owner Author

maca88 commented Jan 7, 2018

With the version 0.8.1 the issue is now fixed. Keep in mind that the generator is not able to transform an async invocation inside a disabled directive, it will only make the code to be compiled (example).

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

No branches or pull requests

2 participants