# wm.open_mainfile is causing issues with context.screen.area in 2.79 [duplicate]

This is my first post so pardon any errors in formatting.

I'm trying to create a script that opens a file and links objects to it however when I attempt to link the objects it gives me a polling error. I looked up how to fix it and I found this code.

for area in bpy.context.screen.area:
if area.type == 'VIEW_3D':
override = bpy.context.copy()
override['area'] = area
break


it only works when the following code isn't present

bpy.ops.wm.open_mainfile()


When it is present I get

AttributeError: 'NoneType' object has no attribute 'area'


I have looked all over and could not find anyone else having this issue so I'm under the impression it is a very niche case so any help would be greatly appreciated. Below is similar code without all the extra filler I've written. The code in question is on lines 44-58.

import bpy

bl_info = {
"author": "Exotic",
"version": (0, 0, 1),
"blender": (2, 7, 9),
"location": "Render > sample",
"description": "",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "System"}

class SampleMessage(bpy.types.Operator):
"""SampleMessage"""
bl_idname = "button.message"
bl_label = "Message"

def execute(self, context):
return {'FINISHED'}

def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self, width=400, height=400)

def draw(self, context):
layout = self.layout
layout.label("WARNING", icon='ERROR')
row = layout.row()
row.label("Are you Sure?.")
row = layout.row()
row.label("Press OK")

bl_label = "Save N' Load Operator"

def execute(self, context):
bpy.ops.wm.open_mainfile(filepath=yourpath)

for area in bpy.context.screen.area:
if area.type == 'VIEW_3D':
override = bpy.context.copy()
override['area'] = area
break

filename = "Cone.001"

return {'FINISHED'}

self.layout.operator(
SampleMessage.bl_idname,
text=SampleMessage.__doc__,
icon='BLENDER'
)

def register():