Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudConfigurationManager throws exception if not run in azure dev emulator #91

Closed
tparvi opened this issue Jun 9, 2012 · 18 comments
Closed

Comments

@tparvi
Copy link

tparvi commented Jun 9, 2012

I'm using VS2012 RC with Azure SDK v1.7. I created new cloud service using ASP.NET MVC4 (empty application) and put following code into Application_Start (the setting is configured in web.config and service configuration correctly):

var value = CloudConfigurationManager.GetSetting("setting");

If I set my web application as startup project in VS the line throws exception "Not running in a hosted service or the Development Fabric" This happens when AzureApplicationSettings calls Trace.WriteLine.

So the problem is that by default the Azure DiagnosticMonitorTraceListener is registered in the web.config and if you are not running inside dev emulator all Trace messages fail.

I'm reporting this because I thought the whole point of CloudConfigurationManager was to make it easier to run web application either inside or outside of the azure dev emulator. Simple fix is to replace the azure trace listener from web.config with something that works without azure dev emulator. So maybe this can be fixed with documentation updated on MSDN (couldn't find anything related to this issue) or is there a better way to handle this?

@ghost ghost assigned aliakb Jun 9, 2012
@piyushjo
Copy link
Contributor

Thank you for reporting this issue - we are investigating the right fix for this issue.

@tobese
Copy link

tobese commented Sep 4, 2012

Hi
I have a similar problem. Running VS2010 and using a WCF service in a WebRole.

When I use the Web Project as Startup and then call:
CloudConfigurationManager.GetSetting("SomeSetting");

I get:

System.Configuration.ConfigurationErrorsException was unhandled by user code
Message=Could not create Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
Source=System
BareMessage=Could not create Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
Line=0
StackTrace:
at System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType, String initializeData)
at System.Diagnostics.TypedElement.BaseGetRuntimeObject()
at System.Diagnostics.ListenerElement.GetRuntimeObject()
at System.Diagnostics.ListenerElementsCollection.GetRuntimeObject()
at System.Diagnostics.TraceInternal.get_Listeners()
at System.Diagnostics.TraceInternal.WriteLine(String message)
at System.Diagnostics.Trace.WriteLine(String message)
at Microsoft.WindowsAzure.AzureApplicationSettings..ctor()
at Microsoft.WindowsAzure.CloudConfigurationManager.get_AppSettings()
at Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting(String name)
at Ifs.Cloud.Production.ServerRole.Downlink.GetResource(String resource, Int32 pageSize, Int32 page, Call call) in E:\work\ZapZap\VisualStudio\TestProjects\ServerRole2\Ifs.Cloud.Production.ServerRole\Downlink.svc.cs:line 29
at SyncInvokeGetResource(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
InnerException: System.InvalidOperationException
Message=Not running in a hosted service or the Development Fabric.
Source=Microsoft.WindowsAzure.Diagnostics
StackTrace:
at Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.GetDefaultStartupInfoForCurrentRoleInstance()
at Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener..ctor()
InnerException:

@tparvi
Copy link
Author

tparvi commented Sep 4, 2012

In the current project I solved this like this:

  1. Comment out the Azure diagnostics listener from web.config (system.diagnostics / trace / listeners where you see Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener)

  2. In the WebRole.cs configure the trace listener by hand:

    Trace.Listeners.Add(new DiagnosticMonitorTraceListener());

Also you can use RoleEnvironment.IsAvailable to check if you are running inside azure or not and act accordingly (use web.config vs. cloud configuration). Note that I'm not using CloudConfigurationManager class but the old RoleEnvironment.GetConfigurationSettingValue() to read the settings.

Edit: I'm actually initializing azure trace listener in WebRole.cs and not in global.asax.cs.

@tafs7
Copy link

tafs7 commented Sep 10, 2012

I have done the steps recommended by @tparvi above, and this seems to get me a little farther along...sometimes. I occasionally still get a message when I hit F5 that says it could not attach the debugger to one of my web roles. To make this go away, tipically, I have to close VS2012, and exit out of the emulator. Then re-open VS2012 and my solution, then F5 again.

After the changes above and when the emulator actually attaches the debugger, I do get the web app to come up in the browser, but when it hits a line of code that calls CloudConfigurationManager.GetSetting(key), it throws a configuration exception with an inner exception stating that I am not running in a cloud.

Also, if I try to hit a line that calls CloudStorageAccount.FromConfigurationSetting(string), this call always returns null, although the connection string is pointing to a valid account key.

It's also worth pointing out that I have 3 team members that use the same source code pulled down from our SVN repository, and they are able to successfully build, run the emulator, and run the apps with the same config settings.

One of those coworkers (like me) is running VS 2012, while the other two are still on VS2010.

Please help! This issue is killing my productivity.

@pr1ntr
Copy link

pr1ntr commented Sep 12, 2012

Is there any headway on this? My project (for no reason) just started to throw this error regardless of configuration. I am know completely blocked from using cloudstorage from localhost.

@hmvs
Copy link

hmvs commented Nov 21, 2012

Same problem. Any solution?

@ghost ghost assigned ogail Mar 28, 2013
@dapug
Copy link

dapug commented Sep 8, 2013

So, um, hey Microsoft, you gonna fix this or what? It's still an issue in v2.1 and this has been a known issue for over a year now. Very annoying.

VS2012 RTM on a WebRole, have to comment out or delete DiagnosticMonitorTraceListener from webconfig in order to run the app outside of the emulator, even though this is the whole point of CloudConfigurationManager.

@jeffwilcox
Copy link
Contributor

I'm following up with folks on this.

@ogail
Copy link
Contributor

ogail commented Oct 18, 2013

Hi guys,
I've proposed a fix in a PR, we'd appreciate your feedback

ogail referenced this issue Oct 21, 2013
Fix WindowsAzure#91
@ogail ogail closed this as completed in 486a38e Oct 22, 2013
@ogazitt
Copy link

ogazitt commented Oct 23, 2013

what release will this fix ship in?

@jeffwilcox
Copy link
Contributor

@ogazitt we're working to prepare an increment nuget update with the hotfix; will reopen this and assign to you to verify once we get that out, hopefully in the next week or so.

@jeffwilcox jeffwilcox reopened this Oct 23, 2013
@ogazitt
Copy link

ogazitt commented Oct 23, 2013

Thanks Jeff.  Having a hot fix would be very helpful given that building it by hand would require me to change the strong naming references throughout the project. 

FWIW, with the 2.1 SDK, I've never been able to work around this issue by adding the DiagnosticMonitorTraceListener instance to the Trace.Listeners collection.  Right now I have to remember to uncomment the appropriate config directive before I deploy, which is obviously suboptimal. Looking forward to a real fix :)


Sent from Mailbox for iPhone

On Tue, Oct 22, 2013 at 10:32 PM, Jeff Wilcox notifications@github.com
wrote:

Reopened #91.

Reply to this email directly or view it on GitHub:
#91

@MFisherMSFT
Copy link

@ogail If you would like to at least eliminate the manual step of changing your config before deploying, you can use a separate solution configuration for deploying.

@ogazitt
Copy link

ogazitt commented Oct 23, 2013

@MFisherMSFT I know how to create separate .cscfg for production and local but I don't know how to create separate web.config files without some post-build hackery. In the past I know there was a mechanism in asp.net to have debug and release transforms for the web.config file, but in VS2012 / Azure SDK 2.1 that doesn't seem to be part of the default azure webrole project. I was about to write a startup task when I found this thread :-) Having a real fix will save me from doing that.

@MFisherMSFT
Copy link

@ogazitt The mechanism that performs transforms of web.config based on the solution configuration still exists. When I create a new Windows Azure Cloud Service project with a Web Role, I see Web.Debug.config and Web.Release.config files under Web.config (which needs to be expanded in the Solution Explorer). And you can right-click on Web.config to create new config transform files.

@ogazitt
Copy link

ogazitt commented Oct 23, 2013

@MFisherMSFT wow, I can’t believe I missed the arrow to expand the web.config node in solution explorer. Embarrassing :-) Thanks for the pointer!

@ogail
Copy link
Contributor

ogail commented Oct 31, 2013

Hi all,
We have pushed the fix for this issue in the version 2.0.2 on NuGet, would appreciate if you can give it a try and let us hear your feedback.

Cheers,
Ogail

@ogail ogail closed this as completed Oct 31, 2013
@ogazitt
Copy link

ogazitt commented Nov 2, 2013

I tried this out by installing the newest (v2.0.2) Windows Azure Configuration Manager package off NuGet. Oddly enough, while my issues running the web project in IIS Express have gone away, I seem to have a new issue with neither the webrole nor the worker role in my azure project logging data anymore.

My setup looks as follows:

web.config for webrole, app.config for worker role have the same sys.diagnostics section:

        <system.diagnostics>
          <trace>
            <listeners>
              <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
                <filter type="" />
              </add>
            </listeners>
          </trace>
        </system.diagnostics>

And the RoleEntryPoint.OnStart() override for both roles has the following code:

                var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
                config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
                config.Logs.BufferQuotaInMB = 1000;
                config.Logs.ScheduledTransferLogLevelFilter = Microsoft.WindowsAzure.Diagnostics.LogLevel.Verbose;

Microsoft.WindowsAzure.Diagnostics.LogLevel.Information;
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);

My WADLogsTable hasn't received any of my Trace.WriteLine() messages since I've redeployed.

I even flushed the wad-control-container blobs (as has been noted on stackoverflow and other places), to no avail.

Unfortunately I'm not 100% sure that the broken traces is correlated to the new Microsoft.WindowsAzure.Configuration.dll, but I'm starting to run out of ideas.

Update:
Note sure how my deployment got horked but after deleting the production deployment and redeploying everything, my tracing issues seem to have gone away.

I can confirm that I no longer get Azure exceptions when I run the web project in IIS Express.

Thanks!

hyonholee pushed a commit to hyonholee/azure-sdk-for-net that referenced this issue Sep 28, 2015
hovsepm pushed a commit that referenced this issue Apr 25, 2016
Latest hydra specs with configurable resource namespace param into
jethibau pushed a commit to jethibau/azure-sdk-for-net that referenced this issue Aug 2, 2018
* Make app settings and conn strings lazy

* Fix tests and re-record

* Fix function app kind

* Re-record CDN and TM

* Address feedback
AlexGhiondea pushed a commit to AlexGhiondea/azure-sdk-for-net that referenced this issue Feb 12, 2019
mentat9 pushed a commit to mentat9/azure-sdk-for-net that referenced this issue Jun 10, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests