googleads / googleads-dotnet-lib

Google Ad Manager SOAP API .NET client library
Apache License 2.0
108 stars 199 forks source link

Null reference exception after .exe file is embedded into c# Project #189

Closed Pallavi-S closed 8 months ago

Pallavi-S commented 5 years ago

I am using Google Adwords Api for LXRPlugin[Excel AddIn] in visual studio 2017 c# project. The visual studio solution contains GoogleAPIIntraction as the main project. The solution runs successfully before .exe file is packaged. After creating .exe file and installing the setup file I am getting the error. In log file following messages are shown in the build.

DownloadDllFiles() An exception occurred during a WebClient request. DownloadXMLFiles() An exception occurred during a WebClient request. Clicked on Add account button selectd package type:agency Adword autherization login form

Ribbon button1_Click Could not load file or assembly 'Google.Apis.Core, Version=1.33.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).

I am sharing the code for DownloadDllFiles and DownloadXMLFiles.

 private void DownloadDllFiles()
        {
            List<string> dllFiles = new List<string> { "Google.Ads.Common.dll", "Google.AdWords.dll" }; //"Google.Apis.Analytics.v3.dll", "Google.Apis.Auth.dll", "Google.Apis.Auth.PlatformServices.dll", "Google.Apis.Core.dll", "Google.Apis.dll", "Google.Apis.PlatformServices.dll" };
            string strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
            strAppDir = strAppDir.Remove(0, 6);
            System.Net.WebClient wc = new System.Net.WebClient();
            foreach (var dll in dllFiles)
            {
                string filePath = strAppDir + dll;
                try
                {
                    wc.DownloadFile(Globals.ThisAddIn.LXRXMLFilePath + dll, filePath);
                }
                catch (Exception ex) { LogWriter.Instance.CreateEntry("DownloadDllFiles() " + ex.Message); }
            }
        }
   ```
private void DownloadXMLFiles()
        {
            List<string> xmlFiles = new List<string> { "ACCOUNT_PERFORMANCE_REPORT.xml", "ADGROUP_PERFORMANCE_REPORT.xml",
                "AD_EXTENSIONS_PERFORMANCE_REPORT.xml", "AD_PERFORMANCE_REPORT.xml", "AGE_RANGE_PERFORMANCE_REPORT.xml",
                "AUDIENCE_PERFORMANCE_REPORT.xml", "AUTOMATIC_PLACEMENTS_PERFORMANCE_REPORT.xml", "CALL_METRICS_CALL_DETAILS_REPORT.xml",
                "CAMPAIGN_NEGATIVE_KEYWORDS_PERFORMANCE_REPORT.xml", "CAMPAIGN_NEGATIVE_PLACEMENTS_PERFORMANCE_REPORT.xml",
                "CAMPAIGN_PERFORMANCE_REPORT.xml", "DISPLAY_KEYWORD_PERFORMANCE_REPORT.xml", "FINAL_URL_REPORT.xml",
                "GENDER_PERFORMANCE_REPORT.xml", "GEO_PERFORMANCE_REPORT.xml", "KEYWORDLESS_QUERY_REPORT.xml","ANALYTICS_QUERY_COLUMNS.xml",
                "KEYWORDS_PERFORMANCE_REPORT.xml", "SEARCH_QUERY_PERFORMANCE_REPORT.xml","PAID_ORGANIC_QUERY_REPORT.xml" };
            string strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
            strAppDir = strAppDir.Remove(0, 6);
            strAppDir = Path.Combine(strAppDir + "\\Xmls\\");
            System.Net.WebClient wc = new System.Net.WebClient();
            foreach (var xml in xmlFiles)
            {
                string filePath = strAppDir + xml;
                try
                {
                    wc.DownloadFile(Globals.ThisAddIn.LXRXMLFilePath + xml, filePath);
                }
                catch (Exception ex) { LogWriter.Instance.CreateEntry("DownloadXMLFiles() " + ex.Message); }
            }
        }

Please help me.

Thanks in advance.
christopherseeley commented 5 years ago

Are you using nuget for dependency management? If not, is it an option?

Pallavi-S commented 5 years ago

I am using nuget to upgrade Google Adwords and Analytics Api,The latest version of google.api.core version is 1.36.1 version,but the required version is 1.33.1. If i uninstall 1.36.1 and install 1.33.1 version, the dependenies and other version are missing.

Pallavi-S commented 5 years ago

I am sending the Fusion Log file for this exception, it may be useful to find the solution.

Fusion Log Info.txt.

Please try to solve my issue.

Thanks in advance, Pallavi

AnashOommen commented 5 years ago

LOG: Post-policy reference: Google.Apis.Core, Version=1.33.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab LOG: Attempting download of new URL file:///C:/Program Files (x86)/NetElixir Inc/LXRPlugin/Google.Apis.Core.DLL. WRN: Comparing the assembly name resulted in the mismatch: Minor Version

Looks like your LXRPlugin folder has an older version of Google.Apis.Core.dll?

On Thu, Nov 15, 2018, 5:57 AM Pallavi-S <notifications@github.com wrote:

I am sending the Fusion Log file for this exception, it may be useful to find the solution.

Fusion Log Info.txt https://github.com/googleads/googleads-dotnet-lib/files/2584948/Fusion.Log.Info.txt .

Please try to solve my problem.

Thanks in advance, Pallavi

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/googleads/googleads-dotnet-lib/issues/189#issuecomment-439000797, or mute the thread https://github.com/notifications/unsubscribe-auth/AETkiNIO8SkBotRpVSLPvi3NsiCIYc9Rks5uvUiCgaJpZM4YGdHX .

Pallavi-S commented 5 years ago

Hi,

LXRPlugin folder contains the updated version 1.36.1, if i update 1.33.1 the dependency libraray google.apis.auth versions are missing.

Thanks, Pallavi

On Thu, Nov 15, 2018 at 7:03 PM Anash P. Oommen notifications@github.com wrote:

LOG: Post-policy reference: Google.Apis.Core, Version=1.33.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab LOG: Attempting download of new URL file:///C:/Program Files (x86)/NetElixir Inc/LXRPlugin/Google.Apis.Core.DLL. WRN: Comparing the assembly name resulted in the mismatch: Minor Version

Looks like your LXRPlugin folder has an older version of Google.Apis.Core.dll?

On Thu, Nov 15, 2018, 5:57 AM Pallavi-S <notifications@github.com wrote:

I am sending the Fusion Log file for this exception, it may be useful to find the solution.

Fusion Log Info.txt < https://github.com/googleads/googleads-dotnet-lib/files/2584948/Fusion.Log.Info.txt

.

Please try to solve my problem.

Thanks in advance, Pallavi

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub < https://github.com/googleads/googleads-dotnet-lib/issues/189#issuecomment-439000797 , or mute the thread < https://github.com/notifications/unsubscribe-auth/AETkiNIO8SkBotRpVSLPvi3NsiCIYc9Rks5uvUiCgaJpZM4YGdHX

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/googleads/googleads-dotnet-lib/issues/189#issuecomment-439041403, or mute the thread https://github.com/notifications/unsubscribe-auth/ApK3NTE9yz1Z8K4EIgBT4DV2Y1PAER0wks5uvW1FgaJpZM4YGdHX .

--

CONFIDENTIALITY INFORMATION AND DISCLAIMER

This email message and its attachments may contain confidential, proprietary or legally privileged information and is intended solely for the use of the individual or entity to whom it is addressed. If you have erroneously received this message, please delete all copies of it immediately and notify the sender. If you are not the intended recipient of the email message you should not disseminate, distribute or copy this e-mail. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, incomplete or contain viruses and NetElixir accepts no liability for any damage caused by the limitations of the e-mail transmission. Thank you for your cooperation.

AnashOommen commented 5 years ago

Try adding an assembly binding redirect binding in the App.config file like this:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Google.Apis.Core" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.36.1.0" newVersion="1.36.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

You can add similar redirects for all the versions of the dependent assemblies that fusion.log complains about.

Pallavi-S commented 5 years ago

Hi,

App config file already contains the binding redirects for the dll as specified.

Any other solution to solve this issue?

Thanks in advance, Pallavi

On Tue, Nov 20, 2018 at 2:43 AM Anash P. Oommen notifications@github.com wrote:

Try adding an assembly binding redirect binding in the App.config file like this:

You can add similar redirects for all the versions of the dependent assemblies that fusion.log complains about.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/googleads/googleads-dotnet-lib/issues/189#issuecomment-440043354, or mute the thread https://github.com/notifications/unsubscribe-auth/ApK3NWiQgURzhjWaCrX8UIvf2jwlTqnHks5uwx7igaJpZM4YGdHX .

--

CONFIDENTIALITY INFORMATION AND DISCLAIMER

This email message and its attachments may contain confidential, proprietary or legally privileged information and is intended solely for the use of the individual or entity to whom it is addressed. If you have erroneously received this message, please delete all copies of it immediately and notify the sender. If you are not the intended recipient of the email message you should not disseminate, distribute or copy this e-mail. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, incomplete or contain viruses and NetElixir accepts no liability for any damage caused by the limitations of the e-mail transmission. Thank you for your cooperation.

AnashOommen commented 5 years ago

Hi Pallavi, was this issue resolved?

davidmine commented 4 years ago

For what it's worth, I experienced a similar problem when I upgraded Google.AdManager from 24.3 to 24.9. I upgraded the NuGet packages Google.Apis, Google.Apis.Auth, and Google.Apis.Core from 1.36.1 to 1.42 (the most up-to-date at the time). While Google.AdManager and Google.Ads.Common claimed to be able to use >=1.36.1, I found that I had trouble unless I kept the packages Google.Apis, Google.Apis.Auth, and Google.Apis.Core at the default version requested by Google.AdManager.

My uninstalled all Google packages, installed the version of Google.AdManager that I wanted, and kept all the default dependencies. No problems afterward.