public void CanCreateAndAssignMessageHeaders()
        {
            var message      = new Message <string, string>();
            var messageProxy = message.DuckCast <IMessage>();

            // Call the CachedMessageHeadersHelper using the compile-time assembly
            var headersProxy = CachedMessageHeadersHelper <TopicPartition> .CreateHeaders();

            AssertHeadersProxy(headersProxy);
            messageProxy.Headers = headersProxy;

            // Now use LoadFile to load a second instance and re-run the tests
            var loadFileAssembly     = Assembly.LoadFile(TopicPartitionType.Assembly.Location);
            var loadHeadersDetails   = CreateGenericCreateHeadersMethod(loadFileAssembly);
            var loadFileHeadersProxy = (IHeaders)loadHeadersDetails.CreateHeaders.Invoke(null, null);

            AssertHeadersProxy(loadFileHeadersProxy);
            messageProxy = loadHeadersDetails.Message;

#if NETCOREAPP3_1 || NET5_0
            var alc = new System.Runtime.Loader.AssemblyLoadContext($"NewAssemblyLoadContext");
            var loadContextAssembly = alc.LoadFromAssemblyPath(TopicPartitionType.Assembly.Location);
            var loadContextDetails  = CreateGenericCreateHeadersMethod(loadContextAssembly);

            var loadContextHeadersProxy = (IHeaders)loadContextDetails.CreateHeaders.Invoke(null, null);
            AssertHeadersProxy(loadContextHeadersProxy);
            messageProxy = loadContextDetails.Message;
#endif
        }
Пример #2
0
        public static async Task Main(string[] args)
        {
            using var listener = StartHttpListenerWithPortResilience(out var uri);

            await RunAsync(typeof(HttpClient), uri);

            for (int i = 0; i < 5; i++)
            {
                var assembly = Assembly.LoadFile(typeof(HttpClient).Assembly.Location);
                await RunAsync(assembly.GetType("System.Net.Http.HttpClient"), uri);
            }

#if NETCOREAPP3_1 || NET5_0
            for (int i = 0; i < 5; i++)
            {
                var alc      = new System.Runtime.Loader.AssemblyLoadContext($"Context: {i}");
                var assembly = alc.LoadFromAssemblyPath(typeof(HttpClient).Assembly.Location);
                await RunAsync(assembly.GetType("System.Net.Http.HttpClient"), uri);
            }
#endif
        }
Пример #3
0
        static void Main(string[] args)
        {
            string prefix = "";

            if (args.Length > 0)
            {
                prefix = args[0];
            }

            // Use the compile-time types and run the tests
            using (var redisManager = new PooledRedisClientManager(Host()))
                using (var redis = (RedisClient)redisManager.GetClient())
                {
                    RunServiceStack(prefix, new RedisClientWrapper(redis));
                }

            // Now use LoadFile to load a second instance and re-run the tests
            var loadFileAssembly = Assembly.LoadFile(_clientManagerType.Assembly.Location);

            using (IDisposable redisManager = (IDisposable)InstantiateClientManagerFromAssembly(loadFileAssembly))
                using (IDisposable redis = (IDisposable)GetClientFromClientManager(redisManager))
                {
                    RunServiceStack(prefix, new RedisClientWrapper(redis));
                }

#if NETCOREAPP3_1 || NET5_0
            var alc         = new System.Runtime.Loader.AssemblyLoadContext($"NewAssemblyLoadContext");
            var alcAssembly = alc.LoadFromAssemblyPath(typeof(PooledRedisClientManager).Assembly.Location);

            using (IDisposable redisManager = (IDisposable)InstantiateClientManagerFromAssembly(alcAssembly))
                using (IDisposable redis = (IDisposable)GetClientFromClientManager(redisManager))
                {
                    RunServiceStack(prefix, new RedisClientWrapper(redis));
                }
#endif
        }
Пример #4
0
        public Type GenerateProxy(Type serviceContract)
        {
            var assemblyName = new AssemblyName(serviceContract.FullName + ".Proxy");

            bool saveAssembly;
            var  assemblyBuilder = CreateAssemblyBuilder(AppDomain.CurrentDomain, assemblyName, out saveAssembly);
            var  moduleBuilder   = CreateModuleBuilder(assemblyBuilder, saveAssembly);
            var  clientType      = CreateClientType(serviceContract, moduleBuilder);

            if (saveAssembly)
            {
#if NET48
                assemblyBuilder.Save(assemblyName.Name + ".dll");
#else
                // Don't take a dedendency on Lokad.ILPack.nupkg. Also, at the time of this writing
                // the most current version (0.6.1) did caused an exception. Building the repo
                // (74f8fe7) and referencing the created DLL did work.
                string directory   = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string helper      = Path.Combine(directory, "Lokad.ILPack.dll");
                bool   foundHelper = false;

                if (!File.Exists(helper))
                {
                    helper = Environment.GetEnvironmentVariable("WCFPROXY_SAVE_HELPER");
                    if (!string.IsNullOrEmpty(helper) && File.Exists(helper))
                    {
                        foundHelper = true;
                    }
                }
                else
                {
                    foundHelper = true;
                }

                if (foundHelper)
                {
                    var ldx = new System.Runtime.Loader.AssemblyLoadContext(helper, true);
                    try
                    {
                        var hass      = ldx.LoadFromAssemblyPath(helper);
                        var genType   = hass.GetType("Lokad.ILPack.AssemblyGenerator");
                        var genMethod = genType.GetMethod("GenerateAssembly", new[] { typeof(Assembly), typeof(string) });

                        var    generator  = Activator.CreateInstance(genType);
                        string outputFile = Path.Combine(AssemblyOutputDirectory, assemblyName.Name + ".dll");
                        genMethod.Invoke(generator, new object[] { assemblyBuilder, outputFile });
                    }
                    finally
                    {
                        ldx.Unload();
                    }
                }
                else
                {
                    Trace.WriteLine($"Saving assembly to file is not supported. " +
                                    $"File '{AssemblyOutputDirectory}\\{assemblyName}.dll' not created");
                }
#endif
            }

            return(clientType);
        }