Strongly named assemblies does not seem to work

Issue #3 resolved
Former user created an issue

I tried to get it to work the other day but I couldn’t.

{"Trying to add interceptors for method GetLineStatuses, but the type declared in the JSON doesn't match it's type."}

Our application works with strongly named assemblies in the GAC, maybe that’s why it is not working?

This is the config file I am trying with (I have chosen a method without parameters to make it easier, without the public key token, version and culture I was getting another error about not being able to find the assembly):

{
    "Types": [
        {
            "TypeName": "Sequel.UW.Risk.UIP.EditPolicyWorkItem, Sequel.UW.Risk.UIP, Version=3.3.0.0, PublicKeyToken=a33a4222cb18bcbe, Culture=neutral",
            "Methods": [
                {
                    "MethodSignature": "GetLineStatuses()",
                    "Interceptors": [ "WriteMethodNameToConsoleInterceptor"]
                }
            ],
           "GenericArgumentTypes": []

        }

    ],
    "GlobalInterceptors": [],
    "Key":""
}

That class is declared in another assembly (signed), called Sequel.UW.Risk.UIP.dll:

namespace Sequel.UW.Risk.UIP
{
    public class EditPolicyWorkItem : WorkItem, ILockableEntity, IDisposable
    {

And the method I am trying to intercept is:

        public string GetLineStatuses()
        {

If the assembly reference is not strong (i.e. without culture, version and public token) then I get the following:

{"The type Sequel.UW.Risk.UIP.EditPolicyWorkItem, Sequel.UW.Risk.UIP could not be found. Is the name correct in the JSON?"}

Comments (7)

  1. Ricardo Barbosa

    Hi Javier,

    Thanks for reporting this issue back to us.

    I have recreated your scenario, by signing and placing on the GAC a Sequel.UW.Risk.UIP.dll.

    gac1.jpg

    In fact the only was to make it work was to select copy local on the assembly properties.

    copy-local.jpg

    Of course that works for dev environments but not for production so I have fixed that and just uploaded v.1.2.4 onto nuget for you to please try it out.

    From this version on I have conventionalized that for GAC assemblies only we shouldn't declare the type FullName on the JSON.

    This is how your JSON should look:

    {
        "Types": [
            {
                "TypeName": "Sequel.UW.Risk.UIP.EditPolicyWorkItem",
                "Methods": [
                    {
                        "MethodSignature": "GetLineStatuses()",
                        "Interceptors": [ "WriteMethodNameToConsoleInterceptor"]
                    }
                ],
               "GenericArgumentTypes": []
    
            }
    
        ],
        "GlobalInterceptors": [],
        "Key":""
    }
    

    Please tell me if that worked for you.

    Thanks,

    Ricardo

  2. Javier García Magna

    Hi!

    Sorry I should have said the other DLL is loaded by reflection (sometimes) / dependency injection (other scenarios). Apologies as I didn't make this clear, i.e. there is not a direct reference from the main project to the other DLL.

    Unfortunately 1.2.4 doesn't work yet. I have upgraded the package but if I don't specify a strong name in the config file then I get:

    {"The type Sequel.UW.Risk.UIP.EditPolicyWorkItem could not be found. Is the name correct in the JSON?"}

    If I enter the full name for the DLL then I get the other error I was getting:

    {"Trying to add interceptors for method GetLineStatuses, but the type declared in the JSON doesn't match it's type."}

    Codecop version updated to 1.2.4

    Many thanks and apologies for not making it clear. So the scenario is a bit weird I know, DLLs in the GAC + loaded in runtime. I don't think we can get away without specifying the full name in the config file.

  3. Ricardo Barbosa

    Hi Javier,

    I've just uploaded v1.2.6 onto nuget that adds the possibility to load assemblies from custom locations.

    This is an example of how the JSON could look like for your specific case

    {
      "Types": [
    
        {
          "TypeName": "Sequel.UW.Risk.UIP.EditPolicyWorkItem",
          "Methods": [
            {
              "MethodSignature": "GetLineStatuses()",
              "Interceptors": [ "BeforeAfterInterceptor" ]
            }
          ],
          "GenericArgumentTypes": [ ],
          "AssemblyPath": "C:\\Windows\\Microsoft.NET\\assembly\\GAC_MSIL\\Sequel.UW.Risk.UIP\\v4.0_1.0.0.0__19b7b37c1bacf8ce\\Sequel.UW.Risk.UIP.dll"
        }
      ],
      "GlobalInterceptors": [ ],
      "Key": ""
    }
    

    Please tell us if that works for you.

    Thanks, Ricardo

  4. Javier García Magna

    Hey,

    Just to let you know that it seems to work :-) By the way you don't need to specify the folder in the GAC (a bit ugly) but the path where the DLL is, so for example in my case

    "c:\Program Files (x86)\Sequel Underwriting\bin\gac\Sequel.UW.Risk.UIP.dll"

    (the DLLs are dropped there by the installation script and then added to the GAC)

    I will play a little bit more with it but so far so good.

  5. Ricardo Barbosa

    Alright! That's excellent news Javier! :)

    Yes, explore it and ping me if you need any assistance.

    I will close this ticket for now.

    Keep in touch,

    Ricardo

  6. Log in to comment