Month: July 2022

Uncategorized

FactoryPattern adaptions real world

adapt a pattern and build a reald world ex into it

https://github.com/flowxcode/dotnet-design-patterns-samples#factory-method

https://github.com/flowxcode/dotnet-design-patterns-samples/tree/master/Generating/FactoryMethod

  1. build pattern
  2. introduce config
  3. locate point from where to read config in current project
  4. read config early and compare in diagrams

the factory pattern:

https://dotnetcoretutorials.com/2019/10/15/the-factory-pattern-in-net-core/

TestFixtureContextBase.cs
DeviceMapper -> gets a new DeviceFactory creates Devices , Devices inherit from Device class.

Uncategorized

.dll Type Library Importer Tlbimp.exe and Tlbexp.exe

wanted to add AwUsbApi.dll lib but got

trying to validate dlls

https://stackoverflow.com/questions/3456758/a-reference-to-the-dll-could-not-be-added

using VS Developer Command Prompt

https://docs.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=vs-2022

C:\Program Files\Digi\AnywhereUSB\Advanced>tlbimp AwUsbApi.dll
Microsoft (R) .NET Framework Type Library to Assembly Converter 4.8.3928.0
Copyright (C) Microsoft Corporation.  All rights reserved.

TlbImp : error TI1002 : The input file 'C:\Program Files\Digi\AnywhereUSB\Advanced\AwUsbApi.dll' is not a valid type library.

C:\Program Files\Digi\AnywhereUSB\Advanced>Tlbexp AwUsbApi.dll
Microsoft (R) .NET Framework Assembly to Type Library Converter 4.8.3928.0
Copyright (C) Microsoft Corporation.  All rights reserved.

TlbExp : error TX0000 : Could not load file or assembly 'file:///C:\Program Files\Digi\AnywhereUSB\Advanced\AwUsbApi.dll' or one of its dependencies. The module was expected to contain an assembly manifest.

ist not the first problem. already encountered on digi forum

https://www.digi.com/support/forum/27954/problems-with-awusbapi-dll

Uncategorized

string empty or “”

one pretty fundamental answer:

c stackoverflow:

There really is no difference from a performance and code generated standpoint. In performance testing, they went back and forth between which one was faster vs the other, and only by milliseconds.

In looking at the behind the scenes code, you really don't see any difference either. The only difference is in the IL, which string.Empty use the opcode ldsfld and "" uses the opcode ldstr, but that is only because string.Empty is static, and both instructions do the same thing. If you look at the assembly that is produced, it is exactly the same.

C# Code

private void Test1()
{
    string test1 = string.Empty;    
    string test11 = test1;
}

private void Test2()
{
    string test2 = "";    
    string test22 = test2;
}

IL Code

.method private hidebysig instance void 
          Test1() cil managed
{
  // Code size       10 (0xa)
  .maxstack  1
  .locals init ([0] string test1,
                [1] string test11)
  IL_0000:  nop
  IL_0001:  ldsfld     string [mscorlib]System.String::Empty
  IL_0006:  stloc.0
  IL_0007:  ldloc.0
  IL_0008:  stloc.1
  IL_0009:  ret
} // end of method Form1::Test1
.method private hidebysig instance void 
        Test2() cil managed
{
  // Code size       10 (0xa)
  .maxstack  1
  .locals init ([0] string test2,
                [1] string test22)
  IL_0000:  nop
  IL_0001:  ldstr      ""
  IL_0006:  stloc.0
  IL_0007:  ldloc.0
  IL_0008:  stloc.1
  IL_0009:  ret
} // end of method Form1::Test2

Assembly code

        string test1 = string.Empty;
0000003a  mov         eax,dword ptr ds:[022A102Ch] 
0000003f  mov         dword ptr [ebp-40h],eax 

        string test11 = test1;
00000042  mov         eax,dword ptr [ebp-40h] 
00000045  mov         dword ptr [ebp-44h],eax 
        string test2 = "";
0000003a  mov         eax,dword ptr ds:[022A202Ch] 
00000040  mov         dword ptr [ebp-40h],eax 

        string test22 = test2;
00000043  mov         eax,dword ptr [ebp-40h] 
00000046  mov         dword ptr [ebp-44h],eax 

https://stackoverflow.com/a/1588678/1650038

Uncategorized

COMException

System.Runtime.InteropServices.COMException (0x800703FA): Retrieving the COM class factory for component with CLSID {82EAAE85-00A5-4FE1-8BA7-8DBBACCC6BEA} failed due to the following error: 800703fa Illegal operation attempted on a registry key that has been marked for deletion. (0x800703FA).
at System.RuntimeTypeHandle.AllocateComObject(Void* pClassFactory)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type)
at ...

Solution

moved instance into ctor

public KeoObj()
{
  _proxiLab = (IProxiLAB)Activator.CreateInstance(Type.GetTypeFromProgID("KEOLABS.ProxiLAB"));
}

always a charm, clean code:

https://methodpoet.com/clean-code/

possible relevance:

https://stackoverflow.com/questions/21941216/using-application-pool-identity-results-in-exceptions-and-event-logs

link base:

http://adopenstatic.com/cs/blogs/ken/archive/2008/01/29/15759.aspx

Uncategorized

the AMR command

section 4.5.1, APPLICATION MANAGEMENT REQUEST (AMR) Command

https://globalplatform.org/wp-content/uploads/2014/03/GPC_ISO_Framework_v1.0.pdf

ideas tear and check and repeat.

run multiple parameterized tests with NUnit as in:

https://www.lambdatest.com/blog/nunit-parameterized-test-examples/

        [Test]
        [TestCase("chrome", "72.0", "Windows 10")]
        [TestCase("internet explorer", "11.0", "Windows 10")]
        [TestCase("Safari", "11.0", "macOS High Sierra")]
        [TestCase("MicrosoftEdge", "18.0", "Windows 10")]
        [Parallelizable(ParallelScope.All)]
        public void DuckDuckGo_TestCase_Demo(String browser, String version, String os)
        {
            String username = "user-name";
            String accesskey = "access-key";
            String gridURL = "@hub.lambdatest.com/wd/hub";

interfaces

set up ASP.NET API IIS path.

  • Add Website and created folder eg . c:\iis\myapi
  • Change Application Pool to No Managed Code
  • Check Security of Folder, add
    • IIS_IUSRS
    • IIS AppPool\myapi
  • Browse Created Website (should result in HTTP Error 403.14 - Forbidden to list contents cause nothing is in)
  • Create new repo eg github
  • Create new VisualStudio ASP.NET Core API
  • Run and Debug
  • try api endpoints
  • publish to target Folder (best case: separate folder to copy after publish)
  • Copy contents (using TeraCopy eg , resp. diff sync tool)
  • try sampleendpoint
    • take care that Swagger is not configured to show in default so dont despair
  • commit your state if working
  • checking git status is everything is correctly tracked.
  • rename WeatherForecast to dream name best with eg. Notepad++ replace all and change files names in VS later on.
  • test run and debug
  • publish again
  • test it on local IIS.

works till here. so integrate biz logic and repeat small steps cycle step by step.

sources of error investigation:

https://stackify.com/beyond-iis-logs-find-failed-iis-asp-net-requests/

custom err exc handling

API functional, but problems showing swagger site. steps:

  • had to check security of the COM object:

https://stackoverflow.com/questions/27937375/retrieving-the-com-class-factory-for-component-with-clsid-failed-due-to-the-foll

due to Event Viewer error desc

Category: Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer
EventId: 2
SpanId: cb7174b3e1054a29
TraceId: 789b2e9b100bdb4d3fe6ed8e154135f1
ParentId: 0000000000000000
RequestId: 80000006-0007-ff00-b63f-84710c7967bb
RequestPath: /Keo/CreateKeoObj

Connection ID "18374686511347007489", Request ID "80000006-0007-ff00-b63f-84710c7967bb": An unhandled exception was thrown by the application.

Exception: 
System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {82EAAE85-00A5-4FE1-8BA7-8DBBACCC6BEA} failed due to the following error: 80070005 Access is denied. (0x80070005 (E_ACCESSDENIED)).
   at System.RuntimeTypeHandle.AllocateComObject(Void* pClassFactory)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type)
   at KeoCoreApi.KeoObj.CreateKeoInstance() in C:\git\keolabs\KeoCoreApi\KeoObj.cs:line 18
   at lambda_method4(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()

Next steps if resolved: test from different computer, intranet:

  • connect to ip host and port
  • if connection is not working through, check firewall rules.
  • go to advanced settings
  • open up required port by adding Inbout Rule Port
  • test api from network computer
  • add /swagger , respectively the desired endpoint to url

.