SharpeRAD / Cake.IIS

IIS addin for Cake
http://cakebuild.net
MIT License
52 stars 28 forks source link

NullReferenceException when calling <SiteExists()> #62

Open nbaser opened 4 years ago

nbaser commented 4 years ago

Dear Developers,

lately my Team can't use the SiteExists() funtion. The functions throws allways a NullReferenceException. It's related to the latest addin version and occurs on Windows 10 (latest and previous update versions) Is this a known issue or does someone have any ideas for a workaround?

With kind regards.

IlyaDhtvzGhbltn commented 4 years ago

Any updates ? I am using Cake.IIS version 0.4.2 on Windows 10 like this

try {
    bool exist = SiteVirtualDirectoryExists(PCName, settings);
}
catch (System.Exception ex)
{
    Information(ex.StackTrace);
}

and get the same error

Error: One or more errors occurred. Object reference not set to an instance of an object.

Cake.IIS.VirtualDirectorySettings at Microsoft.Web.Administration.ConfigurationManager.CreateWritableAdminManager(WebConfigurationMap webConfigMap, String configPathToEdit, Boolean isAdminConfig, Boolean isRedirectionConfig) at Microsoft.Web.Administration.ConfigurationManager.CreateConfiguration(WebConfigurationMap configMap, String configPathToEdit, Boolean isAdminConfig, Boolean isRedirectionConfig) at Microsoft.Web.Administration.ConfigurationManager.GetConfiguration(String rawConfigurationPath, String cacheKey, Boolean isAdminConfig, Boolean isRedirectionConfig) at Microsoft.Web.Administration.ConfigurationManager.GetApplicationHostConfiguration() at Microsoft.Web.Administration.ServerManager.SitesSectionCreator() at Microsoft.Web.Administration.Lazy.Initialize[T](T& target, CreateInstanceDelegate1 valueFactory) at Microsoft.Web.Administration.ServerManager.SitesCollectionCreator() at Microsoft.Web.Administration.Lazy.Initialize[T](T& target, CreateInstanceDelegate1 valueFactory) at Cake.IIS.BaseSiteManager.VirtualDirectoryExists(VirtualDirectorySettings settings) at Cake.IIS.VirtualDirectoryAliases.SiteVirtualDirectoryExists(ICakeContext context, String server, VirtualDirectorySettings settings) at Submission#0.SiteVirtualDirectoryExists(String server, VirtualDirectorySettings settings) in :line 3015 at Submission#0.<>b__0_1(ICakeContext context) in C:**\script.cake:line 131

SharpeRAD commented 4 years ago

Please contribute to the community by submitting a PR to resolve this issue.

nrukavkov commented 4 years ago

@SharpeRAD please give us the hint where could be a problem. Your addin is amazing and we want to continue to support it if you can't

SharpeRAD commented 4 years ago

The exception is thrown by Microsoft.Web.Administration This project is really just a wrapper for that nuget package which hasn’t been updated in a long time and hasn’t been open sourced.

I’ve provided a troubleshooting page for all known errors and solutions. I would assume from the code that the issue is caused by remote calls to versions that don't support it.

Check which version of IIS you are using and when Microsoft switched to using REST based administration APIs (v10)

Explorer the REST API docs for alternative methods

I’m happy to accept any PRs that will resolve this.